Index: test/tools/llvm-objdump/AArch64/elf-aarch64-mapping-symbols.test =================================================================== --- test/tools/llvm-objdump/AArch64/elf-aarch64-mapping-symbols.test +++ test/tools/llvm-objdump/AArch64/elf-aarch64-mapping-symbols.test @@ -23,7 +23,6 @@ # CHECK: c: 6f 72 6c 64 .word # CHECK: 10: 0a 00 .short # CHECK: Disassembly of section .myothersection: -# CHECK: $x.2: # CHECK: 0: 01 00 00 90 adrp x1, #0 # CHECK: mystr: # CHECK: 4: 62 6c 61 68 .word 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,14 @@ 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()); + // Also make sure that mapping symbols come first. + std::sort(Symbols.begin(), Symbols.end(), []( + std::pair A, std::pair B) { + return (A.first < B.first) || (A.first == B.first && A.second.startswith("$"));}); // Make a list of all the relocations for this section. std::vector Rels; @@ -984,12 +977,23 @@ uint64_t Size; uint64_t Index; + bool DataInCode = false; std::vector::const_iterator rel_cur = Rels.begin(); std::vector::const_iterator rel_end = Rels.end(); // Disassemble symbol by symbol. for (unsigned si = 0, se = Symbols.size(); si != se; ++si) { + // Mapping symbols. + if (Symbols[si].second.startswith("$d")) { + DataInCode = true; + continue; + } + if (Symbols[si].second.startswith("$x")) { + DataInCode = false; + continue; + } + uint64_t Start = Symbols[si].first; // The end is either the section end or the beginning of the next symbol. uint64_t End = (si == se - 1) ? SectSize : Symbols[si + 1].first; @@ -1011,42 +1015,26 @@ // 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; - } + if (DataInCode) { + outs() << format("%8" PRIx64 ":", SectionAddr + Index); + outs() << "\t"; + if (Index + 4 <= End) { + Size = 4; + dumpBytes(Bytes.slice(Index, 4), outs()); + outs() << "\t.word"; + } else if (Index + 2 <= End) { + Size = 2; + dumpBytes(Bytes.slice(Index, 2), outs()); + outs() << "\t.short"; + } else { + Size = 1; + dumpBytes(Bytes.slice(Index, 1), outs()); + outs() << "\t.byte"; } + outs() << "\n"; + continue; } - if (Index >= End) - break; - if (DisAsm->getInstruction(Inst, Size, Bytes.slice(Index), SectionAddr + Index, DebugOut, CommentStream)) {