diff --git a/llvm/test/MC/AArch64/arm64_32-compact-unwind.s b/llvm/test/MC/AArch64/arm64_32-compact-unwind.s --- a/llvm/test/MC/AArch64/arm64_32-compact-unwind.s +++ b/llvm/test/MC/AArch64/arm64_32-compact-unwind.s @@ -4,7 +4,7 @@ ; The compact unwind format in ILP32 mode is pretty much the same, except ; references to addresses (function, personality, LSDA) are pointer-sized. -; CHECK: Contents of section __compact_unwind: +; CHECK: Contents of section __LD,__compact_unwind: ; CHECK-NEXT: 0004 00000000 04000000 00000002 00000000 ; CHECK-NEXT: 0014 00000000 .globl _test_compact_unwind diff --git a/llvm/test/tools/llvm-objdump/MachO/section-contents.test b/llvm/test/tools/llvm-objdump/MachO/section-contents.test --- a/llvm/test/tools/llvm-objdump/MachO/section-contents.test +++ b/llvm/test/tools/llvm-objdump/MachO/section-contents.test @@ -1,16 +1,16 @@ RUN: llvm-objdump --macho -s %p/Inputs/hello.obj.macho-x86_64 | FileCheck %s -CHECK: Contents of section __text: +CHECK: Contents of section __TEXT,__text: CHECK: 0000 554889e5 4883ec20 488d0500 000000c7 UH..H.. H....... CHECK: 0010 45fc0000 0000897d f8488975 f0488955 E......}.H.u.H.U CHECK: 0020 e84889c7 b000e800 000000b9 00000000 .H.............. CHECK: 0030 8945e489 c84883c4 205dc3 .E...H.. ]. -CHECK: Contents of section __cstring: +CHECK: Contents of section __TEXT,__cstring: CHECK: 003b 48656c6c 6f20776f 726c640a 00 Hello world.. -CHECK: Contents of section __compact_unwind: +CHECK: Contents of section __LD,__compact_unwind: CHECK: 0048 00000000 00000000 3b000000 00000001 ........;....... CHECK: 0058 00000000 00000000 00000000 00000000 ................ -CHECK: Contents of section __eh_frame: +CHECK: Contents of section __TEXT,__eh_frame: CHECK: 0068 14000000 00000000 017a5200 01781001 .........zR..x.. CHECK: 0078 100c0708 90010000 24000000 1c000000 ........$....... CHECK: 0088 78ffffff ffffffff 3b000000 00000000 x.......;....... diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp --- a/llvm/tools/llvm-objdump/llvm-objdump.cpp +++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -1619,6 +1619,16 @@ } } +static StringRef getSegmentName(const MachOObjectFile *MachO, + const SectionRef &Section) { + if (MachO) { + DataRefImpl DR = Section.getRawDataRefImpl(); + StringRef SegmentName = MachO->getSectionFinalSegmentName(DR); + return SegmentName; + } + return ""; +} + static void disassembleObject(const Target *TheTarget, const ObjectFile *Obj, MCContext &Ctx, MCDisassembler *PrimaryDisAsm, MCDisassembler *SecondaryDisAsm, @@ -1783,12 +1793,7 @@ } } - StringRef SegmentName = ""; - if (MachO) { - DataRefImpl DR = Section.getRawDataRefImpl(); - SegmentName = MachO->getSectionFinalSegmentName(DR); - } - + StringRef SegmentName = getSegmentName(MachO, Section); StringRef SectionName = unwrapOrError(Section.getName(), Obj->getFileName()); // If the section has no symbol at the start, just insert a dummy one. if (Symbols.empty() || Symbols[0].Addr != 0) { @@ -2388,6 +2393,8 @@ } void objdump::printSectionContents(const ObjectFile *Obj) { + const MachOObjectFile *MachO = dyn_cast(Obj); + for (const SectionRef &Section : ToolSectionFilter(*Obj)) { StringRef Name = unwrapOrError(Section.getName(), Obj->getFileName()); uint64_t BaseAddr = Section.getAddress(); @@ -2395,7 +2402,11 @@ if (!Size) continue; - outs() << "Contents of section " << Name << ":\n"; + outs() << "Contents of section "; + StringRef SegmentName = getSegmentName(MachO, Section); + if (!SegmentName.empty()) + outs() << SegmentName << ","; + outs() << Name << ":\n"; if (Section.isBSS()) { outs() << format("\n", @@ -2553,11 +2564,9 @@ } else if (Section == O->section_end()) { outs() << "*UND*"; } else { - if (MachO) { - DataRefImpl DR = Section->getRawDataRefImpl(); - StringRef SegmentName = MachO->getSectionFinalSegmentName(DR); + StringRef SegmentName = getSegmentName(MachO, *Section); + if (!SegmentName.empty()) outs() << SegmentName << ","; - } StringRef SectionName = unwrapOrError(Section->getName(), FileName); outs() << SectionName; }