[llvm-commits] [compiler-rt] r161862 - in /compiler-rt/trunk/lib/sanitizer_common: CMakeLists.txt sanitizer_linux.cc sanitizer_mac.cc sanitizer_symbolizer_linux.cc sanitizer_symbolizer_mac.cc sanitizer_symbolizer_win.cc sanitizer_win.cc
Alexey Samsonov
samsonov at google.com
Tue Aug 14 06:00:32 PDT 2012
Author: samsonov
Date: Tue Aug 14 08:00:32 2012
New Revision: 161862
URL: http://llvm.org/viewvc/llvm-project?rev=161862&view=rev
Log:
[Sanitizer] move OS-dependent pieces of symbolizer to separate source files
Added:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_linux.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_mac.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_win.cc
Modified:
compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt
compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc
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=161862&r1=161861&r2=161862&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt Tue Aug 14 08:00:32 2012
@@ -11,7 +11,10 @@
sanitizer_posix.cc
sanitizer_printf.cc
sanitizer_symbolizer.cc
+ sanitizer_symbolizer_linux.cc
sanitizer_symbolizer_llvm.cc
+ sanitizer_symbolizer_mac.cc
+ sanitizer_symbolizer_win.cc
sanitizer_win.cc
)
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc?rev=161862&r1=161861&r2=161862&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc Tue Aug 14 08:00:32 2012
@@ -18,11 +18,8 @@
#include "sanitizer_libc.h"
#include "sanitizer_placement_new.h"
#include "sanitizer_procmaps.h"
-#include "sanitizer_symbolizer.h"
-#include <elf.h>
#include <fcntl.h>
-#include <link.h>
#include <pthread.h>
#include <sched.h>
#include <sys/mman.h>
@@ -163,86 +160,6 @@
return 0; // Not found.
}
-// ------------------ sanitizer_symbolizer.h
-typedef ElfW(Ehdr) Elf_Ehdr;
-typedef ElfW(Shdr) Elf_Shdr;
-typedef ElfW(Phdr) Elf_Phdr;
-
-bool FindDWARFSection(uptr object_file_addr, const char *section_name,
- DWARFSection *section) {
- Elf_Ehdr *exe = (Elf_Ehdr*)object_file_addr;
- Elf_Shdr *sections = (Elf_Shdr*)(object_file_addr + exe->e_shoff);
- uptr section_names = object_file_addr +
- sections[exe->e_shstrndx].sh_offset;
- for (int i = 0; i < exe->e_shnum; i++) {
- Elf_Shdr *current_section = §ions[i];
- const char *current_name = (const char*)section_names +
- current_section->sh_name;
- if (IsFullNameOfDWARFSection(current_name, section_name)) {
- section->data = (const char*)object_file_addr +
- current_section->sh_offset;
- section->size = current_section->sh_size;
- return true;
- }
- }
- return false;
-}
-
-#ifdef ANDROID
-uptr GetListOfModules(ModuleDIContext *modules, uptr max_modules) {
- UNIMPLEMENTED();
-}
-#else // ANDROID
-struct DlIteratePhdrData {
- ModuleDIContext *modules;
- uptr current_n;
- uptr max_n;
-};
-
-static const uptr kMaxPathLength = 512;
-
-static int dl_iterate_phdr_cb(dl_phdr_info *info, size_t size, void *arg) {
- DlIteratePhdrData *data = (DlIteratePhdrData*)arg;
- if (data->current_n == data->max_n)
- return 0;
- char *module_name = 0;
- if (data->current_n == 0) {
- // First module is the binary itself.
- module_name = (char*)InternalAlloc(kMaxPathLength);
- uptr module_name_len = readlink("/proc/self/exe",
- module_name, kMaxPathLength);
- CHECK_NE(module_name_len, (uptr)-1);
- CHECK_LT(module_name_len, kMaxPathLength);
- module_name[module_name_len] = '\0';
- } else if (info->dlpi_name) {
- module_name = internal_strdup(info->dlpi_name);
- }
- if (module_name == 0 || module_name[0] == '\0')
- return 0;
- void *mem = &data->modules[data->current_n];
- ModuleDIContext *cur_module = new(mem) ModuleDIContext(module_name,
- info->dlpi_addr);
- data->current_n++;
- for (int i = 0; i < info->dlpi_phnum; i++) {
- const Elf_Phdr *phdr = &info->dlpi_phdr[i];
- if (phdr->p_type == PT_LOAD) {
- uptr cur_beg = info->dlpi_addr + phdr->p_vaddr;
- uptr cur_end = cur_beg + phdr->p_memsz;
- cur_module->addAddressRange(cur_beg, cur_end);
- }
- }
- InternalFree(module_name);
- return 0;
-}
-
-uptr GetListOfModules(ModuleDIContext *modules, uptr max_modules) {
- CHECK(modules);
- DlIteratePhdrData data = {modules, 0, max_modules};
- dl_iterate_phdr(dl_iterate_phdr_cb, &data);
- return data.current_n;
-}
-#endif // ANDROID
-
// ----------------- sanitizer_procmaps.h
ProcessMaps::ProcessMaps() {
proc_self_maps_buff_len_ =
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc?rev=161862&r1=161861&r2=161862&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc Tue Aug 14 08:00:32 2012
@@ -18,7 +18,6 @@
#include "sanitizer_internal_defs.h"
#include "sanitizer_libc.h"
#include "sanitizer_procmaps.h"
-#include "sanitizer_symbolizer.h"
#include <crt_externs.h> // for _NSGetEnviron
#include <fcntl.h>
@@ -107,18 +106,6 @@
return 0;
}
-// ------------------ sanitizer_symbolizer.h
-bool FindDWARFSection(uptr object_file_addr, const char *section_name,
- DWARFSection *section) {
- UNIMPLEMENTED();
- return false;
-}
-
-uptr GetListOfModules(ModuleDIContext *modules, uptr max_modules) {
- UNIMPLEMENTED();
- return 0;
-}
-
// ----------------- sanitizer_procmaps.h
ProcessMaps::ProcessMaps() {
Added: compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_linux.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_linux.cc?rev=161862&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_linux.cc (added)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_linux.cc Tue Aug 14 08:00:32 2012
@@ -0,0 +1,107 @@
+//===-- sanitizer_symbolizer_linux.cc -------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file is shared between AddressSanitizer and ThreadSanitizer
+// run-time libraries.
+// Linux-specific implementation of symbolizer parts.
+//===----------------------------------------------------------------------===//
+#ifdef __linux__
+#include "sanitizer_common.h"
+#include "sanitizer_internal_defs.h"
+#include "sanitizer_placement_new.h"
+#include "sanitizer_symbolizer.h"
+
+#include <elf.h>
+#include <link.h>
+#include <unistd.h>
+
+namespace __sanitizer {
+
+typedef ElfW(Ehdr) Elf_Ehdr;
+typedef ElfW(Shdr) Elf_Shdr;
+typedef ElfW(Phdr) Elf_Phdr;
+
+bool FindDWARFSection(uptr object_file_addr, const char *section_name,
+ DWARFSection *section) {
+ Elf_Ehdr *exe = (Elf_Ehdr*)object_file_addr;
+ Elf_Shdr *sections = (Elf_Shdr*)(object_file_addr + exe->e_shoff);
+ uptr section_names = object_file_addr +
+ sections[exe->e_shstrndx].sh_offset;
+ for (int i = 0; i < exe->e_shnum; i++) {
+ Elf_Shdr *current_section = §ions[i];
+ const char *current_name = (const char*)section_names +
+ current_section->sh_name;
+ if (IsFullNameOfDWARFSection(current_name, section_name)) {
+ section->data = (const char*)object_file_addr +
+ current_section->sh_offset;
+ section->size = current_section->sh_size;
+ return true;
+ }
+ }
+ return false;
+}
+
+#ifdef ANDROID
+uptr GetListOfModules(ModuleDIContext *modules, uptr max_modules) {
+ UNIMPLEMENTED();
+}
+#else // ANDROID
+struct DlIteratePhdrData {
+ ModuleDIContext *modules;
+ uptr current_n;
+ uptr max_n;
+};
+
+static const uptr kMaxPathLength = 512;
+
+static int dl_iterate_phdr_cb(dl_phdr_info *info, size_t size, void *arg) {
+ DlIteratePhdrData *data = (DlIteratePhdrData*)arg;
+ if (data->current_n == data->max_n)
+ return 0;
+ char *module_name = 0;
+ if (data->current_n == 0) {
+ // First module is the binary itself.
+ module_name = (char*)InternalAlloc(kMaxPathLength);
+ uptr module_name_len = readlink("/proc/self/exe",
+ module_name, kMaxPathLength);
+ CHECK_NE(module_name_len, (uptr)-1);
+ CHECK_LT(module_name_len, kMaxPathLength);
+ module_name[module_name_len] = '\0';
+ } else if (info->dlpi_name) {
+ module_name = internal_strdup(info->dlpi_name);
+ }
+ if (module_name == 0 || module_name[0] == '\0')
+ return 0;
+ void *mem = &data->modules[data->current_n];
+ ModuleDIContext *cur_module = new(mem) ModuleDIContext(module_name,
+ info->dlpi_addr);
+ data->current_n++;
+ for (int i = 0; i < info->dlpi_phnum; i++) {
+ const Elf_Phdr *phdr = &info->dlpi_phdr[i];
+ if (phdr->p_type == PT_LOAD) {
+ uptr cur_beg = info->dlpi_addr + phdr->p_vaddr;
+ uptr cur_end = cur_beg + phdr->p_memsz;
+ cur_module->addAddressRange(cur_beg, cur_end);
+ }
+ }
+ InternalFree(module_name);
+ return 0;
+}
+
+uptr GetListOfModules(ModuleDIContext *modules, uptr max_modules) {
+ CHECK(modules);
+ DlIteratePhdrData data = {modules, 0, max_modules};
+ dl_iterate_phdr(dl_iterate_phdr_cb, &data);
+ return data.current_n;
+}
+#endif // ANDROID
+
+} // namespace __sanitizer
+
+#endif // __linux__
Added: compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_mac.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_mac.cc?rev=161862&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_mac.cc (added)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_mac.cc Tue Aug 14 08:00:32 2012
@@ -0,0 +1,33 @@
+//===-- sanitizer_symbolizer_mac.cc ---------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file is shared between AddressSanitizer and ThreadSanitizer
+// run-time libraries.
+// Mac-specific implementation of symbolizer parts.
+//===----------------------------------------------------------------------===//
+#ifdef __APPLE__
+#include "sanitizer_internal_defs.h"
+#include "sanitizer_symbolizer.h"
+
+namespace __sanitizer {
+
+bool FindDWARFSection(uptr object_file_addr, const char *section_name,
+ DWARFSection *section) {
+ UNIMPLEMENTED();
+ return false;
+}
+
+uptr GetListOfModules(ModuleDIContext *modules, uptr max_modules) {
+ UNIMPLEMENTED();
+ return 0;
+}
+
+} // namespace __sanitizer
+
+#endif // __APPLE__
Added: compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_win.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_win.cc?rev=161862&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_win.cc (added)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_win.cc Tue Aug 14 08:00:32 2012
@@ -0,0 +1,35 @@
+//===-- sanitizer_symbolizer_win.cc ---------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file is shared between AddressSanitizer and ThreadSanitizer
+// run-time libraries.
+// Windows-specific implementation of symbolizer parts.
+//===----------------------------------------------------------------------===//
+#ifdef _WIN32
+#include <windows.h>
+
+#include "sanitizer_internal_defs.h"
+#include "sanitizer_symbolizer.h"
+
+namespace __sanitizer {
+
+bool FindDWARFSection(uptr object_file_addr, const char *section_name,
+ DWARFSection *section) {
+ UNIMPLEMENTED();
+ return false;
+}
+
+uptr GetListOfModules(ModuleDIContext *modules, uptr max_modules) {
+ UNIMPLEMENTED();
+ return 0;
+};
+
+} // namespace __sanitizer
+
+#endif // _WIN32
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc?rev=161862&r1=161861&r2=161862&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc Tue Aug 14 08:00:32 2012
@@ -16,7 +16,6 @@
#include "sanitizer_common.h"
#include "sanitizer_libc.h"
-#include "sanitizer_symbolizer.h"
namespace __sanitizer {
@@ -130,17 +129,6 @@
return atexit(function);
}
-// ------------------ sanitizer_symbolizer.h
-bool FindDWARFSection(uptr object_file_addr, const char *section_name,
- DWARFSection *section) {
- UNIMPLEMENTED();
- return false;
-}
-
-uptr GetListOfModules(ModuleDIContext *modules, uptr max_modules) {
- UNIMPLEMENTED();
-};
-
// ------------------ sanitizer_libc.h
void *internal_mmap(void *addr, uptr length, int prot, int flags,
int fd, u64 offset) {
More information about the llvm-commits
mailing list