[llvm] r361395 - [llvm-objdump] Dump inline relocations if the relocated section is specified with --section
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Wed May 22 08:12:51 PDT 2019
Author: maskray
Date: Wed May 22 08:12:51 2019
New Revision: 361395
URL: http://llvm.org/viewvc/llvm-project?rev=361395&view=rev
Log:
[llvm-objdump] Dump inline relocations if the relocated section is specified with --section
This fixes PR41886: llvm-objdump -d -r -j .text doesn't show inline relocations of .text
While here, switch to stable_sort() because we don't want to change the order of relocations applied to the same location. gABI says consecutive relocation records are composed together and their order matters. In practise it is difficult to see relocations applied to the same location not consecutive, we just have to keep the relative order of relocations with the same offset.
Reviewed By: grimar
Differential Revision: https://reviews.llvm.org/D62253
Modified:
llvm/trunk/test/tools/llvm-objdump/X86/section-filter-relocs.test
llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
Modified: llvm/trunk/test/tools/llvm-objdump/X86/section-filter-relocs.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objdump/X86/section-filter-relocs.test?rev=361395&r1=361394&r2=361395&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-objdump/X86/section-filter-relocs.test (original)
+++ llvm/trunk/test/tools/llvm-objdump/X86/section-filter-relocs.test Wed May 22 08:12:51 2019
@@ -1,7 +1,4 @@
## Test that --section works correctly for -d with -r.
-## FIXME: Inline relocations are only printed if the relocation section itself is
-## specified with --section. This test just characterizes the existing behavior.
-## See https://bugs.llvm.org/show_bug.cgi?id=41886
# RUN: yaml2obj %s -o %t.o
## Show non-executable sections are not disassembled even if specified,
@@ -12,21 +9,15 @@
## executable sections if requested explicitly.
## See https://bugs.llvm.org/show_bug.cgi?id=41897.
# RUN: llvm-objdump -d -r %t.o --section=.text --section=.rodata \
-# RUN: | FileCheck %s --check-prefix=DISASM --implicit-check-not=.text2 \
-# RUN: --implicit-check-not=.rodata --implicit-check-not=R_X86_64
-
-## Show that only the specified relocation sections that patch the
-## disassembled sections are dumped.
-# RUN: llvm-objdump -d -r %t.o --section=.text \
-# RUN: --section=.rela.text --section=.rela.text2 \
# RUN: | FileCheck %s --check-prefixes=DISASM,RELOC --implicit-check-not=.text2 \
-# RUN: --implicit-check-not=R_X86_64
+# RUN: --implicit-check-not=.rodata
# DISASM: Disassembly of section .text:
# DISASM-EMPTY:
# DISASM-NEXT: 0000000000000400 .text:
# DISASM-NEXT: 400: e8 00 00 00 00 callq 0 <.text+0x5>
# RELOC-NEXT: 00000401: R_X86_64_PC32 foo+1
+# RELOC-NEXT: 00000401: R_X86_64_GOT32 foo
--- !ELF
FileHeader:
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=361395&r1=361394&r2=361395&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp (original)
+++ llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp Wed May 22 08:12:51 2019
@@ -334,18 +334,18 @@ static StringRef ToolName;
typedef std::vector<std::tuple<uint64_t, StringRef, uint8_t>> SectionSymbolsTy;
+static bool shouldKeep(object::SectionRef S) {
+ if (FilterSections.empty())
+ return true;
+ StringRef String;
+ std::error_code error = S.getName(String);
+ if (error)
+ return false;
+ return is_contained(FilterSections, String);
+}
+
SectionFilter ToolSectionFilter(object::ObjectFile const &O) {
- return SectionFilter(
- [](object::SectionRef const &S) {
- if (FilterSections.empty())
- return true;
- StringRef String;
- std::error_code error = S.getName(String);
- if (error)
- return false;
- return is_contained(FilterSections, String);
- },
- O);
+ return SectionFilter([](object::SectionRef S) { return shouldKeep(S); }, O);
}
void error(std::error_code EC) {
@@ -922,15 +922,15 @@ static size_t countSkippableZeroBytes(Ar
static std::map<SectionRef, std::vector<RelocationRef>>
getRelocsMap(object::ObjectFile const &Obj) {
std::map<SectionRef, std::vector<RelocationRef>> Ret;
- for (const SectionRef &Section : ToolSectionFilter(Obj)) {
- section_iterator RelSec = Section.getRelocatedSection();
- if (RelSec == Obj.section_end())
+ for (SectionRef Sec : Obj.sections()) {
+ section_iterator Relocated = Sec.getRelocatedSection();
+ if (Relocated == Obj.section_end() || !shouldKeep(*Relocated))
continue;
- std::vector<RelocationRef> &V = Ret[*RelSec];
- for (const RelocationRef &R : Section.relocations())
+ std::vector<RelocationRef> &V = Ret[*Relocated];
+ for (const RelocationRef &R : Sec.relocations())
V.push_back(R);
// Sort relocations by address.
- llvm::sort(V, isRelocAddressLess);
+ llvm::stable_sort(V, isRelocAddressLess);
}
return Ret;
}
More information about the llvm-commits
mailing list