unfortunately, this is not as simple as this. <div>We have Darwin and Android, and we also have the llvm-based symbolizer (which will eventually replace asan_symbolize.py). </div><div>Besides, I still want the offsets to be meaningful for addr2line/atos. </div>
<div>Hopefully, you can resolve this with Alexey. </div><div>We may of course put the sanitizer_procmaps.h change under a flag, if the fix takes too long. </div><div><br></div><div>--kcc </div><div><br></div><div><br></div>
<div><br><br><div class="gmail_quote">On Thu, Oct 18, 2012 at 9:21 AM, NAKAMURA Takumi <span dir="ltr"><<a href="mailto:geek4civic@gmail.com" target="_blank">geek4civic@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
compiler-rt/asan: MemoryMappingLayout: Always emit the offset in corresponding module.<br>
<br>
asan_symbolize.py: Use offset with (rounded to page_size) base address, with objdump(1).<br>
<br>
FIXME: I have not tested on darwin.<br>
<br>
<a href="http://llvm-reviews.chandlerc.com/D66" target="_blank">http://llvm-reviews.chandlerc.com/D66</a><br>
<br>
Files:<br>
  compiler-rt/lib/asan/scripts/asan_symbolize.py<br>
  compiler-rt/lib/sanitizer_common/sanitizer_procmaps.h<br>
<br>
Index: compiler-rt/lib/asan/scripts/asan_symbolize.py<br>
===================================================================<br>
--- compiler-rt/lib/asan/scripts/asan_symbolize.py<br>
+++ compiler-rt/lib/asan/scripts/asan_symbolize.py<br>
@@ -109,6 +109,28 @@<br>
     super(Addr2LineSymbolizer, self).__init__()<br>
     self.binary = binary<br>
     self.pipe = self.open_addr2line()<br>
+    self.base = self.get_base_addr()<br>
+<br>
+  def get_base_addr(self):<br>
+    p = subprocess.Popen(<br>
+      ['objdump', '-h', self.binary],<br>
+      stdin=None,<br>
+      stdout=subprocess.PIPE<br>
+      )<br>
+    # Capture the first VMA with 'LOAD'.<br>
+    a = re.compile(r'\s+(?P<Size>[0-9a-f]{8,})\s+(?P<VMA>[0-9a-f]{8,})\s+(?P<LMA>[0-9a-f]{8,})\s+(?P<offset>[0-9a-f]{8,})\s+')<br>
+    b = re.compile(r'\WLOAD\W')<br>
+    base = '';<br>
+    vma = ''<br>
+    for line in p.stdout:<br>
+      ma = a.search(line)<br>
+      if ma:<br>
+        vma = ma.group('VMA')<br>
+      elif base == '' and vma != '' and b.search(line):<br>
+        base = vma<br>
+<br>
+    p.wait()<br>
+    return int(base, 16) & -4096<br>
<br>
   def open_addr2line(self):<br>
     cmd = ['addr2line', '-f', '-e', self.binary]<br>
@@ -122,6 +144,7 @@<br>
     if self.binary != binary:<br>
       return None<br>
     try:<br>
+      offset = "0x%x" % (self.base + int(offset, 16))<br>
       print >> self.pipe.stdin, offset<br>
       function_name = self.pipe.stdout.readline().rstrip()<br>
       file_name = self.pipe.stdout.readline().rstrip()<br>
Index: compiler-rt/lib/sanitizer_common/sanitizer_procmaps.h<br>
===================================================================<br>
--- compiler-rt/lib/sanitizer_common/sanitizer_procmaps.h<br>
+++ compiler-rt/lib/sanitizer_common/sanitizer_procmaps.h<br>
@@ -52,18 +52,8 @@<br>
     for (int i = 0; Next(&start, &end, &file_offset, filename, filename_size);<br>
          i++) {<br>
       if (addr >= start && addr < end) {<br>
-        // Don't subtract 'start' for the first entry:<br>
-        // * If a binary is compiled w/o -pie, then the first entry in<br>
-        //   process maps is likely the binary itself (all dynamic libs<br>
-        //   are mapped higher in address space). For such a binary,<br>
-        //   instruction offset in binary coincides with the actual<br>
-        //   instruction address in virtual memory (as code section<br>
-        //   is mapped to a fixed memory range).<br>
-        // * If a binary is compiled with -pie, all the modules are<br>
-        //   mapped high at address space (in particular, higher than<br>
-        //   shadow memory of the tool), so the module can't be the<br>
-        //   first entry.<br>
-        *offset = (addr - (i ? start : 0)) + file_offset;<br>
+       // FIXME: file_offset doesn't make sense if it is not zero.<br>
+        *offset = (addr - start) + file_offset;<br>
         return true;<br>
       }<br>
     }<br>
<br>_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
<br></blockquote></div><br></div>