[PATCH] D57019: [llvm-objdump] - Introduce getRelocsMap() helper. NFCI.
George Rimar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 22 06:09:48 PST 2019
This revision was automatically updated to reflect the committed changes.
grimar marked an inline comment as done.
Closed by commit rL351824: [llvm-objdump] - Introduce getRelocsMap() helper. NFCI. (authored by grimar, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D57019?vs=182791&id=182901#toc
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D57019/new/
https://reviews.llvm.org/D57019
Files:
llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
Index: llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
===================================================================
--- llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
+++ llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
@@ -868,6 +868,23 @@
return N & ~0x3;
}
+// Returns a map from sections to their relocations.
+static std::map<SectionRef, std::vector<RelocationRef>>
+getRelocsMap(llvm::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())
+ continue;
+ std::vector<RelocationRef> &V = Ret[*RelSec];
+ for (const RelocationRef &R : Section.relocations())
+ V.push_back(R);
+ // Sort relocations by address.
+ llvm::sort(V, isRelocAddressLess);
+ }
+ return Ret;
+}
+
static void disassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
if (StartAddress > StopAddress)
error("Start address should be less than stop address");
@@ -929,15 +946,9 @@
SourcePrinter SP(Obj, TheTarget->getName());
- // Create a mapping, RelocSecs = SectionRelocMap[S], where sections
- // in RelocSecs contain the relocations for section S.
- std::error_code EC;
- std::map<SectionRef, SmallVector<SectionRef, 1>> SectionRelocMap;
- for (const SectionRef &Section : ToolSectionFilter(*Obj)) {
- section_iterator Sec2 = Section.getRelocatedSection();
- if (Sec2 != Obj->section_end())
- SectionRelocMap[*Sec2].push_back(Section);
- }
+ std::map<SectionRef, std::vector<RelocationRef>> RelocMap;
+ if (InlineRelocs)
+ RelocMap = getRelocsMap(*Obj);
// Create a mapping from virtual address to symbol name. This is used to
// pretty print the symbols while disassembling.
@@ -1062,19 +1073,6 @@
}
}
- // Make a list of all the relocations for this section.
- std::vector<RelocationRef> Rels;
- if (InlineRelocs) {
- for (const SectionRef &RelocSec : SectionRelocMap[Section]) {
- for (const RelocationRef &Reloc : RelocSec.relocations()) {
- Rels.push_back(Reloc);
- }
- }
- }
-
- // Sort relocations by address.
- llvm::sort(Rels, isRelocAddressLess);
-
StringRef SegmentName = "";
if (const MachOObjectFile *MachO = dyn_cast<const MachOObjectFile>(Obj)) {
DataRefImpl DR = Section.getRawDataRefImpl();
@@ -1103,6 +1101,7 @@
uint64_t Index;
bool PrintedSection = false;
+ std::vector<RelocationRef> Rels = RelocMap[Section];
std::vector<RelocationRef>::const_iterator RelCur = Rels.begin();
std::vector<RelocationRef>::const_iterator RelEnd = Rels.end();
// Disassemble symbol by symbol.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57019.182901.patch
Type: text/x-patch
Size: 2764 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190122/cae0d5f0/attachment.bin>
More information about the llvm-commits
mailing list