# HG changeset patch # User Michael Spacefalcon # Date 1396506006 0 # Node ID d97fbe98600b840bf067fb0d9bb158232dea2564 # Parent 61a58677dc68a1593d816fc8215a7d7065feba7a tiobjd: recognizing relocs in ldr literals diff -r 61a58677dc68 -r d97fbe98600b ticoff/armdis.c --- a/ticoff/armdis.c Thu Apr 03 05:54:59 2014 +0000 +++ b/ticoff/armdis.c Thu Apr 03 06:20:06 2014 +0000 @@ -11,6 +11,7 @@ #include "globals.h" extern unsigned get_u16(), get_u32(); +extern struct internal_reloc *find_reloc(); extern char *regnames[16], *condition_decode[16], *shift_types[4]; @@ -220,6 +221,7 @@ unsigned off, word, loff; { unsigned litoff, datum; + struct internal_reloc *rel; /* base reg must be 15 */ if (((word >> 16) & 0xF) != 15) @@ -245,6 +247,7 @@ if (litoff >= sec->size) return(0); /* all checks passed, proceed */ + rel = find_reloc(sec, litoff); switch (size) { case 1: datum = filemap[sec->data_offset + litoff]; @@ -256,7 +259,12 @@ datum = get_u32(filemap + sec->data_offset + litoff); break; } - printf("=0x%x\t; via 0x%x\n", datum, litoff); + putchar('='); + if (rel) + disasm_reloc_target(sec, rel, datum); + else + printf("0x%x", datum); + printf("\t; via 0x%x\n", litoff); return(1); } diff -r 61a58677dc68 -r d97fbe98600b ticoff/reloc.c --- a/ticoff/reloc.c Thu Apr 03 05:54:59 2014 +0000 +++ b/ticoff/reloc.c Thu Apr 03 06:20:06 2014 +0000 @@ -123,3 +123,21 @@ } exit(0); } + +struct internal_reloc * +find_reloc(sec, loc) + struct internal_scnhdr *sec; + unsigned loc; +{ + struct internal_reloc *rel; + unsigned m; + + rel = sec->int_relocs; + for (m = 0; m < sec->nreloc; m++, rel++) { + if (rel->location == loc) + return(rel); + if (rel->location > loc) + return(0); + } + return(0); +} diff -r 61a58677dc68 -r d97fbe98600b ticoff/thumbdis.c --- a/ticoff/thumbdis.c Thu Apr 03 05:54:59 2014 +0000 +++ b/ticoff/thumbdis.c Thu Apr 03 06:20:06 2014 +0000 @@ -11,6 +11,7 @@ #include "globals.h" extern unsigned get_u16(), get_u32(); +extern struct internal_reloc *find_reloc(); extern char *regnames[16], *condition_decode[16], *shift_types[4]; @@ -114,16 +115,23 @@ struct internal_scnhdr *sec; unsigned off, word; { - unsigned loff, litoff; + unsigned loff, litoff, datum; + struct internal_reloc *rel; loff = (word & 0xFF) << 2; off &= ~3; off += 4; litoff = off + loff; - if (litoff+4 <= sec->size) - printf("ldr\t%s, =0x%x\t; via 0x%x\n", regnames[(word>>8)&7], - get_u32(filemap + sec->data_offset + litoff), litoff); - else + if (litoff+4 <= sec->size) { + rel = find_reloc(sec, litoff); + datum = get_u32(filemap + sec->data_offset + litoff); + printf("ldr\t%s, =", regnames[(word>>8)&7]); + if (rel) + disasm_reloc_target(sec, rel, datum); + else + printf("0x%x", datum); + printf("\t; via 0x%x\n", litoff); + } else printf("ldr\t%s, [pc, #%u]\t(0x%x)\n", regnames[(word>>8)&7], loff, litoff); }