mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-13 20:32:21 +00:00
Add code to llvm-objdump so the -section option with -macho will disassemble sections
that have attributes indicating they contain instructions. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@228101 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
786f55c1fb
commit
1de0e80e97
9
test/tools/llvm-objdump/X86/macho-nontext-disasm.test
Normal file
9
test/tools/llvm-objdump/X86/macho-nontext-disasm.test
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
# RUN: llvm-mc < %s -triple x86_64-apple-darwin -filetype=obj | llvm-objdump -m -section __FOO,__bar -full-leading-addr -print-imm-hex -no-show-raw-insn - | FileCheck %s
|
||||||
|
|
||||||
|
.section __FOO, __bar
|
||||||
|
_foo:
|
||||||
|
nop
|
||||||
|
|
||||||
|
# CHECK: Contents of (__FOO,__bar) section
|
||||||
|
# CHECK: _foo:
|
||||||
|
# CHECK: 0000000000000000 nop
|
@ -616,7 +616,11 @@ static void DumpRawSectionContents(MachOObjectFile *O, const char *sect,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DumpSectionContents(MachOObjectFile *O, bool verbose) {
|
static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF,
|
||||||
|
StringRef DisSegName, StringRef DisSectName);
|
||||||
|
|
||||||
|
static void DumpSectionContents(StringRef Filename, MachOObjectFile *O,
|
||||||
|
bool verbose) {
|
||||||
SymbolAddressMap AddrMap;
|
SymbolAddressMap AddrMap;
|
||||||
if (verbose)
|
if (verbose)
|
||||||
CreateSymbolAddressMap(O, &AddrMap);
|
CreateSymbolAddressMap(O, &AddrMap);
|
||||||
@ -642,15 +646,16 @@ static void DumpSectionContents(MachOObjectFile *O, bool verbose) {
|
|||||||
(SectName == DumpSectName)) {
|
(SectName == DumpSectName)) {
|
||||||
outs() << "Contents of (" << SegName << "," << SectName
|
outs() << "Contents of (" << SegName << "," << SectName
|
||||||
<< ") section\n";
|
<< ") section\n";
|
||||||
uint32_t section_type;
|
uint32_t section_flags;
|
||||||
if (O->is64Bit()) {
|
if (O->is64Bit()) {
|
||||||
const MachO::section_64 Sec = O->getSection64(Ref);
|
const MachO::section_64 Sec = O->getSection64(Ref);
|
||||||
section_type = Sec.flags & MachO::SECTION_TYPE;
|
section_flags = Sec.flags;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
const MachO::section Sec = O->getSection(Ref);
|
const MachO::section Sec = O->getSection(Ref);
|
||||||
section_type = Sec.flags & MachO::SECTION_TYPE;
|
section_flags = Sec.flags;
|
||||||
}
|
}
|
||||||
|
uint32_t section_type = section_flags & MachO::SECTION_TYPE;
|
||||||
|
|
||||||
StringRef BytesStr;
|
StringRef BytesStr;
|
||||||
Section.getContents(BytesStr);
|
Section.getContents(BytesStr);
|
||||||
@ -659,6 +664,11 @@ static void DumpSectionContents(MachOObjectFile *O, bool verbose) {
|
|||||||
uint64_t sect_addr = Section.getAddress();
|
uint64_t sect_addr = Section.getAddress();
|
||||||
|
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
|
if ((section_flags & MachO::S_ATTR_PURE_INSTRUCTIONS) ||
|
||||||
|
(section_flags & MachO::S_ATTR_SOME_INSTRUCTIONS)) {
|
||||||
|
DisassembleMachO(Filename, O, SegName, SectName);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
switch (section_type) {
|
switch (section_type) {
|
||||||
case MachO::S_REGULAR:
|
case MachO::S_REGULAR:
|
||||||
DumpRawSectionContents(O, sect, sect_size, sect_addr);
|
DumpRawSectionContents(O, sect, sect_size, sect_addr);
|
||||||
@ -722,8 +732,6 @@ static bool checkMachOAndArchFlags(ObjectFile *O, StringRef Filename) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF);
|
|
||||||
|
|
||||||
// ProcessMachO() is passed a single opened Mach-O file, which may be an
|
// ProcessMachO() is passed a single opened Mach-O file, which may be an
|
||||||
// archive member and or in a slice of a universal file. It prints the
|
// archive member and or in a slice of a universal file. It prints the
|
||||||
// the file name and header info and then processes it according to the
|
// the file name and header info and then processes it according to the
|
||||||
@ -746,7 +754,7 @@ static void ProcessMachO(StringRef Filename, MachOObjectFile *MachOOF,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (Disassemble)
|
if (Disassemble)
|
||||||
DisassembleMachO(Filename, MachOOF);
|
DisassembleMachO(Filename, MachOOF, "__TEXT", "__text");
|
||||||
if (IndirectSymbols)
|
if (IndirectSymbols)
|
||||||
PrintIndirectSymbols(MachOOF, true);
|
PrintIndirectSymbols(MachOOF, true);
|
||||||
if (DataInCode)
|
if (DataInCode)
|
||||||
@ -760,7 +768,7 @@ static void ProcessMachO(StringRef Filename, MachOObjectFile *MachOOF,
|
|||||||
if (SectionContents)
|
if (SectionContents)
|
||||||
PrintSectionContents(MachOOF);
|
PrintSectionContents(MachOOF);
|
||||||
if (DumpSections.size() != 0)
|
if (DumpSections.size() != 0)
|
||||||
DumpSectionContents(MachOOF, true);
|
DumpSectionContents(Filename, MachOOF, true);
|
||||||
if (SymbolTable)
|
if (SymbolTable)
|
||||||
PrintSymbolTable(MachOOF);
|
PrintSymbolTable(MachOOF);
|
||||||
if (UnwindInfo)
|
if (UnwindInfo)
|
||||||
@ -2547,7 +2555,8 @@ static void emitComments(raw_svector_ostream &CommentStream,
|
|||||||
CommentStream.resync();
|
CommentStream.resync();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF) {
|
static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF,
|
||||||
|
StringRef DisSegName, StringRef DisSectName) {
|
||||||
const char *McpuDefault = nullptr;
|
const char *McpuDefault = nullptr;
|
||||||
const Target *ThumbTarget = nullptr;
|
const Target *ThumbTarget = nullptr;
|
||||||
const Target *TheTarget = GetTarget(MachOOF, &McpuDefault, &ThumbTarget);
|
const Target *TheTarget = GetTarget(MachOOF, &McpuDefault, &ThumbTarget);
|
||||||
@ -2715,28 +2724,18 @@ static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF) {
|
|||||||
diContext.reset(DIContext::getDWARFContext(*DbgObj));
|
diContext.reset(DIContext::getDWARFContext(*DbgObj));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: For now this only disassembles the (__TEXT,__text) section (see the
|
if (DumpSections.size() == 0)
|
||||||
// checks in the code below at the top of this loop). It should allow a
|
outs() << "(" << DisSegName << "," << DisSectName << ") section\n";
|
||||||
// darwin otool(1) like -s option to disassemble any named segment & section
|
|
||||||
// that is marked as containing instructions with the attributes
|
|
||||||
// S_ATTR_PURE_INSTRUCTIONS or S_ATTR_SOME_INSTRUCTIONS in the flags field of
|
|
||||||
// the section structure.
|
|
||||||
outs() << "(__TEXT,__text) section\n";
|
|
||||||
|
|
||||||
for (unsigned SectIdx = 0; SectIdx != Sections.size(); SectIdx++) {
|
for (unsigned SectIdx = 0; SectIdx != Sections.size(); SectIdx++) {
|
||||||
|
|
||||||
bool SectIsText = Sections[SectIdx].isText();
|
|
||||||
if (SectIsText == false)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
StringRef SectName;
|
StringRef SectName;
|
||||||
if (Sections[SectIdx].getName(SectName) || SectName != "__text")
|
if (Sections[SectIdx].getName(SectName) || SectName != DisSectName)
|
||||||
continue; // Skip non-text sections
|
continue;
|
||||||
|
|
||||||
DataRefImpl DR = Sections[SectIdx].getRawDataRefImpl();
|
DataRefImpl DR = Sections[SectIdx].getRawDataRefImpl();
|
||||||
|
|
||||||
StringRef SegmentName = MachOOF->getSectionFinalSegmentName(DR);
|
StringRef SegmentName = MachOOF->getSectionFinalSegmentName(DR);
|
||||||
if (SegmentName != "__TEXT")
|
if (SegmentName != DisSegName)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
StringRef BytesStr;
|
StringRef BytesStr;
|
||||||
|
Loading…
Reference in New Issue
Block a user