From c07bbbcef9117cdef249fcea2ae4c9f32ae50ae3 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Sat, 12 Feb 2022 14:05:08 -0500 Subject: [PATCH] Revert "[asan] Always skip first object from dl_iterate_phdr" This reverts commit d75a5650dbdc595f836db4711f2a480f87243593. Breaks asan_dlopen_test.cpp on several bots, see comments on https://reviews.llvm.org/D119515 --- compiler-rt/lib/asan/asan_linux.cpp | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/compiler-rt/lib/asan/asan_linux.cpp b/compiler-rt/lib/asan/asan_linux.cpp index 42de45b..1d92c53 100644 --- a/compiler-rt/lib/asan/asan_linux.cpp +++ b/compiler-rt/lib/asan/asan_linux.cpp @@ -131,21 +131,30 @@ static int FindFirstDSOCallback(struct dl_phdr_info *info, size_t size, VReport(2, "info->dlpi_name = %s\tinfo->dlpi_addr = %p\n", info->dlpi_name, (void *)info->dlpi_addr); - const char **name = (const char **)data; + // Continue until the first dynamic library is found + if (!info->dlpi_name || info->dlpi_name[0] == 0) + return 0; + + // Ignore vDSO + if (internal_strncmp(info->dlpi_name, "linux-", sizeof("linux-") - 1) == 0) + return 0; +#if SANITIZER_FREEBSD || SANITIZER_NETBSD // Ignore first entry (the main program) - if (!*name) { - *name = ""; + char **p = (char **)data; + if (!(*p)) { + *p = (char *)-1; return 0; } +#endif -# if SANITIZER_LINUX - // Ignore vDSO - if (internal_strncmp(info->dlpi_name, "linux-", sizeof("linux-") - 1) == 0) +#if SANITIZER_SOLARIS + // Ignore executable on Solaris + if (info->dlpi_addr == 0) return 0; -# endif +#endif - *name = info->dlpi_name; + *(const char **)data = info->dlpi_name; return 1; } @@ -166,7 +175,7 @@ void AsanCheckDynamicRTPrereqs() { // Ensure that dynamic RT is the first DSO in the list const char *first_dso_name = nullptr; dl_iterate_phdr(FindFirstDSOCallback, &first_dso_name); - if (first_dso_name && first_dso_name[0] && !IsDynamicRTName(first_dso_name)) { + if (first_dso_name && !IsDynamicRTName(first_dso_name)) { Report("ASan runtime does not come first in initial library list; " "you should either link runtime to your application or " "manually preload it with LD_PRELOAD.\n"); -- 2.7.4