@@ -868,6 +868,23 @@ static size_t countSkippableZeroBytes(ArrayRef<uint8_t> Buf) {
868
868
return N & ~0x3 ;
869
869
}
870
870
871
+ // Returns a map from sections to their relocations.
872
+ static std::map<SectionRef, std::vector<RelocationRef>>
873
+ getRelocsMap (llvm::object::ObjectFile const &Obj) {
874
+ std::map<SectionRef, std::vector<RelocationRef>> Ret;
875
+ for (const SectionRef &Section : ToolSectionFilter (Obj)) {
876
+ section_iterator RelSec = Section.getRelocatedSection ();
877
+ if (RelSec == Obj.section_end ())
878
+ continue ;
879
+ std::vector<RelocationRef> &V = Ret[*RelSec];
880
+ for (const RelocationRef &R : Section.relocations ())
881
+ V.push_back (R);
882
+ // Sort relocations by address.
883
+ llvm::sort (V, isRelocAddressLess);
884
+ }
885
+ return Ret;
886
+ }
887
+
871
888
static void disassembleObject (const ObjectFile *Obj, bool InlineRelocs) {
872
889
if (StartAddress > StopAddress)
873
890
error (" Start address should be less than stop address" );
@@ -929,15 +946,9 @@ static void disassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
929
946
930
947
SourcePrinter SP (Obj, TheTarget->getName ());
931
948
932
- // Create a mapping, RelocSecs = SectionRelocMap[S], where sections
933
- // in RelocSecs contain the relocations for section S.
934
- std::error_code EC;
935
- std::map<SectionRef, SmallVector<SectionRef, 1 >> SectionRelocMap;
936
- for (const SectionRef &Section : ToolSectionFilter (*Obj)) {
937
- section_iterator Sec2 = Section.getRelocatedSection ();
938
- if (Sec2 != Obj->section_end ())
939
- SectionRelocMap[*Sec2].push_back (Section);
940
- }
949
+ std::map<SectionRef, std::vector<RelocationRef>> RelocMap;
950
+ if (InlineRelocs)
951
+ RelocMap = getRelocsMap (*Obj);
941
952
942
953
// Create a mapping from virtual address to symbol name. This is used to
943
954
// pretty print the symbols while disassembling.
@@ -1062,19 +1073,6 @@ static void disassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
1062
1073
}
1063
1074
}
1064
1075
1065
- // Make a list of all the relocations for this section.
1066
- std::vector<RelocationRef> Rels;
1067
- if (InlineRelocs) {
1068
- for (const SectionRef &RelocSec : SectionRelocMap[Section]) {
1069
- for (const RelocationRef &Reloc : RelocSec.relocations ()) {
1070
- Rels.push_back (Reloc);
1071
- }
1072
- }
1073
- }
1074
-
1075
- // Sort relocations by address.
1076
- llvm::sort (Rels, isRelocAddressLess);
1077
-
1078
1076
StringRef SegmentName = " " ;
1079
1077
if (const MachOObjectFile *MachO = dyn_cast<const MachOObjectFile>(Obj)) {
1080
1078
DataRefImpl DR = Section.getRawDataRefImpl ();
@@ -1103,6 +1101,7 @@ static void disassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
1103
1101
uint64_t Index;
1104
1102
bool PrintedSection = false ;
1105
1103
1104
+ std::vector<RelocationRef> Rels = RelocMap[Section];
1106
1105
std::vector<RelocationRef>::const_iterator RelCur = Rels.begin ();
1107
1106
std::vector<RelocationRef>::const_iterator RelEnd = Rels.end ();
1108
1107
// Disassemble symbol by symbol.
0 commit comments