[llvm-objdump] Exclude __mh_*_header symbols during MachO disassembly
authorGreg McGary <gkm@fb.com>
Mon, 3 May 2021 02:08:02 +0000 (19:08 -0700)
committerGreg McGary <gkm@fb.com>
Wed, 12 May 2021 13:39:14 +0000 (06:39 -0700)
commit5a439015393e616b2faed9a9fbb1d7036b28e786
tree4c76c65e8306a2b2cfe0ab53b834a6890b0598fe
parent46adccc5cc1095f57b65fb2a17a4a023ccc77eb9
[llvm-objdump] Exclude __mh_*_header symbols during MachO disassembly

`__mh_(execute|dylib|dylinker|bundle|preload|object)_header` are special symbols whose values hold the VMA of the Mach header to support introspection. They are attached to the first section in `__TEXT`, even though their addresses are outside `__TEXT`, and they do not refer to code.

It is normally harmless, but when the first section of `__TEXT` has no other symbols, `__mh_*_header` is considered by the disassembler when determing function boundaries. Since `__mh_*_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.

Differential Revision: https://reviews.llvm.org/D101786
llvm/test/tools/llvm-objdump/MachO/no-text-symbols-disassembly.test [new file with mode: 0644]
llvm/tools/llvm-objdump/llvm-objdump.cpp