xref: /freebsd/contrib/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_dl.cpp (revision a90b9d0159070121c221b966469c3e36d912bf82)
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 
14 #include "sanitizer_dl.h"
15 
16 #include "sanitizer_common/sanitizer_platform.h"
17 
18 #if SANITIZER_GLIBC
19 #  include <dlfcn.h>
20 #endif
21 
22 namespace __sanitizer {
23 extern const char *SanitizerToolName;
24 
25 const char *DladdrSelfFName(void) {
26 #if SANITIZER_GLIBC
27   Dl_info info;
28   int ret = dladdr((void *)&SanitizerToolName, &info);
29   if (ret) {
30     return info.dli_fname;
31   }
32 #endif
33 
34   return nullptr;
35 }
36 
37 }  // namespace __sanitizer
38