Index: tools/llvm-objdump/llvm-objdump.cpp =================================================================== --- tools/llvm-objdump/llvm-objdump.cpp +++ tools/llvm-objdump/llvm-objdump.cpp @@ -917,8 +917,6 @@ // Make a list of all the symbols in this section. std::vector> Symbols; - std::vector DataMappingSymsAddr; - std::vector TextMappingSymsAddr; for (const SymbolRef &Symbol : Obj->symbols()) { if (Section.containsSymbol(Symbol)) { ErrorOr AddressOrErr = Symbol.getAddress(); @@ -931,19 +929,11 @@ ErrorOr Name = Symbol.getName(); error(Name.getError()); Symbols.push_back(std::make_pair(Address, *Name)); - if (Obj->isELF() && Obj->getArch() == Triple::aarch64) { - if (Name->startswith("$d")) - DataMappingSymsAddr.push_back(Address); - if (Name->startswith("$x")) - TextMappingSymsAddr.push_back(Address); - } } } // Sort the symbols by address, just in case they didn't come in that way. array_pod_sort(Symbols.begin(), Symbols.end()); - std::sort(DataMappingSymsAddr.begin(), DataMappingSymsAddr.end()); - std::sort(TextMappingSymsAddr.begin(), TextMappingSymsAddr.end()); // Make a list of all the relocations for this section. std::vector Rels; @@ -1011,36 +1001,37 @@ // AArch64 ELF binaries can interleave data and text in the // same section. We rely on the markers introduced to // understand what we need to dump. - if (Obj->isELF() && Obj->getArch() == Triple::aarch64) { - uint64_t Stride = 0; - - auto DAI = std::lower_bound(DataMappingSymsAddr.begin(), - DataMappingSymsAddr.end(), Index); - if (DAI != DataMappingSymsAddr.end() && *DAI == Index) { - // Switch to data. - while (Index < End) { - outs() << format("%8" PRIx64 ":", SectionAddr + Index); - outs() << "\t"; - if (Index + 4 <= End) { - Stride = 4; - dumpBytes(Bytes.slice(Index, 4), outs()); - outs() << "\t.word"; - } else if (Index + 2 <= End) { - Stride = 2; - dumpBytes(Bytes.slice(Index, 2), outs()); - outs() << "\t.short"; - } else { - Stride = 1; - dumpBytes(Bytes.slice(Index, 1), outs()); - outs() << "\t.byte"; - } - Index += Stride; - outs() << "\n"; - auto TAI = std::lower_bound(TextMappingSymsAddr.begin(), - TextMappingSymsAddr.end(), Index); - if (TAI != TextMappingSymsAddr.end() && *TAI == Index) - break; + auto SymCmp = [](std::pair Sym, uint64_t Index) + -> bool { return Sym.first < Index; }; + uint64_t Stride = 0; + + auto DAI = + std::lower_bound(Symbols.begin(), Symbols.end(), Index, SymCmp); + if (DAI != Symbols.end() && DAI->first == Index && + DAI->second.startswith("$d")) { + while (Index < End) { + outs() << format("%8" PRIx64 ":", SectionAddr + Index); + outs() << "\t"; + if (Index + 4 <= End) { + Stride = 4; + dumpBytes(Bytes.slice(Index, 4), outs()); + outs() << "\t.word"; + } else if (Index + 2 <= End) { + Stride = 2; + dumpBytes(Bytes.slice(Index, 2), outs()); + outs() << "\t.short"; + } else { + Stride = 1; + dumpBytes(Bytes.slice(Index, 1), outs()); + outs() << "\t.byte"; } + Index += Stride; + outs() << "\n"; + auto TAI = + std::lower_bound(Symbols.begin(), Symbols.end(), Index, SymCmp); + if (TAI != Symbols.end() && TAI->first == Index && + TAI->second.startswith("$x")) + break; } }