llvm.org GIT mirror llvm / 2effd6c
Fix "llvm-objdump -d -r" to show relocations inline for ELF files This fixes a regression introduced by r182908, which broke llvm-objdump's ability to display relocations inline in a disassembly dump for ELF object files. That change removed a SectionRelocMap from Object/ELF.h, which we recreate in llvm-objdump.cpp. I discovered this regression via an out-of-tree test (test/NaCl/X86/pnacl-hides-sandbox-x86-64.ll) which used llvm-objdump. Note that the "Unknown" string in the test output on i386 isn't quite right, but this appears to be a pre-existing bug. Differential Revision: http://llvm-reviews.chandlerc.com/D2559 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@200090 91177308-0d34-0410-b5e6-96231b3b80d8 Mark Seaborn 6 years ago
2 changed file(s) with 58 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
55 RUN: | FileCheck %s -check-prefix MACHO-i386
66 RUN: llvm-objdump -d -r %p/../Inputs/trivial-object-test.macho-x86-64 \
77 RUN: | FileCheck %s -check-prefix MACHO-x86-64
8 RUN: llvm-objdump -d -r %p/../Inputs/trivial-object-test.elf-i386 \
9 RUN: | FileCheck %s -check-prefix ELF-i386
10 RUN: llvm-objdump -d -r %p/../Inputs/trivial-object-test.elf-x86-64 \
11 RUN: | FileCheck %s -check-prefix ELF-x86-64
812
913 COFF-i386: file format COFF-i386
1014 COFF-i386: Disassembly of section .text:
6468 MACHO-x86-64: 1f: 8b 44 24 04 movl 4(%rsp), %eax
6569 MACHO-x86-64: 23: 48 83 c4 08 addq $8, %rsp
6670 MACHO-x86-64: 27: c3 ret
71
72 ELF-i386: file format ELF32-i386
73 ELF-i386: Disassembly of section .text:
74 ELF-i386: main:
75 ELF-i386: 0: 83 ec 0c subl $12, %esp
76 ELF-i386: 3: c7 44 24 08 00 00 00 00 movl $0, 8(%esp)
77 ELF-i386: b: c7 04 24 00 00 00 00 movl $0, (%esp)
78 ELF-i386: e: R_386_32 Unknown
79 ELF-i386: 12: e8 fc ff ff ff calll -4
80 ELF-i386: 13: R_386_PC32 Unknown
81 ELF-i386: 17: e8 fc ff ff ff calll -4
82 ELF-i386: 18: R_386_PC32 Unknown
83 ELF-i386: 1c: 8b 44 24 08 movl 8(%esp), %eax
84 ELF-i386: 20: 83 c4 0c addl $12, %esp
85 ELF-i386: 23: c3 ret
86
87 ELF-x86-64: file format ELF64-x86-64
88 ELF-x86-64: Disassembly of section .text:
89 ELF-x86-64: main:
90 ELF-x86-64: 0: 48 83 ec 08 subq $8, %rsp
91 ELF-x86-64: 4: c7 44 24 04 00 00 00 00 movl $0, 4(%rsp)
92 ELF-x86-64: c: bf 00 00 00 00 movl $0, %edi
93 ELF-x86-64: d: R_X86_64_32S .rodata.str1.1+0
94 ELF-x86-64: 11: e8 00 00 00 00 callq 0
95 ELF-x86-64: 12: R_X86_64_PC32 puts-4-P
96 ELF-x86-64: 16: 30 c0 xorb %al, %al
97 ELF-x86-64: 18: e8 00 00 00 00 callq 0
98 ELF-x86-64: 19: R_X86_64_PC32 SomeOtherFunction-4-P
99 ELF-x86-64: 1d: 8b 44 24 04 movl 4(%rsp), %eax
100 ELF-x86-64: 21: 48 83 c4 08 addq $8, %rsp
101 ELF-x86-64: 25: c3 ret
381381 }
382382 }
383383
384 // Create a mapping, RelocSecs = SectionRelocMap[S], where sections
385 // in RelocSecs contain the relocations for section S.
384386 error_code EC;
387 std::map > SectionRelocMap;
388 for (section_iterator I = Obj->begin_sections(), E = Obj->end_sections();
389 I != E; I.increment(EC)) {
390 if (error(EC))
391 break;
392 section_iterator Sec2 = I->getRelocatedSection();
393 if (Sec2 != Obj->end_sections())
394 SectionRelocMap[*Sec2].push_back(*I);
395 }
396
385397 for (section_iterator I = Obj->begin_sections(), E = Obj->end_sections();
386398 I != E; I.increment(EC)) {
387399 if (error(EC))
422434 // Make a list of all the relocations for this section.
423435 std::vector Rels;
424436 if (InlineRelocs) {
425 for (relocation_iterator RI = I->begin_relocations(),
426 RE = I->end_relocations();
427 RI != RE; RI.increment(EC)) {
428 if (error(EC))
429 break;
430 Rels.push_back(*RI);
437 SmallVectorImpl *RelocSecs = &SectionRelocMap[*I];
438 for (SmallVectorImpl::iterator RelocSec = RelocSecs->begin(),
439 E = RelocSecs->end();
440 RelocSec != E; ++RelocSec) {
441 for (relocation_iterator RI = RelocSec->begin_relocations(),
442 RE = RelocSec->end_relocations();
443 RI != RE; RI.increment(EC)) {
444 if (error(EC))
445 break;
446 Rels.push_back(*RI);
447 }
431448 }
432449 }
433450