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 @@ -0,0 +1,32 @@ +# RUN: llvm-mc -filetype=obj -triple=aarch64-unknown-freebsd %s -o %t +# RUN: llvm-objdump -d %t | FileCheck %s + +.section .mysection,"ax",@progbits +.globl _start +_start: + adr x1,msg +msg: .asciz "Hello, world\n" +msgend: + +.section .myothersection,"ax",@progbits + adrp x1,mystr +mystr: + .asciz "blah" + .size mystr, 4 + +# CHECK: Disassembly of section .mysection: +# CHECK: _start: +# CHECK: 0: 21 00 00 10 adr x1, #4 +# CHECK: +# CHECK: msg: +# CHECK: 4: 48 65 6c 6c .word +# CHECK: 8: 6f 2c 20 77 .word +# 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: +# CHECK: mystr: +# CHECK: 4: 62 6c 61 68 .word +# CHECK: 8: 00 .byte Index: tools/llvm-objdump/llvm-objdump.cpp =================================================================== --- tools/llvm-objdump/llvm-objdump.cpp +++ tools/llvm-objdump/llvm-objdump.cpp @@ -917,6 +917,8 @@ // 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(); @@ -929,6 +931,12 @@ 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); + } } } @@ -998,6 +1006,48 @@ for (Index = Start; Index < End; Index += Size) { MCInst Inst; + // 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; + + for (auto &DA : DataMappingSymsAddr) { + // Switch to data. + if (Index == DA) { + 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"; + for (auto &TA : TextMappingSymsAddr) + // Switch back to text. + if (Index == TA) + break; + } + break; + } + } + } + + if (Index >= End) + break; + if (DisAsm->getInstruction(Inst, Size, Bytes.slice(Index), SectionAddr + Index, DebugOut, CommentStream)) {