[llvm] r200090 - Fix "llvm-objdump -d -r" to show relocations inline for ELF files
Mark Seaborn
mseaborn at chromium.org
Sat Jan 25 09:38:19 PST 2014
Author: mseaborn
Date: Sat Jan 25 11:38:19 2014
New Revision: 200090
URL: http://llvm.org/viewvc/llvm-project?rev=200090&view=rev
Log:
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
Modified:
llvm/trunk/test/Object/X86/objdump-disassembly-inline-relocations.test
llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
Modified: llvm/trunk/test/Object/X86/objdump-disassembly-inline-relocations.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/X86/objdump-disassembly-inline-relocations.test?rev=200090&r1=200089&r2=200090&view=diff
==============================================================================
--- llvm/trunk/test/Object/X86/objdump-disassembly-inline-relocations.test (original)
+++ llvm/trunk/test/Object/X86/objdump-disassembly-inline-relocations.test Sat Jan 25 11:38:19 2014
@@ -6,6 +6,10 @@ RUN: llvm-objdump -d -r %p/../Inputs/tri
RUN: | FileCheck %s -check-prefix MACHO-i386
RUN: llvm-objdump -d -r %p/../Inputs/trivial-object-test.macho-x86-64 \
RUN: | FileCheck %s -check-prefix MACHO-x86-64
+RUN: llvm-objdump -d -r %p/../Inputs/trivial-object-test.elf-i386 \
+RUN: | FileCheck %s -check-prefix ELF-i386
+RUN: llvm-objdump -d -r %p/../Inputs/trivial-object-test.elf-x86-64 \
+RUN: | FileCheck %s -check-prefix ELF-x86-64
COFF-i386: file format COFF-i386
COFF-i386: Disassembly of section .text:
@@ -65,3 +69,34 @@ MACHO-x86-64:
MACHO-x86-64: 1f: 8b 44 24 04 movl 4(%rsp), %eax
MACHO-x86-64: 23: 48 83 c4 08 addq $8, %rsp
MACHO-x86-64: 27: c3 ret
+
+ELF-i386: file format ELF32-i386
+ELF-i386: Disassembly of section .text:
+ELF-i386: main:
+ELF-i386: 0: 83 ec 0c subl $12, %esp
+ELF-i386: 3: c7 44 24 08 00 00 00 00 movl $0, 8(%esp)
+ELF-i386: b: c7 04 24 00 00 00 00 movl $0, (%esp)
+ELF-i386: e: R_386_32 Unknown
+ELF-i386: 12: e8 fc ff ff ff calll -4
+ELF-i386: 13: R_386_PC32 Unknown
+ELF-i386: 17: e8 fc ff ff ff calll -4
+ELF-i386: 18: R_386_PC32 Unknown
+ELF-i386: 1c: 8b 44 24 08 movl 8(%esp), %eax
+ELF-i386: 20: 83 c4 0c addl $12, %esp
+ELF-i386: 23: c3 ret
+
+ELF-x86-64: file format ELF64-x86-64
+ELF-x86-64: Disassembly of section .text:
+ELF-x86-64: main:
+ELF-x86-64: 0: 48 83 ec 08 subq $8, %rsp
+ELF-x86-64: 4: c7 44 24 04 00 00 00 00 movl $0, 4(%rsp)
+ELF-x86-64: c: bf 00 00 00 00 movl $0, %edi
+ELF-x86-64: d: R_X86_64_32S .rodata.str1.1+0
+ELF-x86-64: 11: e8 00 00 00 00 callq 0
+ELF-x86-64: 12: R_X86_64_PC32 puts-4-P
+ELF-x86-64: 16: 30 c0 xorb %al, %al
+ELF-x86-64: 18: e8 00 00 00 00 callq 0
+ELF-x86-64: 19: R_X86_64_PC32 SomeOtherFunction-4-P
+ELF-x86-64: 1d: 8b 44 24 04 movl 4(%rsp), %eax
+ELF-x86-64: 21: 48 83 c4 08 addq $8, %rsp
+ELF-x86-64: 25: c3 ret
Modified: llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp?rev=200090&r1=200089&r2=200090&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp (original)
+++ llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp Sat Jan 25 11:38:19 2014
@@ -382,7 +382,19 @@ static void DisassembleObject(const Obje
}
}
+ // Create a mapping, RelocSecs = SectionRelocMap[S], where sections
+ // in RelocSecs contain the relocations for section S.
error_code EC;
+ std::map<SectionRef, SmallVector<SectionRef, 1> > SectionRelocMap;
+ for (section_iterator I = Obj->begin_sections(), E = Obj->end_sections();
+ I != E; I.increment(EC)) {
+ if (error(EC))
+ break;
+ section_iterator Sec2 = I->getRelocatedSection();
+ if (Sec2 != Obj->end_sections())
+ SectionRelocMap[*Sec2].push_back(*I);
+ }
+
for (section_iterator I = Obj->begin_sections(), E = Obj->end_sections();
I != E; I.increment(EC)) {
if (error(EC))
@@ -423,12 +435,17 @@ static void DisassembleObject(const Obje
// Make a list of all the relocations for this section.
std::vector<RelocationRef> Rels;
if (InlineRelocs) {
- for (relocation_iterator RI = I->begin_relocations(),
- RE = I->end_relocations();
- RI != RE; RI.increment(EC)) {
- if (error(EC))
- break;
- Rels.push_back(*RI);
+ SmallVectorImpl<SectionRef> *RelocSecs = &SectionRelocMap[*I];
+ for (SmallVectorImpl<SectionRef>::iterator RelocSec = RelocSecs->begin(),
+ E = RelocSecs->end();
+ RelocSec != E; ++RelocSec) {
+ for (relocation_iterator RI = RelocSec->begin_relocations(),
+ RE = RelocSec->end_relocations();
+ RI != RE; RI.increment(EC)) {
+ if (error(EC))
+ break;
+ Rels.push_back(*RI);
+ }
}
}
More information about the llvm-commits
mailing list