From 218b64b5aede69b9788f9c75ff9e185d9472cd5d Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Thu, 13 Aug 2015 18:31:43 +0000 Subject: [PATCH] [llvm-cxxdump] Correctly process relocations when given multiple files Archive files wouldn't lead to us reprocessing the section relocations for the new object files. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@244932 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llvm-cxxdump/llvm-cxxdump.cpp | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/tools/llvm-cxxdump/llvm-cxxdump.cpp b/tools/llvm-cxxdump/llvm-cxxdump.cpp index b2a653700b4..ede13f7aca5 100644 --- a/tools/llvm-cxxdump/llvm-cxxdump.cpp +++ b/tools/llvm-cxxdump/llvm-cxxdump.cpp @@ -64,20 +64,7 @@ static void reportError(StringRef Input, std::error_code EC) { reportError(Input, EC.message()); } -static SmallVectorImpl &getRelocSections(const ObjectFile *Obj, - const SectionRef &Sec) { - static bool MappingDone = false; - static std::map> SectionRelocMap; - if (!MappingDone) { - for (const SectionRef &Section : Obj->sections()) { - section_iterator Sec2 = Section.getRelocatedSection(); - if (Sec2 != Obj->section_end()) - SectionRelocMap[*Sec2].push_back(Section); - } - MappingDone = true; - } - return SectionRelocMap[Sec]; -} +static std::map> SectionRelocMap; static void collectRelocatedSymbols(const ObjectFile *Obj, const SectionRef &Sec, uint64_t SecAddress, @@ -85,7 +72,7 @@ static void collectRelocatedSymbols(const ObjectFile *Obj, StringRef *I, StringRef *E) { uint64_t SymOffset = SymAddress - SecAddress; uint64_t SymEnd = SymOffset + SymSize; - for (const SectionRef &SR : getRelocSections(Obj, Sec)) { + for (const SectionRef &SR : SectionRelocMap[Sec]) { for (const object::RelocationRef &Reloc : SR.relocations()) { if (I == E) break; @@ -109,7 +96,7 @@ static void collectRelocationOffsets( std::map, StringRef> &Collection) { uint64_t SymOffset = SymAddress - SecAddress; uint64_t SymEnd = SymOffset + SymSize; - for (const SectionRef &SR : getRelocSections(Obj, Sec)) { + for (const SectionRef &SR : SectionRelocMap[Sec]) { for (const object::RelocationRef &Reloc : SR.relocations()) { const object::symbol_iterator RelocSymI = Reloc.getSymbol(); if (RelocSymI == Obj->symbol_end()) @@ -173,6 +160,13 @@ static void dumpCXXData(const ObjectFile *Obj) { std::map, StringRef> VTTEntries; std::map TINames; + SectionRelocMap.clear(); + for (const SectionRef &Section : Obj->sections()) { + section_iterator Sec2 = Section.getRelocatedSection(); + if (Sec2 != Obj->section_end()) + SectionRelocMap[*Sec2].push_back(Section); + } + uint8_t BytesInAddress = Obj->getBytesInAddress(); std::vector> SymAddr = -- 2.34.1