aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-objdump/llvm-objdump.cpp
diff options
context:
space:
mode:
authorFangrui Song <maskray@google.com>2019-05-22 15:12:51 +0000
committerFangrui Song <maskray@google.com>2019-05-22 15:12:51 +0000
commitc289d218b9fa9c78e7ae631208a8b06663dd803d (patch)
tree9a5e24805ede962f9ddc3ff9fcd34e93b88d8b49 /llvm/tools/llvm-objdump/llvm-objdump.cpp
parent74b791b4f721ff17ffbf9322aa6f47e2f3cca0dc (diff)
downloadllvm-c289d218b9fa9c78e7ae631208a8b06663dd803d.zip
llvm-c289d218b9fa9c78e7ae631208a8b06663dd803d.tar.gz
llvm-c289d218b9fa9c78e7ae631208a8b06663dd803d.tar.bz2
[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 llvm-svn: 361395
Diffstat (limited to 'llvm/tools/llvm-objdump/llvm-objdump.cpp')
-rw-r--r--llvm/tools/llvm-objdump/llvm-objdump.cpp34
1 files changed, 17 insertions, 17 deletions
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index c16b0c1..318e0ad 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -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(ArrayRef<uint8_t> Buf) {
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;
}