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

Differential Revision: http://reviews.llvm.org/D4656

llvm-svn: 213940
This commit is contained in:
Viktor Kutuzov 2014-07-25 12:29:04 +00:00
parent 1f8930e3d3
commit 2fde54f48c
2 changed files with 35 additions and 0 deletions

View File

@ -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 @@ 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

View File

@ -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 @@ 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 {