38 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8//9// This file has helper functions that depend on libc's dynamic loading10// introspection.11//12//===----------------------------------------------------------------------===//13 14#include "sanitizer_dl.h"15 16#include "sanitizer_common/sanitizer_platform.h"17 18#if SANITIZER_GLIBC19# include <dlfcn.h>20#endif21 22namespace __sanitizer {23extern const char *SanitizerToolName;24 25const char *DladdrSelfFName(void) {26#if SANITIZER_GLIBC27 Dl_info info;28 int ret = dladdr((void *)&SanitizerToolName, &info);29 if (ret) {30 return info.dli_fname;31 }32#endif33 34 return nullptr;35}36 37} // namespace __sanitizer38