changeset 133:daeaa5950d10

tiobjd: Thumb bl w/o reloc: find symbol if there is one
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Mon, 07 Apr 2014 01:22:09 +0000
parents af0f8bfa3b3a
children c131238c56bf
files leo-obj/tool/disasm.c leo-obj/tool/thumbdis.c
diffstat 2 files changed, 32 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/leo-obj/tool/disasm.c	Mon Apr 07 00:59:34 2014 +0000
+++ b/leo-obj/tool/disasm.c	Mon Apr 07 01:22:09 2014 +0000
@@ -14,7 +14,7 @@
 extern unsigned get_u16(), get_u32();
 extern char *storage_class_to_string();
 
-static int auto_xlat_section_relocs = 1;
+int auto_xlat_section_relocs = 1;
 
 static void
 find_better_symbol(sec, symp, addp)
--- a/leo-obj/tool/thumbdis.c	Mon Apr 07 00:59:34 2014 +0000
+++ b/leo-obj/tool/thumbdis.c	Mon Apr 07 01:22:09 2014 +0000
@@ -8,6 +8,7 @@
 #include <string.h>
 #include <strings.h>
 #include "intstruct.h"
+#include "coffconst.h"
 #include "globals.h"
 
 extern unsigned get_u16(), get_u32();
@@ -15,6 +16,8 @@
 
 extern char *regnames[16], *condition_decode[16], *shift_types[4];
 
+extern int auto_xlat_section_relocs;
+
 static void
 format_1_2(word)
 	unsigned word;
@@ -389,12 +392,35 @@
 	}
 }
 
+static char *
+bl_norel_find_symbol(sec, dest)
+	struct internal_scnhdr *sec;
+	unsigned dest;
+{
+	struct internal_syment *sym;
+	unsigned n;
+
+	for (n = 0; n < sec->nsymbols; n++) {
+		sym = sec->sorted_symbols[n];
+		if (sym->value > dest)
+			break;
+		if (sym->value < dest)
+			continue;
+		if (sym->class != C_EXT && sym->class != C_STAT)
+			continue;
+		if (sym->name[0] == '$')
+			return(sym->name);
+	}
+	return(0);
+}
+
 thumb_check_bl(sec, off)
 	struct internal_scnhdr *sec;
 	unsigned off;
 {
 	unsigned ins1, ins2;
 	unsigned dest;
+	char *destsym;
 
 	ins1 = get_u16(filemap + sec->data_offset + off);
 	if ((ins1 & 0xF800) != 0xF000)
@@ -407,7 +433,11 @@
 	if (dest & 0x00400000)
 		dest |= 0xFF800000;
 	dest += off + 4;
-	printf("%04x %04x\tbl\t0x%x\n", ins1, ins2, dest);
+	printf("%04x %04x\tbl\t", ins1, ins2);
+	destsym = bl_norel_find_symbol(sec, dest);
+	if (destsym)
+		printf("%s\t; ", destsym);
+	printf("0x%x\n", dest);
 	return(1);
 }