[PATCH] Fix "llvm-objdump -d -r" to show relocations inline for ELF files
Mark Seaborn
mseaborn at chromium.org
Wed Jan 22 09:26:35 PST 2014
Changed to handle multiple relocation sections per section.
Hi rafael.espindola, rafael,
http://llvm-reviews.chandlerc.com/D2559
CHANGE SINCE LAST DIFF
http://llvm-reviews.chandlerc.com/D2559?vs=6477&id=6574#toc
Files:
test/Object/X86/objdump-disassembly-inline-relocations.test
tools/llvm-objdump/llvm-objdump.cpp
Index: test/Object/X86/objdump-disassembly-inline-relocations.test
===================================================================
--- test/Object/X86/objdump-disassembly-inline-relocations.test
+++ test/Object/X86/objdump-disassembly-inline-relocations.test
@@ -6,6 +6,10 @@
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: 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
Index: tools/llvm-objdump/llvm-objdump.cpp
===================================================================
--- tools/llvm-objdump/llvm-objdump.cpp
+++ tools/llvm-objdump/llvm-objdump.cpp
@@ -382,7 +382,19 @@
}
+ // 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)) {
@@ -418,11 +430,16 @@
// 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);
+ }
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2559.2.patch
Type: text/x-patch
Size: 5058 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140122/e9e6e910/attachment.bin>
More information about the llvm-commits
mailing list