From 77c0ac23362326b5f64b926134c3b9b41341f2c8 Mon Sep 17 00:00:00 2001 From: Alexander Potapenko Date: Tue, 2 Oct 2012 15:42:24 +0000 Subject: [PATCH] Do not patch the instruction address when symbolizing the reports. Instead, print the correct address at runtime. llvm-svn: 165018 --- compiler-rt/lib/asan/scripts/asan_symbolize.py | 33 +--------------------- compiler-rt/lib/sanitizer_common/sanitizer_mac.cc | 10 ++++++- .../lib/sanitizer_common/sanitizer_procmaps.h | 1 + 3 files changed, 11 insertions(+), 33 deletions(-) diff --git a/compiler-rt/lib/asan/scripts/asan_symbolize.py b/compiler-rt/lib/asan/scripts/asan_symbolize.py index a4f91c8..7891041 100755 --- a/compiler-rt/lib/asan/scripts/asan_symbolize.py +++ b/compiler-rt/lib/asan/scripts/asan_symbolize.py @@ -146,39 +146,8 @@ class DarwinSymbolizer(Symbolizer): self.vmaddr = None self.pipe = None - def get_binary_vmaddr(self): - """Get the slide value to be added to the address. - - We're looking for the following piece in otool -l output: - Load command 0 - cmd LC_SEGMENT - cmdsize 736 - segname __TEXT - vmaddr 0x00000000 - """ - if self.vmaddr: - return self.vmaddr - cmdline = ['otool', '-l', self.binary] - pipe = subprocess.Popen(cmdline, - stdin=subprocess.PIPE, - stdout=subprocess.PIPE) - is_text = False - vmaddr = 0 - for line in pipe.stdout: - line = line.strip() - if line.startswith('segname'): - is_text = (line == 'segname __TEXT') - continue - if line.startswith('vmaddr') and is_text: - sv = line.split(' ') - vmaddr = int(sv[-1], 16) - break - self.vmaddr = vmaddr - return self.vmaddr - def write_addr_to_pipe(self, offset): - slide = self.get_binary_vmaddr() - print >> self.pipe.stdin, '0x%x' % (int(offset, 16) + slide) + print >> self.pipe.stdin, '0x%x' % int(offset, 16) def open_atos(self): if DEBUG: diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_mac.cc b/compiler-rt/lib/sanitizer_common/sanitizer_mac.cc index aaf95d5..6be53cd 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_mac.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_mac.cc @@ -151,6 +151,7 @@ void MemoryMappingLayout::Reset() { current_load_cmd_count_ = -1; current_load_cmd_addr_ = 0; current_magic_ = 0; + current_filetype_ = 0; } // Next and NextSegmentLoad were inspired by base/sysinfo.cc in @@ -171,7 +172,13 @@ bool MemoryMappingLayout::NextSegmentLoad( const SegmentCommand* sc = (const SegmentCommand *)lc; if (start) *start = sc->vmaddr + dlloff; if (end) *end = sc->vmaddr + sc->vmsize + dlloff; - if (offset) *offset = sc->fileoff; + if (offset) { + if (current_filetype_ == /*MH_EXECUTE*/ 0x2) { + *offset = sc->vmaddr; + } else { + *offset = sc->fileoff; + } + } if (filename) { internal_strncpy(filename, _dyld_get_image_name(current_image_), filename_size); @@ -190,6 +197,7 @@ bool MemoryMappingLayout::Next(uptr *start, uptr *end, uptr *offset, // Set up for this image; current_load_cmd_count_ = hdr->ncmds; current_magic_ = hdr->magic; + current_filetype_ = hdr->filetype; switch (current_magic_) { #ifdef MH_MAGIC_64 case MH_MAGIC_64: { diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_procmaps.h b/compiler-rt/lib/sanitizer_common/sanitizer_procmaps.h index 126c895..4763e1f 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_procmaps.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_procmaps.h @@ -84,6 +84,7 @@ class MemoryMappingLayout { char filename[], uptr filename_size); int current_image_; u32 current_magic_; + u32 current_filetype_; int current_load_cmd_count_; char *current_load_cmd_addr_; # endif -- 2.7.4