# HG changeset patch # User Michael Spacefalcon # Date 1396511223 0 # Node ID 193926ccd1ecc33db741b98a19475d2e0c9f1a0f # Parent f9fde7f36ae341122cacd54fd85117d502854ad3 tiobjd: better handling of section-relative relocs diff -r f9fde7f36ae3 -r 193926ccd1ec ticoff/disasm.c --- a/ticoff/disasm.c Thu Apr 03 07:16:20 2014 +0000 +++ b/ticoff/disasm.c Thu Apr 03 07:47:03 2014 +0000 @@ -13,6 +13,32 @@ extern unsigned get_u16(), get_u32(); +static void +find_better_symbol(symp, addp) + struct internal_syment **symp; + unsigned *addp; +{ + struct internal_scnhdr *sec; + unsigned addr; + struct internal_syment *sym, *symsel; + unsigned n; + + sec = (*symp)->section; + addr = *addp; + symsel = 0; + for (n = 0; n < sec->nsymbols; n++) { + sym = sec->sorted_symbols[n]; + if (sym->value > addr) + break; + if (sym->class == C_EXT || sym->class == C_STAT) + symsel = sym; + } + if (symsel) { + *symp = symsel; + *addp = addr - symsel->value; + } +} + void disasm_reloc_target(sec, rel, addend) struct internal_scnhdr *sec; @@ -22,6 +48,8 @@ struct internal_syment *sym = rel->sym; addend -= sym->value; + if (sym->section && !strcmp(sym->name, sym->section->name)) + find_better_symbol(&sym, &addend); if (addend >= 10) printf("%s+0x%x", sym->name, addend); else if (addend) @@ -185,6 +213,7 @@ get_int_section_table(); get_int_symbol_table(); extern_profile_report("Module"); + sort_symbols_of_all_sec(); for (secnum = 0; secnum < nsections; secnum++) { sec = sections + secnum; printf("=== %s ===\n", sec->name); diff -r f9fde7f36ae3 -r 193926ccd1ec ticoff/symtab.c --- a/ticoff/symtab.c Thu Apr 03 07:16:20 2014 +0000 +++ b/ticoff/symtab.c Thu Apr 03 07:47:03 2014 +0000 @@ -200,6 +200,20 @@ compare_for_sort); } +void +sort_symbols_of_all_sec() +{ + unsigned n; + struct internal_scnhdr *sec; + + for (n = 0; n < nsections; n++) { + sec = sections + n; + if (!sec->nsymbols) + continue; + sort_symbols_of_sec(sec); + } +} + cmd_nm() { unsigned n, m;