mirror of
https://github.com/ianlancetaylor/libbacktrace.git
synced 2026-03-25 19:49:07 +08:00
libbacktrace: support FDPIC
Based on patch by Max Filippov. * internal.h: If FDPIC, #include <link.h> and/or <sys/link.h>. (libbacktrace_using_fdpic): Define. (struct libbacktrace_base_address): Define. (libbacktrace_add_base): Define. (backtrace_dwarf_add): Change base_address to struct libbacktrace_base_address. * dwarf.c (struct dwarf_data): Change base_address to struct libbacktrace_base_address. (add_ranges, find_address_ranges, build_ddress_map): Likewise. (build_dwarf_data, build_dwarf_add): Likewise. (add_low_high_range): Change base_address to struct libbacktrace_base_address. Use libbacktrace_add_base. (add_ranges_from_ranges, add_ranges_from_rnglists): Likewise. (add_line): Use libbacktrace_add_base. * elf.c (elf_initialize_syminfo): Change base_address to struct libbacktrace_base_address. Use libbacktrace_add_base. (elf_add): Change base_address to struct libbacktrace_base_address. (phdr_callback): Likewise. Initialize base_address.m. (backtrace_initialize): If using FDPIC, don't call elf_add with main executable; always use dl_iterate_phdr. * macho.c (macho_add_symtab): Change base_address to struct libbacktrace_base_address. Use libbacktrace_add_base. (macho_syminfo): Change base_address to struct libbacktrace_base_address. (macho_add_fat, macho_add_dsym, macho_add): Likewise. (backtrace_initialize): Likewise. Initialize base_address.m. * pecoff.c (coff_initialize_syminfo): Change base_address to struct libbacktrace_base_address. Use libbacktrace_add_base. (coff_add): Change base_address to struct libbacktrace_base_address. Initialize base_address.m.
This commit is contained in:
25
macho.c
25
macho.c
@@ -315,8 +315,9 @@ static const char * const dwarf_section_names[DEBUG_MAX] =
|
||||
/* Forward declaration. */
|
||||
|
||||
static int macho_add (struct backtrace_state *, const char *, int, off_t,
|
||||
const unsigned char *, uintptr_t, int,
|
||||
backtrace_error_callback, void *, fileline *, int *);
|
||||
const unsigned char *, struct libbacktrace_base_address,
|
||||
int, backtrace_error_callback, void *, fileline *,
|
||||
int *);
|
||||
|
||||
/* A dummy callback function used when we can't find any debug info. */
|
||||
|
||||
@@ -511,7 +512,7 @@ macho_defined_symbol (uint8_t type)
|
||||
|
||||
static int
|
||||
macho_add_symtab (struct backtrace_state *state, int descriptor,
|
||||
uintptr_t base_address, int is_64,
|
||||
struct libbacktrace_base_address base_address, int is_64,
|
||||
off_t symoff, unsigned int nsyms, off_t stroff,
|
||||
unsigned int strsize,
|
||||
backtrace_error_callback error_callback, void *data)
|
||||
@@ -626,7 +627,7 @@ macho_add_symtab (struct backtrace_state *state, int descriptor,
|
||||
if (name[0] == '_')
|
||||
++name;
|
||||
macho_symbols[j].name = name;
|
||||
macho_symbols[j].address = value + base_address;
|
||||
macho_symbols[j].address = libbacktrace_add_base (value, base_address);
|
||||
++j;
|
||||
}
|
||||
|
||||
@@ -758,7 +759,8 @@ macho_syminfo (struct backtrace_state *state, uintptr_t addr,
|
||||
static int
|
||||
macho_add_fat (struct backtrace_state *state, const char *filename,
|
||||
int descriptor, int swapped, off_t offset,
|
||||
const unsigned char *match_uuid, uintptr_t base_address,
|
||||
const unsigned char *match_uuid,
|
||||
struct libbacktrace_base_address base_address,
|
||||
int skip_symtab, uint32_t nfat_arch, int is_64,
|
||||
backtrace_error_callback error_callback, void *data,
|
||||
fileline *fileline_fn, int *found_sym)
|
||||
@@ -860,7 +862,8 @@ macho_add_fat (struct backtrace_state *state, const char *filename,
|
||||
|
||||
static int
|
||||
macho_add_dsym (struct backtrace_state *state, const char *filename,
|
||||
uintptr_t base_address, const unsigned char *uuid,
|
||||
struct libbacktrace_base_address base_address,
|
||||
const unsigned char *uuid,
|
||||
backtrace_error_callback error_callback, void *data,
|
||||
fileline* fileline_fn)
|
||||
{
|
||||
@@ -978,7 +981,7 @@ macho_add_dsym (struct backtrace_state *state, const char *filename,
|
||||
static int
|
||||
macho_add (struct backtrace_state *state, const char *filename, int descriptor,
|
||||
off_t offset, const unsigned char *match_uuid,
|
||||
uintptr_t base_address, int skip_symtab,
|
||||
struct libbacktrace_base_address base_address, int skip_symtab,
|
||||
backtrace_error_callback error_callback, void *data,
|
||||
fileline *fileline_fn, int *found_sym)
|
||||
{
|
||||
@@ -1240,7 +1243,7 @@ backtrace_initialize (struct backtrace_state *state, const char *filename,
|
||||
c = _dyld_image_count ();
|
||||
for (i = 0; i < c; ++i)
|
||||
{
|
||||
uintptr_t base_address;
|
||||
struct libbacktrace_base_address base_address;
|
||||
const char *name;
|
||||
int d;
|
||||
fileline mff;
|
||||
@@ -1264,7 +1267,7 @@ backtrace_initialize (struct backtrace_state *state, const char *filename,
|
||||
continue;
|
||||
}
|
||||
|
||||
base_address = _dyld_get_image_vmaddr_slide (i);
|
||||
base_address.m = _dyld_get_image_vmaddr_slide (i);
|
||||
|
||||
mff = macho_nodebug;
|
||||
if (!macho_add (state, name, d, 0, NULL, base_address, 0,
|
||||
@@ -1319,10 +1322,12 @@ backtrace_initialize (struct backtrace_state *state, const char *filename,
|
||||
void *data, fileline *fileline_fn)
|
||||
{
|
||||
fileline macho_fileline_fn;
|
||||
struct libbacktrace_base_address zero_base_address;
|
||||
int found_sym;
|
||||
|
||||
macho_fileline_fn = macho_nodebug;
|
||||
if (!macho_add (state, filename, descriptor, 0, NULL, 0, 0,
|
||||
memset (&zero_base_address, 0, sizeof zero_base_address);
|
||||
if (!macho_add (state, filename, descriptor, 0, NULL, zero_base_address, 0,
|
||||
error_callback, data, &macho_fileline_fn, &found_sym))
|
||||
return 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user