[PATCH] D101786: [llvm-objdump] Exclude __mh_execute_header symbol during MachO disassembly
Greg McGary via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon May 3 13:55:26 PDT 2021
gkm created this revision.
Herald added subscribers: rupprecht, kristof.beyls.
Herald added a reviewer: jhenderson.
Herald added a reviewer: MaskRay.
gkm requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
`__mh_execute_header` is a special symbol whose value has the VMA of the Mach header. It is attached to the first section in `__TEXT`, even though its address is outside `__TEXT`, and it does not refer to code.
It is normally harmless, but when the first section of `__TEXT` has no other symbols, `__mh_execute_header` is considered by the disassembler when determing function boundaries. Since `__mh_execute_header` refers to an address outside `__TEXT`, the boundary determination fails and disassembly quits.
Since `__TEXT,__text` normally has symbols, this bug is obscured. Experiments placing `__stubs` and `__stub_helper` first exposed the bug, since neither has symbols.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D101786
Files:
llvm/test/tools/llvm-objdump/MachO/Inputs/no-text-symbols.macho-x86_64
llvm/test/tools/llvm-objdump/MachO/no-text-symbols-disassembly.test
llvm/tools/llvm-objdump/llvm-objdump.cpp
Index: llvm/tools/llvm-objdump/llvm-objdump.cpp
===================================================================
--- llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -1076,10 +1076,14 @@
if (Obj->isELF() && getElfSymbolType(Obj, Symbol) == ELF::STT_SECTION)
continue;
- // Don't ask a Mach-O STAB symbol for its section unless you know that
- // STAB symbol's section field refers to a valid section index. Otherwise
- // the symbol may error trying to load a section that does not exist.
if (MachO) {
+ // __mh_execute_header is a special symbol that does not bind to
+ // code, and is irrelevant for disassembly.
+ if (NameOrErr->equals("__mh_execute_header"))
+ continue;
+ // Don't ask a Mach-O STAB symbol for its section unless you know that
+ // STAB symbol's section field refers to a valid section index. Otherwise
+ // the symbol may error trying to load a section that does not exist.
DataRefImpl SymDRI = Symbol.getRawDataRefImpl();
uint8_t NType = (MachO->is64Bit() ?
MachO->getSymbol64TableEntry(SymDRI).n_type:
Index: llvm/test/tools/llvm-objdump/MachO/no-text-symbols-disassembly.test
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-objdump/MachO/no-text-symbols-disassembly.test
@@ -0,0 +1,6 @@
+## Verify that we see dissassembler output even when there are no
+## symbols in __TEXT,__text.
+
+RUN: llvm-objdump -d %p/Inputs/no-text-symbols.macho-x86_64 | FileCheck %s
+
+CHECK: Disassembly of section __TEXT,__text:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101786.342539.patch
Type: text/x-patch
Size: 1640 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210503/13c06e39/attachment.bin>
More information about the llvm-commits
mailing list