mirror of
https://github.com/ianlancetaylor/libbacktrace.git
synced 2026-03-29 21:49:06 +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:
30
pecoff.c
30
pecoff.c
@@ -382,10 +382,11 @@ coff_is_function_symbol (const b_coff_internal_symbol *isym)
|
||||
|
||||
static int
|
||||
coff_initialize_syminfo (struct backtrace_state *state,
|
||||
uintptr_t base_address, int is_64,
|
||||
const b_coff_section_header *sects, size_t sects_num,
|
||||
const b_coff_external_symbol *syms, size_t syms_size,
|
||||
const unsigned char *strtab, size_t strtab_size,
|
||||
struct libbacktrace_base_address base_address,
|
||||
int is_64, const b_coff_section_header *sects,
|
||||
size_t sects_num, const b_coff_external_symbol *syms,
|
||||
size_t syms_size, const unsigned char *strtab,
|
||||
size_t strtab_size,
|
||||
backtrace_error_callback error_callback,
|
||||
void *data, struct coff_syminfo_data *sdata)
|
||||
{
|
||||
@@ -490,9 +491,10 @@ coff_initialize_syminfo (struct backtrace_state *state,
|
||||
secnum = coff_read2 (asym->section_number);
|
||||
|
||||
coff_sym->name = name;
|
||||
coff_sym->address = (coff_read4 (asym->value)
|
||||
+ sects[secnum - 1].virtual_address
|
||||
+ base_address);
|
||||
coff_sym->address =
|
||||
libbacktrace_add_base ((coff_read4 (asym->value)
|
||||
+ sects[secnum - 1].virtual_address),
|
||||
base_address);
|
||||
coff_sym++;
|
||||
}
|
||||
|
||||
@@ -662,8 +664,8 @@ coff_add (struct backtrace_state *state, int descriptor,
|
||||
struct backtrace_view debug_view;
|
||||
int debug_view_valid;
|
||||
int is_64;
|
||||
uintptr_t image_base;
|
||||
uintptr_t base_address = 0;
|
||||
struct libbacktrace_base_address image_base;
|
||||
struct libbacktrace_base_address base_address;
|
||||
struct dwarf_sections dwarf_sections;
|
||||
|
||||
*found_sym = 0;
|
||||
@@ -739,13 +741,14 @@ coff_add (struct backtrace_state *state, int descriptor,
|
||||
(sects_view.data + fhdr.size_of_optional_header);
|
||||
|
||||
is_64 = 0;
|
||||
memset (&image_base, 0, sizeof image_base);
|
||||
if (fhdr.size_of_optional_header > sizeof (*opt_hdr))
|
||||
{
|
||||
if (opt_hdr->magic == PE_MAGIC)
|
||||
image_base = opt_hdr->u.pe.image_base;
|
||||
image_base.m = opt_hdr->u.pe.image_base;
|
||||
else if (opt_hdr->magic == PEP_MAGIC)
|
||||
{
|
||||
image_base = opt_hdr->u.pep.image_base;
|
||||
image_base.m = opt_hdr->u.pep.image_base;
|
||||
is_64 = 1;
|
||||
}
|
||||
else
|
||||
@@ -754,8 +757,6 @@ coff_add (struct backtrace_state *state, int descriptor,
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
else
|
||||
image_base = 0;
|
||||
|
||||
/* Read the symbol table and the string table. */
|
||||
|
||||
@@ -910,8 +911,9 @@ coff_add (struct backtrace_state *state, int descriptor,
|
||||
+ (sections[i].offset - min_offset));
|
||||
}
|
||||
|
||||
memset (&base_address, 0, sizeof base_address);
|
||||
#ifdef HAVE_WINDOWS_H
|
||||
base_address = module_handle - image_base;
|
||||
base_address.m = module_handle - image_base.m;
|
||||
#endif
|
||||
|
||||
if (!backtrace_dwarf_add (state, base_address, &dwarf_sections,
|
||||
|
||||
Reference in New Issue
Block a user