[llvm] 3f1a9b7 - [objdump][macho] Emit segment names along with section names
Daniel Sanders via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 4 09:57:13 PDT 2020
Author: Daniel Sanders
Date: 2020-09-04T09:57:02-07:00
New Revision: 3f1a9b7eca0a969e18aabefa3ceb9054b94c17c0
URL: https://github.com/llvm/llvm-project/commit/3f1a9b7eca0a969e18aabefa3ceb9054b94c17c0
DIFF: https://github.com/llvm/llvm-project/commit/3f1a9b7eca0a969e18aabefa3ceb9054b94c17c0.diff
LOG: [objdump][macho] Emit segment names along with section names
I recently came across a MachO with multiple sections of the same name but
different segments. We should emit the segment name alongside the section name
for MachO's.
Differential Revision: https://reviews.llvm.org/D87119
Added:
Modified:
llvm/test/MC/AArch64/arm64_32-compact-unwind.s
llvm/test/tools/llvm-objdump/MachO/section-contents.test
llvm/tools/llvm-objdump/llvm-objdump.cpp
Removed:
################################################################################
diff --git a/llvm/test/MC/AArch64/arm64_32-compact-unwind.s b/llvm/test/MC/AArch64/arm64_32-compact-unwind.s
index 59d882ae3a5c..d221640a0747 100644
--- 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
index cd68e1fa550b..d938e903fd07 100644
--- 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
index 6b3ecd9cef19..b63d08b90ff5 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -1619,6 +1619,16 @@ collectLocalBranchTargets(ArrayRef<uint8_t> Bytes, const MCInstrAnalysis *MIA,
}
}
+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 @@ static void disassembleObject(const Target *TheTarget, const ObjectFile *Obj,
}
}
- 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::printSectionHeaders(const ObjectFile *Obj) {
}
void objdump::printSectionContents(const ObjectFile *Obj) {
+ const MachOObjectFile *MachO = dyn_cast<const MachOObjectFile>(Obj);
+
for (const SectionRef &Section : ToolSectionFilter(*Obj)) {
StringRef Name = unwrapOrError(Section.getName(), Obj->getFileName());
uint64_t BaseAddr = Section.getAddress();
@@ -2395,7 +2402,11 @@ void objdump::printSectionContents(const ObjectFile *Obj) {
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("<skipping contents of bss section at [%04" PRIx64
", %04" PRIx64 ")>\n",
@@ -2553,11 +2564,9 @@ void objdump::printSymbol(const ObjectFile *O, const SymbolRef &Symbol,
} 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;
}
More information about the llvm-commits
mailing list