[llvm-commits] [compiler-rt] r161045 - in /compiler-rt/trunk/lib/sanitizer_common: CMakeLists.txt sanitizer_symbolizer.cc sanitizer_symbolizer.h sanitizer_symbolizer_llvm.cc

Dmitry Vyukov dvyukov at google.com
Mon Aug 13 11:47:54 PDT 2012


This breaks Go runtime:

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
as gotsan.s -o race_linux_amd64.syso
/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)'
/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)'
/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*)'
collect2: ld returned 1 exit status

Please keep everything related to symbolization in separate files as it
makes sense only for C/C++.




On Tue, Jul 31, 2012 at 3:51 PM, Alexey Samsonov <samsonov at google.com>wrote:

> Author: samsonov
> Date: Tue Jul 31 06:51:26 2012
> New Revision: 161045
>
> URL: http://llvm.org/viewvc/llvm-project?rev=161045&view=rev
> Log:
> [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.
>
> Added:
>     compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_llvm.cc
> Modified:
>     compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt
>     compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.cc
>     compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.h
>
> Modified: compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt?rev=161045&r1=161044&r2=161045&view=diff
>
> ==============================================================================
> --- compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt (original)
> +++ compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt Tue Jul 31
> 06:51:26 2012
> @@ -11,13 +11,15 @@
>    sanitizer_posix.cc
>    sanitizer_printf.cc
>    sanitizer_symbolizer.cc
> +  sanitizer_symbolizer_llvm.cc
>    sanitizer_win.cc
>    )
>
>  set(SANITIZER_CFLAGS "-fPIC -fno-exceptions -funwind-tables
> -fvisibility=hidden")
>
>  set(SANITIZER_COMMON_DEFINITIONS
> -       SANITIZER_HAS_EXCEPTIONS=1)
> +  SANITIZER_HAS_EXCEPTIONS=1
> +  )
>
>  if(CAN_TARGET_X86_64)
>    add_library(RTSanitizerCommon.x86_64 OBJECT ${SANITIZER_SOURCES})
>
> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.cc
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.cc?rev=161045&r1=161044&r2=161045&view=diff
>
> ==============================================================================
> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.cc
> (original)
> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.cc Tue Jul
> 31 06:51:26 2012
> @@ -7,13 +7,11 @@
>  //
>
>  //===----------------------------------------------------------------------===//
>  //
> -// This is a stub for LLVM-based symbolizer.
>  // This file is shared between AddressSanitizer and ThreadSanitizer
> -// run-time libraries. See sanitizer.h for details.
> +// run-time libraries. See sanitizer_symbolizer.h for details.
>
>  //===----------------------------------------------------------------------===//
>
>  #include "sanitizer_common.h"
> -#include "sanitizer_placement_new.h"
>  #include "sanitizer_procmaps.h"
>  #include "sanitizer_symbolizer.h"
>
> @@ -50,6 +48,7 @@
>    n_ranges_ = 0;
>    mapped_addr_ = 0;
>    mapped_size_ = 0;
> +  dwarf_context_ = 0;
>  }
>
>  void ModuleDIContext::addAddressRange(uptr beg, uptr end) {
> @@ -71,29 +70,25 @@
>    info->module = internal_strdup(full_name_);
>    info->module_offset = info->address - base_address_;
>    if (mapped_addr_ == 0)
> -    CreateDIContext();
> -  // FIXME: Use the actual debug info context here.
> -  info->function = 0;
> -  info->file = 0;
> -  info->line = 0;
> -  info->column = 0;
> +    CreateDWARFContext();
> +  getLineInfoFromContext(dwarf_context_, info);
>  }
>
> -void ModuleDIContext::CreateDIContext() {
> +void ModuleDIContext::CreateDWARFContext() {
>    mapped_addr_ = (uptr)MapFileToMemory(full_name_, &mapped_size_);
>    CHECK(mapped_addr_);
>    DWARFSection debug_info;
>    DWARFSection debug_abbrev;
> -  DWARFSection debug_line;
>    DWARFSection debug_aranges;
> +  DWARFSection debug_line;
>    DWARFSection debug_str;
>    FindDWARFSection(mapped_addr_, "debug_info", &debug_info);
>    FindDWARFSection(mapped_addr_, "debug_abbrev", &debug_abbrev);
> -  FindDWARFSection(mapped_addr_, "debug_line", &debug_line);
>    FindDWARFSection(mapped_addr_, "debug_aranges", &debug_aranges);
> +  FindDWARFSection(mapped_addr_, "debug_line", &debug_line);
>    FindDWARFSection(mapped_addr_, "debug_str", &debug_str);
> -  // FIXME: Construct actual debug info context using mapped_addr,
> -  // mapped_size and pointers to DWARF sections in memory.
> +  dwarf_context_ = getDWARFContext(debug_info, debug_abbrev,
> debug_aranges,
> +                                   debug_line, debug_str);
>  }
>
>  class Symbolizer {
>
> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.h
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.h?rev=161045&r1=161044&r2=161045&view=diff
>
> ==============================================================================
> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.h
> (original)
> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.h Tue Jul
> 31 06:51:26 2012
> @@ -66,6 +66,14 @@
>                        DWARFSection *section);
>  bool IsFullNameOfDWARFSection(const char *full_name, const char
> *short_name);
>
> +class DWARFContext;
> +DWARFContext *getDWARFContext(DWARFSection debug_info,
> +                              DWARFSection debug_abbrev,
> +                              DWARFSection debug_aranges,
> +                              DWARFSection debug_line,
> +                              DWARFSection debug_str);
> +void getLineInfoFromContext(DWARFContext *context, AddressInfo *info);
> +
>  class ModuleDIContext {
>   public:
>    ModuleDIContext(const char *module_name, uptr base_address);
> @@ -76,7 +84,7 @@
>    const char *full_name() const { return full_name_; }
>
>   private:
> -  void CreateDIContext();
> +  void CreateDWARFContext();
>
>    struct AddressRange {
>      uptr beg;
> @@ -90,6 +98,7 @@
>    uptr n_ranges_;
>    uptr mapped_addr_;
>    uptr mapped_size_;
> +  DWARFContext *dwarf_context_;
>  };
>
>  // OS-dependent function that gets the linked list of all loaded modules.
>
> Added: compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_llvm.cc
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_llvm.cc?rev=161045&view=auto
>
> ==============================================================================
> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_llvm.cc
> (added)
> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_llvm.cc
> Tue Jul 31 06:51:26 2012
> @@ -0,0 +1,104 @@
> +//===-- sanitizer_symbolizer_llvm.cc
> --------------------------------------===//
> +//
> +//                     The LLVM Compiler Infrastructure
> +//
> +// This file is distributed under the University of Illinois Open Source
> +// License. See LICENSE.TXT for details.
> +//
>
> +//===----------------------------------------------------------------------===//
> +//
> +// This is a wrapper around llvm::DIContext, moved to separate file to
> +// include LLVM headers in a single place in sanitizer library. If macro
> +// SANITIZER_USES_LLVM_LIBS is not defined, then sanitizer runtime
> +// will not include LLVM headers and will not require static
> +// LLVM libraries to link with.
> +// In this case, the symbolizer will just return zeroes instead of
> +// valid file/line info.
> +//
> +// This file is shared between AddressSanitizer and ThreadSanitizer
> +// run-time libraries.
>
> +//===----------------------------------------------------------------------===//
> +
> +#include "sanitizer_common.h"
> +#include "sanitizer_symbolizer.h"
> +
> +#ifdef SANITIZER_USES_LLVM_LIBS
> +# ifndef __STDC_LIMIT_MACROS
> +#  define __STDC_LIMIT_MACROS 1
> +# endif
> +# ifndef __STDC_CONSTANT_MACROS
> +#  define __STDC_CONSTANT_MACROS 1
> +# endif
> +# include "llvm/ADT/StringRef.h"
> +# include "llvm/DebugInfo/DIContext.h"
> +
> +namespace __sanitizer {
> +
> +static llvm::StringRef ToStringRef(const DWARFSection &section) {
> +  return llvm::StringRef(section.data, section.size);
> +}
> +
> +class DWARFContext : public llvm::DIContext {};
> +
> +DWARFContext *getDWARFContext(DWARFSection debug_info,
> +                              DWARFSection debug_abbrev,
> +                              DWARFSection debug_aranges,
> +                              DWARFSection debug_line,
> +                              DWARFSection debug_str) {
> +  return (DWARFContext*)llvm::DIContext::getDWARFContext(
> +      true, ToStringRef(debug_info), ToStringRef(debug_abbrev),
> +      llvm::StringRef(),  // don't use .debug_aranges for now.
> +      ToStringRef(debug_line), ToStringRef(debug_str));
> +}
> +
> +void getLineInfoFromContext(DWARFContext *context, AddressInfo *info) {
> +  CHECK(context);
> +  uint32_t flags = llvm::DILineInfoSpecifier::FileLineInfo |
> +                   llvm::DILineInfoSpecifier::AbsoluteFilePath |
> +                   llvm::DILineInfoSpecifier::FunctionName;
> +  llvm::DILineInfo line_info = context->getLineInfoForAddress(
> +      info->module_offset, flags);
> +
> +  const char *function = line_info.getFunctionName();
> +  CHECK(function);
> +  if (0 != internal_strcmp("<invalid>", function))
> +    info->function = internal_strdup(function);
> +  else
> +    info->function = 0;
> +
> +  const char *file = line_info.getFileName();
> +  CHECK(file);
> +  if (0 != internal_strcmp("<invalid>", file))
> +    info->file = internal_strdup(file);
> +  else
> +    info->file = 0;
> +
> +  info->line = line_info.getLine();
> +  info->column = line_info.getColumn();
> +}
> +
> +}  // namespace __sanitizer
> +
> +#else  // SANITIZER_USES_LLVM_LIBS
> +namespace __sanitizer {
> +
> +class DWARFContext {};
> +
> +DWARFContext *getDWARFContext(DWARFSection debug_info,
> +                              DWARFSection debug_abbrev,
> +                              DWARFSection debug_aranges,
> +                              DWARFSection debug_line,
> +                              DWARFSection debug_str) {
> +  return 0;
> +}
> +
> +void getLineInfoFromContext(DWARFContext *context, AddressInfo *info) {
> +  (void)context;
> +  info->function = 0;
> +  info->file = 0;
> +  info->line = 0;
> +  info->column = 0;
> +}
> +
> +}  // namespace __sanitizer
> +#endif  // SANITIZER_USES_LLVM_LIBS
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20120813/bc8fe5c5/attachment.html>


More information about the llvm-commits mailing list