Skip to content

Commit

Permalink
libbacktrace: update xcoff.c for base_address changes
Browse files Browse the repository at this point in the history
	* xcoff.c (struct xcoff_fileline_data): Change base_address field
	to struct libbacktrace_base_address.
	(xcoff_initialize_syminfo): Change base_address to struct
	libbacktrace_base_address.  Use libbacktrace_add_base.
	(xcoff_initialize_fileline): Likewise.
	(xcoff_lookup_pc): Use libbacktrace_add_base.
	(xcoff_add): Change base_address to struct
	libbacktrace_base_address.
	(xcoff_armem_add, xcoff_add_shared_libs): Likewise.
	(backtrace_initialize): Likewise.
	* Makefile.am (xcoff.lo): Remove unused target.
	(xcoff_32.lo, xcoff_64.lo): New targets.
	* Makefile.in: Regenerate.
  • Loading branch information
ianlancetaylor committed Aug 5, 2024
1 parent 6ce91a2 commit 86885d1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 21 deletions.
3 changes: 2 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,8 @@ sort.lo: config.h backtrace.h internal.h
stest.lo: config.h backtrace.h internal.h
state.lo: config.h backtrace.h backtrace-supported.h internal.h
unknown.lo: config.h backtrace.h internal.h
xcoff.lo: config.h backtrace.h internal.h
xcoff_32.lo: config.h backtrace.h internal.h
xcoff_64.lo: config.h backtrace.h internal.h
xztest.lo: config.h backtrace.h backtrace-supported.h internal.h testlib.h
ztest.lo: config.h backtrace.h backtrace-supported.h internal.h testlib.h

3 changes: 2 additions & 1 deletion Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -2810,7 +2810,8 @@ sort.lo: config.h backtrace.h internal.h
stest.lo: config.h backtrace.h internal.h
state.lo: config.h backtrace.h backtrace-supported.h internal.h
unknown.lo: config.h backtrace.h internal.h
xcoff.lo: config.h backtrace.h internal.h
xcoff_32.lo: config.h backtrace.h internal.h
xcoff_64.lo: config.h backtrace.h internal.h
xztest.lo: config.h backtrace.h backtrace-supported.h internal.h testlib.h
ztest.lo: config.h backtrace.h backtrace-supported.h internal.h testlib.h

Expand Down
46 changes: 27 additions & 19 deletions xcoff.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ struct xcoff_fileline_data
size_t linenos_size;
uint64_t lnnoptr0;
/* Loader address. */
uintptr_t base_address;
struct libbacktrace_base_address base_address;
};

/* Information we gather for the DWARF sections we care about. */
Expand Down Expand Up @@ -586,7 +586,7 @@ xcoff_symname (const b_xcoff_syment *asym,

static int
xcoff_initialize_syminfo (struct backtrace_state *state,
uintptr_t base_address,
struct libbacktrace_base_address base_address,
const b_xcoff_syment *syms, size_t nsyms,
const unsigned char *strtab, size_t strtab_size,
backtrace_error_callback error_callback, void *data,
Expand Down Expand Up @@ -628,7 +628,8 @@ xcoff_initialize_syminfo (struct backtrace_state *state,
{
const b_xcoff_auxent *aux = (const b_xcoff_auxent *) (asym + 1);
xcoff_symbols[j].name = xcoff_symname (asym, strtab, strtab_size);
xcoff_symbols[j].address = base_address + asym->n_value;
xcoff_symbols[j].address =
libbacktrace_add_base (asym->n_value, base_address);
/* x_fsize will be 0 if there is no debug information. */
xcoff_symbols[j].size = aux->x_fcn.x_fsize;
++j;
Expand Down Expand Up @@ -766,7 +767,8 @@ xcoff_lookup_pc (struct backtrace_state *state ATTRIBUTE_UNUSED,
lineno = (const b_xcoff_lineno *) lineptr;
if (lineno->l_lnno == 0)
break;
if (pc <= fdata->base_address + lineno->l_addr.l_paddr)
if (pc <= libbacktrace_add_base (lineno->l_addr.l_paddr,
fdata->base_address))
break;
match = lnnoptr;
lnno = lineno->l_lnno;
Expand Down Expand Up @@ -860,7 +862,7 @@ xcoff_fileline (struct backtrace_state *state, uintptr_t pc,

static int
xcoff_initialize_fileline (struct backtrace_state *state,
uintptr_t base_address,
struct libbacktrace_base_address base_address,
const b_xcoff_scnhdr *sects,
const b_xcoff_syment *syms, size_t nsyms,
const unsigned char *strtab, size_t strtab_size,
Expand Down Expand Up @@ -1001,7 +1003,7 @@ xcoff_initialize_fileline (struct backtrace_state *state,
fn->name = xcoff_symname (fsym, strtab, strtab_size);
fn->filename = filename;
fn->sect_base = sects[fsym->n_scnum - 1].s_paddr;
fn->pc = base_address + fsym->n_value;
fn->pc = libbacktrace_add_base (fsym->n_value, base_address);
fn->size = fsize;
fn->lnno = lnno;
fn->lnnoptr = lnnoptr;
Expand Down Expand Up @@ -1070,7 +1072,8 @@ xcoff_initialize_fileline (struct backtrace_state *state,

static int
xcoff_add (struct backtrace_state *state, int descriptor, off_t offset,
uintptr_t base_address, backtrace_error_callback error_callback,
struct libbacktrace_base_address base_address,
backtrace_error_callback error_callback,
void *data, fileline *fileline_fn, int *found_sym, int exe)
{
struct backtrace_view fhdr_view;
Expand Down Expand Up @@ -1159,9 +1162,9 @@ xcoff_add (struct backtrace_state *state, int descriptor, off_t offset,
On AIX, virtual address is either fixed for executable
or given by ldinfo. This address will include the XCOFF
headers. */
base_address = ((exe ? XCOFF_AIX_TEXTBASE : base_address)
+ stext->s_scnptr
- stext->s_paddr);
base_address.m = ((exe ? XCOFF_AIX_TEXTBASE : base_address.m)
+ stext->s_scnptr
- stext->s_paddr);

lnnoptr = stext->s_lnnoptr;
nlnno = stext->s_nlnno;
Expand Down Expand Up @@ -1393,9 +1396,9 @@ xcoff_parse_decimal (const char *buf, size_t size, off_t *off)

static int
xcoff_armem_add (struct backtrace_state *state, int descriptor,
uintptr_t base_address, const char *member,
backtrace_error_callback error_callback, void *data,
fileline *fileline_fn, int *found_sym)
struct libbacktrace_base_address base_address,
const char *member, backtrace_error_callback error_callback,
void *data, fileline *fileline_fn, int *found_sym)
{
struct backtrace_view view;
b_ar_fl_hdr fl_hdr;
Expand Down Expand Up @@ -1516,6 +1519,8 @@ xcoff_add_shared_libs (struct backtrace_state *state,
ldinfo = (const struct ld_info *) buf;
while ((const char *) ldinfo < (const char *) buf + buflen)
{
struct libbacktrace_base_address base_address;

if (*ldinfo->ldinfo_filename != '/')
goto next;

Expand All @@ -1527,16 +1532,17 @@ xcoff_add_shared_libs (struct backtrace_state *state,
/* Check if it is an archive (member name not empty). */

member = ldinfo->ldinfo_filename + strlen (ldinfo->ldinfo_filename) + 1;
memset (&base_address, 0, sizeof base_address);
base_address.m = (uintptr_t) ldinfo->ldinfo_textorg;
if (*member)
{
xcoff_armem_add (state, descriptor,
(uintptr_t) ldinfo->ldinfo_textorg, member,
xcoff_armem_add (state, descriptor, base_address, member,
error_callback, data, fileline_fn, &lib_found_sym);
}
else
{
xcoff_add (state, descriptor, 0, (uintptr_t) ldinfo->ldinfo_textorg,
error_callback, data, fileline_fn, &lib_found_sym, 0);
xcoff_add (state, descriptor, 0, base_address, error_callback, data,
fileline_fn, &lib_found_sym, 0);
}
if (lib_found_sym)
*found_sym = 1;
Expand All @@ -1561,12 +1567,14 @@ backtrace_initialize (struct backtrace_state *state,
backtrace_error_callback error_callback,
void *data, fileline *fileline_fn)
{
struct libbacktrace_base_address zero_base_address;
int ret;
int found_sym;
fileline xcoff_fileline_fn = xcoff_nodebug;

ret = xcoff_add (state, descriptor, 0, 0, error_callback, data,
&xcoff_fileline_fn, &found_sym, 1);
memset (&zero_base_address, 0, sizeof zero_base_address);
ret = xcoff_add (state, descriptor, 0, zero_base_address,
error_callback, data, &xcoff_fileline_fn, &found_sym, 1);
if (!ret)
return 0;

Expand Down

0 comments on commit 86885d1

Please sign in to comment.