From 2fde54f48cdf7655bba13a8d0e898c174e3ab6e4 Mon Sep 17 00:00:00 2001 From: Viktor Kutuzov Date: Fri, 25 Jul 2014 12:29:04 +0000 Subject: [PATCH] Support traversing ELF objects for sanitizers needs on FreeBSD in 32-bit mode Differential Revision: http://reviews.llvm.org/D4656 llvm-svn: 213940 --- .../lib/sanitizer_common/sanitizer_freebsd.h | 29 ++++++++++++++++++++++ .../sanitizer_common/sanitizer_linux_libcdep.cc | 6 +++++ 2 files changed, 35 insertions(+) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_freebsd.h b/compiler-rt/lib/sanitizer_common/sanitizer_freebsd.h index 52a2a85..eea248f 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_freebsd.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_freebsd.h @@ -22,6 +22,7 @@ #if SANITIZER_FREEBSD && (SANITIZER_WORDSIZE == 32) # include # if __FreeBSD_version <= 902001 // v9.2 +# include # include namespace __sanitizer { @@ -74,6 +75,34 @@ typedef struct __xucontext { int __spare__[4]; } xucontext_t; +typedef struct { + __uint32_t p_type; + __uint32_t p_offset; + __uint32_t p_vaddr; + __uint32_t p_paddr; + __uint32_t p_filesz; + __uint32_t p_memsz; + __uint32_t p_flags; + __uint32_t p_align; +} XElf32_Phdr; + +struct xdl_phdr_info { + Elf_Addr dlpi_addr; + const char *dlpi_name; + const XElf32_Phdr *dlpi_phdr; + Elf_Half dlpi_phnum; + unsigned long long int dlpi_adds; + unsigned long long int dlpi_subs; + size_t dlpi_tls_modid; + void *dlpi_tls_data; +}; + +typedef int (*__xdl_iterate_hdr_callback)(struct xdl_phdr_info*, size_t, void*); +typedef int xdl_iterate_phdr_t(__xdl_iterate_hdr_callback, void*); + +#define xdl_iterate_phdr(callback, param) \ + (((xdl_iterate_phdr_t*) dl_iterate_phdr)((callback), (param))) + } // namespace __sanitizer # endif // __FreeBSD_version <= 902001 diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cc b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cc index 92e6b78..26fc36514 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cc @@ -17,6 +17,7 @@ #include "sanitizer_common.h" #include "sanitizer_flags.h" +#include "sanitizer_freebsd.h" #include "sanitizer_linux.h" #include "sanitizer_placement_new.h" #include "sanitizer_procmaps.h" @@ -35,6 +36,7 @@ #if SANITIZER_FREEBSD #include +#include #define pthread_getattr_np pthread_attr_get_np #endif @@ -471,6 +473,10 @@ uptr GetListOfModules(LoadedModule *modules, uptr max_modules, #else // SANITIZER_ANDROID # if !SANITIZER_FREEBSD typedef ElfW(Phdr) Elf_Phdr; +# elif SANITIZER_WORDSIZE == 32 && __FreeBSD_version <= 902001 // v9.2 +# define Elf_Phdr XElf32_Phdr +# define dl_phdr_info xdl_phdr_info +# define dl_iterate_phdr(c, b) xdl_iterate_phdr((c), (b)) # endif struct DlIteratePhdrData { -- 2.7.4