Skip to content

Commit 2f5efbf

Browse files
libbacktrace: don't strip leading underscore on 64-bit PE
* pecoff.c (coff_initialize_syminfo): Add is_64 parameter. (coff_add): Determine and pass is_64. Closes #28
1 parent 4ae8d98 commit 2f5efbf

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

pecoff.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ coff_is_function_symbol (const b_coff_internal_symbol *isym)
330330

331331
static int
332332
coff_initialize_syminfo (struct backtrace_state *state,
333-
uintptr_t base_address,
333+
uintptr_t base_address, int is_64,
334334
const b_coff_section_header *sects, size_t sects_num,
335335
const b_coff_external_symbol *syms, size_t syms_size,
336336
const unsigned char *strtab, size_t strtab_size,
@@ -426,9 +426,12 @@ coff_initialize_syminfo (struct backtrace_state *state,
426426
else
427427
name = isym.name;
428428

429-
/* Strip leading '_'. */
430-
if (name[0] == '_')
431-
name++;
429+
if (!is_64)
430+
{
431+
/* Strip leading '_'. */
432+
if (name[0] == '_')
433+
name++;
434+
}
432435

433436
/* Symbol value is section relative, so we need to read the address
434437
of its section. */
@@ -605,6 +608,7 @@ coff_add (struct backtrace_state *state, int descriptor,
605608
off_t max_offset;
606609
struct backtrace_view debug_view;
607610
int debug_view_valid;
611+
int is_64;
608612
uintptr_t image_base;
609613
struct dwarf_sections dwarf_sections;
610614

@@ -680,12 +684,16 @@ coff_add (struct backtrace_state *state, int descriptor,
680684
sects = (const b_coff_section_header *)
681685
(sects_view.data + fhdr.size_of_optional_header);
682686

687+
is_64 = 0;
683688
if (fhdr.size_of_optional_header > sizeof (*opt_hdr))
684689
{
685690
if (opt_hdr->magic == PE_MAGIC)
686691
image_base = opt_hdr->u.pe.image_base;
687692
else if (opt_hdr->magic == PEP_MAGIC)
688-
image_base = opt_hdr->u.pep.image_base;
693+
{
694+
image_base = opt_hdr->u.pep.image_base;
695+
is_64 = 1;
696+
}
689697
else
690698
{
691699
error_callback (data, "bad magic in PE optional header", 0);
@@ -778,7 +786,7 @@ coff_add (struct backtrace_state *state, int descriptor,
778786
if (sdata == NULL)
779787
goto fail;
780788

781-
if (!coff_initialize_syminfo (state, image_base,
789+
if (!coff_initialize_syminfo (state, image_base, is_64,
782790
sects, sects_num,
783791
syms_view.data, syms_size,
784792
str_view.data, str_size,

0 commit comments

Comments
 (0)