summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/Object/X86/objdump-disassembly-inline-relocations.test35
-rw-r--r--tools/llvm-objdump/llvm-objdump.cpp29
2 files changed, 58 insertions, 6 deletions
diff --git a/test/Object/X86/objdump-disassembly-inline-relocations.test b/test/Object/X86/objdump-disassembly-inline-relocations.test
index 2ef1a435d7..7861576504 100644
--- a/test/Object/X86/objdump-disassembly-inline-relocations.test
+++ b/test/Object/X86/objdump-disassembly-inline-relocations.test
@@ -6,6 +6,10 @@ RUN: llvm-objdump -d -r %p/../Inputs/trivial-object-test.macho-i386 \
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: 1b: X86_64_RELOC_BRANCH _SomeOther
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
diff --git a/tools/llvm-objdump/llvm-objdump.cpp b/tools/llvm-objdump/llvm-objdump.cpp
index 5efb74f11f..9a56bf9b4c 100644
--- a/tools/llvm-objdump/llvm-objdump.cpp
+++ b/tools/llvm-objdump/llvm-objdump.cpp
@@ -382,7 +382,19 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
}
}
+ // 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 ObjectFile *Obj, bool InlineRelocs) {
// 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);
+ }
}
}