diff options
author | Greg McGary <gkm@fb.com> | 2021-05-02 19:08:02 -0700 |
---|---|---|
committer | Greg McGary <gkm@fb.com> | 2021-05-12 06:39:14 -0700 |
commit | 5a439015393e616b2faed9a9fbb1d7036b28e786 (patch) | |
tree | 4c76c65e8306a2b2cfe0ab53b834a6890b0598fe /llvm/tools/llvm-objdump/llvm-objdump.cpp | |
parent | 46adccc5cc1095f57b65fb2a17a4a023ccc77eb9 (diff) | |
download | llvm-5a439015393e616b2faed9a9fbb1d7036b28e786.zip llvm-5a439015393e616b2faed9a9fbb1d7036b28e786.tar.gz llvm-5a439015393e616b2faed9a9fbb1d7036b28e786.tar.bz2 |
[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
Diffstat (limited to 'llvm/tools/llvm-objdump/llvm-objdump.cpp')
-rw-r--r-- | llvm/tools/llvm-objdump/llvm-objdump.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp index c13ccfd..3689dd4 100644 --- a/llvm/tools/llvm-objdump/llvm-objdump.cpp +++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -1076,10 +1076,15 @@ static void disassembleObject(const Target *TheTarget, const ObjectFile *Obj, 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|dylib|dylinker|bundle|preload|object)_header are special + // symbols that support MachO header introspection. They do not bind to + // code locations and are irrelevant for disassembly. + if (NameOrErr->startswith("__mh_") && NameOrErr->endswith("_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: |