diff --git a/test/tools/llvm-objdump/X86/Inputs/hello.exe.stripped.macho-x86_64 b/test/tools/llvm-objdump/X86/Inputs/hello.exe.stripped.macho-x86_64 new file mode 100755 index 00000000000..9c52d168bef Binary files /dev/null and b/test/tools/llvm-objdump/X86/Inputs/hello.exe.stripped.macho-x86_64 differ diff --git a/test/tools/llvm-objdump/X86/macho-dis-symname.test b/test/tools/llvm-objdump/X86/macho-dis-symname.test index 39d16ecba6f..9e4f2e3c71f 100644 --- a/test/tools/llvm-objdump/X86/macho-dis-symname.test +++ b/test/tools/llvm-objdump/X86/macho-dis-symname.test @@ -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 diff --git a/test/tools/llvm-objdump/X86/macho-disassembly-stripped.test b/test/tools/llvm-objdump/X86/macho-disassembly-stripped.test new file mode 100644 index 00000000000..fab86f8b979 --- /dev/null +++ b/test/tools/llvm-objdump/X86/macho-disassembly-stripped.test @@ -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 diff --git a/tools/llvm-objdump/MachODump.cpp b/tools/llvm-objdump/MachODump.cpp index fe7cf0dd335..3f4185e6330 100644 --- a/tools/llvm-objdump/MachODump.cpp +++ b/tools/llvm-objdump/MachODump.cpp @@ -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.