[compiler-rt] r315024 - [LSan] Detect dynamic loader by its base address.

Hans Wennborg via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 5 15:21:41 PDT 2017


Looks like it broke this one:
http://lab.llvm.org:8011/builders/clang-ppc64be-linux/builds/11384

On Thu, Oct 5, 2017 at 2:38 PM, Alex Shlyapnikov via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
> Author: alekseyshl
> Date: Thu Oct  5 14:38:33 2017
> New Revision: 315024
>
> URL: http://llvm.org/viewvc/llvm-project?rev=315024&view=rev
> Log:
> [LSan] Detect dynamic loader by its base address.
>
> Summary:
> Relanding D33859, which was reverted because it has "broken LOTS of
> ARM/AArch64 bots for two days".
>
> If it breaks something again, please provide some pointers to broken
> bots, not just revert it, otherwise it's very hard to reason what's
> wrong with this commit.
>
> Whenever possible (Linux + glibc 2.16+), detect dynamic loader module by
> its base address, not by the module name matching. The current name
> matching approach fails on some configurations.
>
> Reviewers: eugenis
>
> Subscribers: aemerson, kubamracek, kristof.beyls, llvm-commits
>
> Differential Revision: https://reviews.llvm.org/D38600
>
> Modified:
>     compiler-rt/trunk/lib/lsan/lsan_common.cc
>     compiler-rt/trunk/lib/lsan/lsan_common_linux.cc
>     compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc
>     compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform.h
>
> Modified: compiler-rt/trunk/lib/lsan/lsan_common.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/lsan_common.cc?rev=315024&r1=315023&r2=315024&view=diff
> ==============================================================================
> --- compiler-rt/trunk/lib/lsan/lsan_common.cc (original)
> +++ compiler-rt/trunk/lib/lsan/lsan_common.cc Thu Oct  5 14:38:33 2017
> @@ -411,8 +411,9 @@ static void MarkInvalidPCCb(uptr chunk,
>    }
>  }
>
> -// On Linux, handles dynamically allocated TLS blocks by treating all chunks
> -// allocated from ld-linux.so as reachable.
> +// On Linux, treats all chunks allocated from ld-linux.so as reachable, which
> +// covers dynamically allocated TLS blocks, internal dynamic loader's loaded
> +// modules accounting etc.
>  // Dynamic TLS blocks contain the TLS variables of dynamically loaded modules.
>  // They are allocated with a __libc_memalign() call in allocate_and_init()
>  // (elf/dl-tls.c). Glibc won't tell us the address ranges occupied by those
>
> Modified: compiler-rt/trunk/lib/lsan/lsan_common_linux.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/lsan_common_linux.cc?rev=315024&r1=315023&r2=315024&view=diff
> ==============================================================================
> --- compiler-rt/trunk/lib/lsan/lsan_common_linux.cc (original)
> +++ compiler-rt/trunk/lib/lsan/lsan_common_linux.cc Thu Oct  5 14:38:33 2017
> @@ -23,6 +23,10 @@
>  #include "sanitizer_common/sanitizer_linux.h"
>  #include "sanitizer_common/sanitizer_stackdepot.h"
>
> +#if SANITIZER_USE_GETAUXVAL
> +#include <sys/auxv.h>
> +#endif  // SANITIZER_USE_GETAUXVAL
> +
>  namespace __lsan {
>
>  static const char kLinkerName[] = "ld";
> @@ -30,8 +34,12 @@ static const char kLinkerName[] = "ld";
>  static char linker_placeholder[sizeof(LoadedModule)] ALIGNED(64);
>  static LoadedModule *linker = nullptr;
>
> -static bool IsLinker(const char* full_name) {
> -  return LibraryNameIs(full_name, kLinkerName);
> +static bool IsLinker(const LoadedModule& module) {
> +#if SANITIZER_USE_GETAUXVAL
> +  return module.base_address() == getauxval(AT_BASE);
> +#else
> +  return LibraryNameIs(module.full_name(), kLinkerName);
> +#endif  // SANITIZER_USE_GETAUXVAL
>  }
>
>  __attribute__((tls_model("initial-exec")))
> @@ -49,22 +57,25 @@ void InitializePlatformSpecificModules()
>    ListOfModules modules;
>    modules.init();
>    for (LoadedModule &module : modules) {
> -    if (!IsLinker(module.full_name())) continue;
> +    if (!IsLinker(module))
> +      continue;
>      if (linker == nullptr) {
>        linker = reinterpret_cast<LoadedModule *>(linker_placeholder);
>        *linker = module;
>        module = LoadedModule();
>      } else {
>        VReport(1, "LeakSanitizer: Multiple modules match \"%s\". "
> -              "TLS will not be handled correctly.\n", kLinkerName);
> +              "TLS and other allocations originating from linker might be "
> +              "falsely reported as leaks.\n", kLinkerName);
>        linker->clear();
>        linker = nullptr;
>        return;
>      }
>    }
>    if (linker == nullptr) {
> -    VReport(1, "LeakSanitizer: Dynamic linker not found. "
> -               "TLS will not be handled correctly.\n");
> +    VReport(1, "LeakSanitizer: Dynamic linker not found. TLS and other "
> +               "allocations originating from linker might be falsely reported "
> +                "as leaks.\n");
>    }
>  }
>
>
> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc?rev=315024&r1=315023&r2=315024&view=diff
> ==============================================================================
> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc (original)
> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc Thu Oct  5 14:38:33 2017
> @@ -93,16 +93,6 @@ extern char **environ;  // provided by c
>  #include <sys/signal.h>
>  #endif
>
> -#ifndef __GLIBC_PREREQ
> -#define __GLIBC_PREREQ(x, y) 0
> -#endif
> -
> -#if SANITIZER_LINUX && __GLIBC_PREREQ(2, 16)
> -# define SANITIZER_USE_GETAUXVAL 1
> -#else
> -# define SANITIZER_USE_GETAUXVAL 0
> -#endif
> -
>  #if SANITIZER_USE_GETAUXVAL
>  #include <sys/auxv.h>
>  #endif
>
> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform.h
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform.h?rev=315024&r1=315023&r2=315024&view=diff
> ==============================================================================
> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform.h (original)
> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform.h Thu Oct  5 14:38:33 2017
> @@ -282,5 +282,14 @@
>  # define SANITIZER_SUPPRESS_LEAK_ON_PTHREAD_EXIT 0
>  #endif
>
> +#ifndef __GLIBC_PREREQ
> +#define __GLIBC_PREREQ(x, y) 0
> +#endif
> +
> +#if SANITIZER_LINUX && __GLIBC_PREREQ(2, 16)
> +# define SANITIZER_USE_GETAUXVAL 1
> +#else
> +# define SANITIZER_USE_GETAUXVAL 0
> +#endif
>
>  #endif // SANITIZER_PLATFORM_H
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits


More information about the llvm-commits mailing list