[PATCH] Support traversing ELF objects for sanitizers needs on FreeBSD in 32-bit mode

Viktor Kutuzov vkutuzov at accesssoftek.com
Fri Jul 25 05:37:51 PDT 2014


Closed by commit rL213940 (authored by vkutuzov).

REPOSITORY
  rL LLVM

http://reviews.llvm.org/D4656

Files:
  compiler-rt/trunk/lib/sanitizer_common/sanitizer_freebsd.h
  compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc

Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_freebsd.h
===================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_freebsd.h
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_freebsd.h
@@ -22,6 +22,7 @@
 #if SANITIZER_FREEBSD && (SANITIZER_WORDSIZE == 32)
 # include <osreldate.h>
 # if __FreeBSD_version <= 902001  // v9.2
+#  include <link.h>
 #  include <ucontext.h>
 
 namespace __sanitizer {
@@ -74,6 +75,34 @@
   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
Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc
===================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc
+++ compiler-rt/trunk/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 <pthread_np.h>
+#include <osreldate.h>
 #define pthread_getattr_np pthread_attr_get_np
 #endif
 
@@ -471,6 +473,10 @@
 #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 {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4656.11873.patch
Type: text/x-patch
Size: 2340 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140725/08cb2228/attachment.bin>


More information about the llvm-commits mailing list