1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 11:13:28 +01:00

Fix llvm-objdump when disassembling a stripped Mach-O binary with the -macho option.

It was printing out nothing in this case.

llvm-objdump tries to disassemble sections a symbol at a time.  In the case of a
fully stripped Mach-O executable the only symbol remaining in the (__TEXT,__text)
section is the special linker defined symbol __mh_execute_header . This
symbol is special in that while it is N_SECT symbol in the (__TEXT,__text)
its address is before the start of the (__TEXT,__text).  It’s address is the
start of the __TEXT segment which is where the mach header is statically
linked. So the code in DisassembleMachO() needs to deal with this case specially.

rdar://26778273

llvm-svn: 272837
This commit is contained in:
Kevin Enderby 2016-06-15 21:14:01 +00:00
parent f2459e81e7
commit 813c166168
4 changed files with 33 additions and 1 deletions

View File

@ -17,3 +17,9 @@
# CHECK-NOT: __start:
# CHECK-NOT: 0000000100000d22
# CHECK-NOT: _main:
# not RUN: llvm-objdump -m -d %p/Inputs/exeThread.macho-x86_64 -dis-symname _environ 2>&1 | FileCheck -check-prefix BAD-SYMAME-1 %s
BAD-SYMAME-1: -dis-symname: _environ not in the section
# not RUN: llvm-objdump -m -d %p/Inputs/exeThread.macho-x86_64 -dis-symname __mh_execute_header 2>&1 | FileCheck -check-prefix BAD-SYMAME-2 %s
BAD-SYMAME-2: -dis-symname: __mh_execute_header not in any section

View File

@ -0,0 +1,6 @@
// RUN: llvm-objdump -d -m -no-show-raw-insn -full-leading-addr -print-imm-hex %p/Inputs/hello.exe.stripped.macho-x86_64 | FileCheck %s
CHECK: (__TEXT,__text) section
CHECK: 0000000100000f30 pushq %rbp
CHECK: 0000000100000f31 movq %rsp, %rbp
CHECK: 0000000100000f34 subq $0x20, %rsp

View File

@ -6677,7 +6677,27 @@ static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF,
// Make sure the symbol is defined in this section.
bool containsSym = Sections[SectIdx].containsSymbol(Symbols[SymIdx]);
if (!containsSym)
if (!containsSym) {
if (!DisSymName.empty() && DisSymName == SymName) {
outs() << "-dis-symname: " << DisSymName << " not in the section\n";
return;
}
continue;
}
// The __mh_execute_header is special and we need to deal with that fact
// this symbol is before the start of the (__TEXT,__text) section and at the
// address of the start of the __TEXT segment. This is because this symbol
// is an N_SECT symbol in the (__TEXT,__text) but its address is before the
// start of the section in a standard MH_EXECUTE filetype.
if (!DisSymName.empty() && DisSymName == "__mh_execute_header") {
outs() << "-dis-symname: __mh_execute_header not in any section\n";
return;
}
// When this code is trying to disassemble a symbol at a time and in the case
// there is only the __mh_execute_header symbol left as in a stripped
// executable, we need to deal with this by ignoring this symbol so the whole
// section is disassembled and this symbol is then not displayed.
if (SymName == "__mh_execute_header")
continue;
// If we are only disassembling one symbol see if this is that symbol.