[compiler-rt] c07bbbc - Revert "[asan] Always skip first object from dl_iterate_phdr"

Nico Weber via llvm-commits llvm-commits at lists.llvm.org
Sat Feb 12 11:06:11 PST 2022


Author: Nico Weber
Date: 2022-02-12T14:05:59-05:00
New Revision: c07bbbcef9117cdef249fcea2ae4c9f32ae50ae3

URL: https://github.com/llvm/llvm-project/commit/c07bbbcef9117cdef249fcea2ae4c9f32ae50ae3
DIFF: https://github.com/llvm/llvm-project/commit/c07bbbcef9117cdef249fcea2ae4c9f32ae50ae3.diff

LOG: 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

Added: 
    

Modified: 
    compiler-rt/lib/asan/asan_linux.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/asan/asan_linux.cpp b/compiler-rt/lib/asan/asan_linux.cpp
index 42de45b632718..1d92c530bd110 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");


        


More information about the llvm-commits mailing list