# HG changeset patch # User Michael Spacefalcon # Date 1404444161 0 # Node ID 452baa748747c477cfef2e28cf8031cdc80cda30 # Parent ddbfc1a1a8112dcc90ab79238b805eac9783a1fb objgrep: -r implemented diff -r ddbfc1a1a811 -r 452baa748747 objgrep/dumpmatch.c --- a/objgrep/dumpmatch.c Fri Jul 04 03:07:09 2014 +0000 +++ b/objgrep/dumpmatch.c Fri Jul 04 03:22:41 2014 +0000 @@ -38,3 +38,70 @@ } } } + +static unsigned +arm_branch_reloc(location) + unsigned location; +{ + unsigned word, dest; + + word = get_u32(binfilemap + location); + dest = (word & 0x00FFFFFF) << 2; + if (dest & 0x02000000) + dest |= 0xFC000000; + dest += location + 8; + return(dest); +} + +static unsigned +thumb_bl_reloc(location) + unsigned location; +{ + unsigned ins1, ins2; + unsigned dest; + + ins1 = get_u16(binfilemap + location); + ins2 = get_u16(binfilemap + location + 2); + dest = ((ins1 & 0x7FF) << 12) | ((ins2 & 0x7FF) << 1); + if (dest & 0x00400000) + dest |= 0xFF800000; + dest += location + 4; + return(dest); +} + +dump_relocs_on_match() +{ + unsigned n, value; + struct internal_reloc *rel; + + printf("\nDeduced from relocs:\n\n"); + for (n = 0, rel = relocs; n < grep_section->nreloc; n++, rel++) { + switch (rel->type) { + case RTYPE_LONG: + value = get_u32(binfilemap + match_offset + + rel->location); + break; + case RTYPE_ARM_B: + value = arm_branch_reloc(match_offset + rel->location); + break; + case RTYPE_THUMB_BL: + value = thumb_bl_reloc(match_offset + rel->location); + break; + default: + fprintf(stderr, + "BUG in dump_relocs_on_match(): bad reloc type\n"); + abort(); + } + value -= rel->addend; + if (rel->secbase) + printf("%s:%s = %08X\n", objfilename, + rel->secbase->name, value); + else if (rel->extsym) + printf("%s = %08X\n", rel->extsym->name, value); + else { + fprintf(stderr, + "BUG in dump_relocs_on_match(): no base for reloc\n"); + abort(); + } + } +} diff -r ddbfc1a1a811 -r 452baa748747 objgrep/main.c --- a/objgrep/main.c Fri Jul 04 03:07:09 2014 +0000 +++ b/objgrep/main.c Fri Jul 04 03:22:41 2014 +0000 @@ -68,5 +68,7 @@ binfilename, match_offset); if (sflag) dump_symtab_on_match(); + if (rflag && grep_section->nreloc) + dump_relocs_on_match(); exit(0); }