<br><br><div class="gmail_quote">On Tue, Aug 14, 2012 at 11:22 AM, Dmitry Vyukov <span dir="ltr"><<a href="mailto:dvyukov@google.com" target="_blank">dvyukov@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="gmail_extra"><div class="gmail_quote"><div class="im">On Tue, Aug 14, 2012 at 11:01 AM, Alexey Samsonov <span dir="ltr"><<a href="mailto:samsonov@google.com" target="_blank">samsonov@google.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="gmail_quote"><div>On Mon, Aug 13, 2012 at 10:47 PM, Dmitry Vyukov <span dir="ltr"><<a href="mailto:dvyukov@google.com" target="_blank">dvyukov@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


This breaks Go runtime:<div><br></div><div><div>gcc gotsan.cc -S -o tmp.s -I../rtl -I../.. -I../../sanitizer_common -fPIC -g -Wall -Werror -fno-exceptions -DTSAN_GO -DSANITIZER_GO -DTSAN_SHADOW_COUNT=4 -DTSAN_DEBUG=0 -O3 -fomit-frame-pointer -ffreestanding</div>



<div>as gotsan.s -o race_linux_amd64.syso</div><div>/usr/bin/ld.gold: race_linux_amd64.syso: in function __sanitizer::dl_iterate_phdr_cb(dl_phdr_info*, unsigned long, void*):gotsan.cc:4485: error: undefined reference to '__sanitizer::ModuleDIContext::ModuleDIContext(char const*, unsigned long)'</div>



<div>/usr/bin/ld.gold: race_linux_amd64.syso: in function __sanitizer::dl_iterate_phdr_cb(dl_phdr_info*, unsigned long, void*):gotsan.cc:4492: error: undefined reference to '__sanitizer::ModuleDIContext::addAddressRange(unsigned long, unsigned long)'</div>



<div>/usr/bin/ld.gold: race_linux_amd64.syso: in function __sanitizer::FindDWARFSection(unsigned long, char const*, __sanitizer::DWARFSection*):gotsan.cc:4442: error: undefined reference to '__sanitizer::IsFullNameOfDWARFSection(char const*, char const*)'</div>



<div>collect2: ld returned 1 exit status</div><div><br></div><div>Please keep everything related to symbolization in separate files as it makes sense only for C/C++.</div></div></blockquote><div><br></div></div><div>I can, but then I'd have to create even more OS-specific files (sanitizer_symoblizer_win, sanitizer_symbolizer_linux etc.) in parallel to existing OS-specific files in sanitizer_common.</div>

</div></blockquote><div><br></div></div><div>I think that's good.</div><div class="im"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_quote">

<div>Why can't you include all the sources into go runtime? To save the size or because it's the Wrong thing to do?</div></div></blockquote><div><br></div></div><div>There are several reasons. Size of runtime matters. It will require parts of llvm as well, but Go runtime is very restricted in what it can contain (no global ctors, no weak symbols, no deps on libstdc++, etc), I do not think that llvm satisfies the requirements. And I think it is the wrong thing to do.</div>
</div></div></blockquote><div><br></div><div>r161862</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_extra"><div class="gmail_quote">
<div><div class="h5">
<div><br></div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_quote"><div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div><div>On Tue, Jul 31, 2012 at 3:51 PM, Alexey Samsonov <span dir="ltr"><<a href="mailto:samsonov@google.com" target="_blank">samsonov@google.com</a>></span> wrote:<br></div></div><div><div><div class="gmail_extra">

<div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

Author: samsonov<br>
Date: Tue Jul 31 06:51:26 2012<br>
New Revision: 161045<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=161045&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=161045&view=rev</a><br>
Log:<br>
[Sanitizer] Wrapper around llvm::DIContext from LLVM DebugInfo library. If a macro SANITIZER_USES_LLVM_LIBS is defined (by default it is not), then sanitizer runtime includes llvm headers and tries to use LLVM libs for in-process symbolization. To make it functional, we have to link with these LLVM libs - either pass them to linker from Clang driver, or link them into static ASan runtime when we build it.<br>




<br>
Added:<br>
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_llvm.cc<br>
Modified:<br>
    compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt<br>
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.cc<br>
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.h<br>
<br>
Modified: compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt?rev=161045&r1=161044&r2=161045&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt?rev=161045&r1=161044&r2=161045&view=diff</a><br>




==============================================================================<br>
--- compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt (original)<br>
+++ compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt Tue Jul 31 06:51:26 2012<br>
@@ -11,13 +11,15 @@<br>
   sanitizer_posix.cc<br>
   sanitizer_printf.cc<br>
   sanitizer_symbolizer.cc<br>
+  sanitizer_symbolizer_llvm.cc<br>
   sanitizer_win.cc<br>
   )<br>
<br>
 set(SANITIZER_CFLAGS "-fPIC -fno-exceptions -funwind-tables -fvisibility=hidden")<br>
<br>
 set(SANITIZER_COMMON_DEFINITIONS<br>
-       SANITIZER_HAS_EXCEPTIONS=1)<br>
+  SANITIZER_HAS_EXCEPTIONS=1<br>
+  )<br>
<br>
 if(CAN_TARGET_X86_64)<br>
   add_library(RTSanitizerCommon.x86_64 OBJECT ${SANITIZER_SOURCES})<br>
<br>
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.cc?rev=161045&r1=161044&r2=161045&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.cc?rev=161045&r1=161044&r2=161045&view=diff</a><br>




==============================================================================<br>
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.cc (original)<br>
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.cc Tue Jul 31 06:51:26 2012<br>
@@ -7,13 +7,11 @@<br>
 //<br>
 //===----------------------------------------------------------------------===//<br>
 //<br>
-// This is a stub for LLVM-based symbolizer.<br>
 // This file is shared between AddressSanitizer and ThreadSanitizer<br>
-// run-time libraries. See sanitizer.h for details.<br>
+// run-time libraries. See sanitizer_symbolizer.h for details.<br>
 //===----------------------------------------------------------------------===//<br>
<br>
 #include "sanitizer_common.h"<br>
-#include "sanitizer_placement_new.h"<br>
 #include "sanitizer_procmaps.h"<br>
 #include "sanitizer_symbolizer.h"<br>
<br>
@@ -50,6 +48,7 @@<br>
   n_ranges_ = 0;<br>
   mapped_addr_ = 0;<br>
   mapped_size_ = 0;<br>
+  dwarf_context_ = 0;<br>
 }<br>
<br>
 void ModuleDIContext::addAddressRange(uptr beg, uptr end) {<br>
@@ -71,29 +70,25 @@<br>
   info->module = internal_strdup(full_name_);<br>
   info->module_offset = info->address - base_address_;<br>
   if (mapped_addr_ == 0)<br>
-    CreateDIContext();<br>
-  // FIXME: Use the actual debug info context here.<br>
-  info->function = 0;<br>
-  info->file = 0;<br>
-  info->line = 0;<br>
-  info->column = 0;<br>
+    CreateDWARFContext();<br>
+  getLineInfoFromContext(dwarf_context_, info);<br>
 }<br>
<br>
-void ModuleDIContext::CreateDIContext() {<br>
+void ModuleDIContext::CreateDWARFContext() {<br>
   mapped_addr_ = (uptr)MapFileToMemory(full_name_, &mapped_size_);<br>
   CHECK(mapped_addr_);<br>
   DWARFSection debug_info;<br>
   DWARFSection debug_abbrev;<br>
-  DWARFSection debug_line;<br>
   DWARFSection debug_aranges;<br>
+  DWARFSection debug_line;<br>
   DWARFSection debug_str;<br>
   FindDWARFSection(mapped_addr_, "debug_info", &debug_info);<br>
   FindDWARFSection(mapped_addr_, "debug_abbrev", &debug_abbrev);<br>
-  FindDWARFSection(mapped_addr_, "debug_line", &debug_line);<br>
   FindDWARFSection(mapped_addr_, "debug_aranges", &debug_aranges);<br>
+  FindDWARFSection(mapped_addr_, "debug_line", &debug_line);<br>
   FindDWARFSection(mapped_addr_, "debug_str", &debug_str);<br>
-  // FIXME: Construct actual debug info context using mapped_addr,<br>
-  // mapped_size and pointers to DWARF sections in memory.<br>
+  dwarf_context_ = getDWARFContext(debug_info, debug_abbrev, debug_aranges,<br>
+                                   debug_line, debug_str);<br>
 }<br>
<br>
 class Symbolizer {<br>
<br>
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.h?rev=161045&r1=161044&r2=161045&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.h?rev=161045&r1=161044&r2=161045&view=diff</a><br>




==============================================================================<br>
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.h (original)<br>
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.h Tue Jul 31 06:51:26 2012<br>
@@ -66,6 +66,14 @@<br>
                       DWARFSection *section);<br>
 bool IsFullNameOfDWARFSection(const char *full_name, const char *short_name);<br>
<br>
+class DWARFContext;<br>
+DWARFContext *getDWARFContext(DWARFSection debug_info,<br>
+                              DWARFSection debug_abbrev,<br>
+                              DWARFSection debug_aranges,<br>
+                              DWARFSection debug_line,<br>
+                              DWARFSection debug_str);<br>
+void getLineInfoFromContext(DWARFContext *context, AddressInfo *info);<br>
+<br>
 class ModuleDIContext {<br>
  public:<br>
   ModuleDIContext(const char *module_name, uptr base_address);<br>
@@ -76,7 +84,7 @@<br>
   const char *full_name() const { return full_name_; }<br>
<br>
  private:<br>
-  void CreateDIContext();<br>
+  void CreateDWARFContext();<br>
<br>
   struct AddressRange {<br>
     uptr beg;<br>
@@ -90,6 +98,7 @@<br>
   uptr n_ranges_;<br>
   uptr mapped_addr_;<br>
   uptr mapped_size_;<br>
+  DWARFContext *dwarf_context_;<br>
 };<br>
<br>
 // OS-dependent function that gets the linked list of all loaded modules.<br>
<br>
Added: compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_llvm.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_llvm.cc?rev=161045&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_llvm.cc?rev=161045&view=auto</a><br>




==============================================================================<br>
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_llvm.cc (added)<br>
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_llvm.cc Tue Jul 31 06:51:26 2012<br>
@@ -0,0 +1,104 @@<br>
+//===-- sanitizer_symbolizer_llvm.cc --------------------------------------===//<br>
+//<br>
+//                     The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+//<br>
+// This is a wrapper around llvm::DIContext, moved to separate file to<br>
+// include LLVM headers in a single place in sanitizer library. If macro<br>
+// SANITIZER_USES_LLVM_LIBS is not defined, then sanitizer runtime<br>
+// will not include LLVM headers and will not require static<br>
+// LLVM libraries to link with.<br>
+// In this case, the symbolizer will just return zeroes instead of<br>
+// valid file/line info.<br>
+//<br>
+// This file is shared between AddressSanitizer and ThreadSanitizer<br>
+// run-time libraries.<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#include "sanitizer_common.h"<br>
+#include "sanitizer_symbolizer.h"<br>
+<br>
+#ifdef SANITIZER_USES_LLVM_LIBS<br>
+# ifndef __STDC_LIMIT_MACROS<br>
+#  define __STDC_LIMIT_MACROS 1<br>
+# endif<br>
+# ifndef __STDC_CONSTANT_MACROS<br>
+#  define __STDC_CONSTANT_MACROS 1<br>
+# endif<br>
+# include "llvm/ADT/StringRef.h"<br>
+# include "llvm/DebugInfo/DIContext.h"<br>
+<br>
+namespace __sanitizer {<br>
+<br>
+static llvm::StringRef ToStringRef(const DWARFSection &section) {<br>
+  return llvm::StringRef(section.data, section.size);<br>
+}<br>
+<br>
+class DWARFContext : public llvm::DIContext {};<br>
+<br>
+DWARFContext *getDWARFContext(DWARFSection debug_info,<br>
+                              DWARFSection debug_abbrev,<br>
+                              DWARFSection debug_aranges,<br>
+                              DWARFSection debug_line,<br>
+                              DWARFSection debug_str) {<br>
+  return (DWARFContext*)llvm::DIContext::getDWARFContext(<br>
+      true, ToStringRef(debug_info), ToStringRef(debug_abbrev),<br>
+      llvm::StringRef(),  // don't use .debug_aranges for now.<br>
+      ToStringRef(debug_line), ToStringRef(debug_str));<br>
+}<br>
+<br>
+void getLineInfoFromContext(DWARFContext *context, AddressInfo *info) {<br>
+  CHECK(context);<br>
+  uint32_t flags = llvm::DILineInfoSpecifier::FileLineInfo |<br>
+                   llvm::DILineInfoSpecifier::AbsoluteFilePath |<br>
+                   llvm::DILineInfoSpecifier::FunctionName;<br>
+  llvm::DILineInfo line_info = context->getLineInfoForAddress(<br>
+      info->module_offset, flags);<br>
+<br>
+  const char *function = line_info.getFunctionName();<br>
+  CHECK(function);<br>
+  if (0 != internal_strcmp("<invalid>", function))<br>
+    info->function = internal_strdup(function);<br>
+  else<br>
+    info->function = 0;<br>
+<br>
+  const char *file = line_info.getFileName();<br>
+  CHECK(file);<br>
+  if (0 != internal_strcmp("<invalid>", file))<br>
+    info->file = internal_strdup(file);<br>
+  else<br>
+    info->file = 0;<br>
+<br>
+  info->line = line_info.getLine();<br>
+  info->column = line_info.getColumn();<br>
+}<br>
+<br>
+}  // namespace __sanitizer<br>
+<br>
+#else  // SANITIZER_USES_LLVM_LIBS<br>
+namespace __sanitizer {<br>
+<br>
+class DWARFContext {};<br>
+<br>
+DWARFContext *getDWARFContext(DWARFSection debug_info,<br>
+                              DWARFSection debug_abbrev,<br>
+                              DWARFSection debug_aranges,<br>
+                              DWARFSection debug_line,<br>
+                              DWARFSection debug_str) {<br>
+  return 0;<br>
+}<br>
+<br>
+void getLineInfoFromContext(DWARFContext *context, AddressInfo *info) {<br>
+  (void)context;<br>
+  info->function = 0;<br>
+  info->file = 0;<br>
+  info->line = 0;<br>
+  info->column = 0;<br>
+}<br>
+<br>
+}  // namespace __sanitizer<br>
+#endif  // SANITIZER_USES_LLVM_LIBS<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">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>
</blockquote></div><br></div>
</div></div></blockquote></div></div><span><font color="#888888"><br><br clear="all"><div><br></div>-- <br><div>Alexey Samsonov, MSK</div><br>
</font></span></blockquote></div></div></div><br></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div>Alexey Samsonov, MSK</div><br>