changeset 118:193926ccd1ec

tiobjd: better handling of section-relative relocs
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Thu, 03 Apr 2014 07:47:03 +0000
parents f9fde7f36ae3
children fb1e47bebe00
files ticoff/disasm.c ticoff/symtab.c
diffstat 2 files changed, 43 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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);
--- 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;