sanitizer_dl.cpp 964 B

12345678910111213141516171819202122232425262728293031323334353637
  1. //===-- sanitizer_dl.cpp --------------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file has helper functions that depend on libc's dynamic loading
  10. // introspection.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #include "sanitizer_dl.h"
  14. #include "sanitizer_common/sanitizer_platform.h"
  15. #if SANITIZER_GLIBC
  16. # include <dlfcn.h>
  17. #endif
  18. namespace __sanitizer {
  19. extern const char *SanitizerToolName;
  20. const char *DladdrSelfFName(void) {
  21. #if SANITIZER_GLIBC
  22. Dl_info info;
  23. int ret = dladdr((void *)&SanitizerToolName, &info);
  24. if (ret) {
  25. return info.dli_fname;
  26. }
  27. #endif
  28. return nullptr;
  29. }
  30. } // namespace __sanitizer