[llvm-commits] [compiler-rt] r149063 - in /compiler-rt/trunk/lib/asan: asan_mac.cc asan_procmaps.h

Alexander Potapenko glider at google.com
Thu Jan 26 09:01:20 PST 2012


Author: glider
Date: Thu Jan 26 11:01:20 2012
New Revision: 149063

URL: http://llvm.org/viewvc/llvm-project?rev=149063&view=rev
Log:
Fix a bug in AsanProcMaps on Mac: on 64 bits the program was trying to read twice as many segment load commands as the binary actually contained.

Modified:
    compiler-rt/trunk/lib/asan/asan_mac.cc
    compiler-rt/trunk/lib/asan/asan_procmaps.h

Modified: compiler-rt/trunk/lib/asan/asan_mac.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_mac.cc?rev=149063&r1=149062&r2=149063&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_mac.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_mac.cc Thu Jan 26 11:01:20 2012
@@ -177,6 +177,7 @@
   current_image_ = _dyld_image_count();
   current_load_cmd_count_ = -1;
   current_load_cmd_addr_ = NULL;
+  current_magic_ = 0;
 }
 
 // Next and NextSegmentLoad were inspired by base/sysinfo.cc in
@@ -202,6 +203,8 @@
       real_strncpy(filename, _dyld_get_image_name(current_image_),
                    filename_size);
     }
+    if (FLAG_v >= 4)
+      Report("LC_SEGMENT: %p--%p %s+%p\n", *start, *end, filename, *offset);
     return true;
   }
   return false;
@@ -216,7 +219,8 @@
     if (current_load_cmd_count_ < 0) {
       // Set up for this image;
       current_load_cmd_count_ = hdr->ncmds;
-      switch (hdr->magic) {
+      current_magic_ = hdr->magic;
+      switch (current_magic_) {
 #ifdef MH_MAGIC_64
         case MH_MAGIC_64: {
           current_load_cmd_addr_ = (char*)hdr + sizeof(mach_header_64);
@@ -233,18 +237,24 @@
       }
     }
 
-    // We start with the next load command (we've already looked at this one).
-    for (current_load_cmd_count_--;
-         current_load_cmd_count_ >= 0;
-         current_load_cmd_count_--) {
+    for (; current_load_cmd_count_ >= 0; current_load_cmd_count_--) {
+      switch (current_magic_) {
+        // current_magic_ may be only one of MH_MAGIC, MH_MAGIC_64.
 #ifdef MH_MAGIC_64
-      if (NextSegmentLoad<LC_SEGMENT_64, struct segment_command_64>(
-              start, end, offset, filename, filename_size))
-        return true;
+        case MH_MAGIC_64: {
+          if (NextSegmentLoad<LC_SEGMENT_64, struct segment_command_64>(
+                  start, end, offset, filename, filename_size))
+            return true;
+          break;
+        }
 #endif
-      if (NextSegmentLoad<LC_SEGMENT, struct segment_command>(
-              start, end, offset, filename, filename_size))
-        return true;
+        case MH_MAGIC: {
+          if (NextSegmentLoad<LC_SEGMENT, struct segment_command>(
+                  start, end, offset, filename, filename_size))
+            return true;
+          break;
+        }
+      }
     }
     // If we get here, no more load_cmd's in this image talk about
     // segments.  Go on to the next image.

Modified: compiler-rt/trunk/lib/asan/asan_procmaps.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_procmaps.h?rev=149063&r1=149062&r2=149063&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_procmaps.h (original)
+++ compiler-rt/trunk/lib/asan/asan_procmaps.h Thu Jan 26 11:01:20 2012
@@ -64,6 +64,7 @@
   char *current_;
 #elif defined __APPLE__
   int current_image_;
+  uint32_t current_magic_;
   int current_load_cmd_count_;
   char *current_load_cmd_addr_;
 #endif





More information about the llvm-commits mailing list