[lld-macho] Emit local symbols in symtab; record metadata in LC_DYSYMTAB
authorJez Ng <jezng@fb.com>
Tue, 1 Dec 2020 22:45:09 +0000 (14:45 -0800)
committerJez Ng <jezng@fb.com>
Tue, 1 Dec 2020 23:05:20 +0000 (15:05 -0800)
commit51629abce0e2f9d1376eb0b5070532a2bbec6766
treeaa3d1f46edeb475eae49ed1726e6c2a7606b00ed
parent3fcb0eeb152beb4320c7632bcfa2b1e7c2e5ca00
[lld-macho] Emit local symbols in symtab; record metadata in LC_DYSYMTAB

Symbols of the same type must be laid out contiguously: following ld64's
lead, we choose to emit all local symbols first, then external symbols,
and finally undefined symbols. For each symbol type, the LC_DYSYMTAB
load command will record the range (start index and total number) of
those symbols in the symbol table.

This work was motivated by the fact that LLDB won't search for debug
info if LC_DYSYMTAB says there are no local symbols (since STABS symbols
are all local symbols). With this change, LLDB is now able to display
the source lines at a given breakpoint when debugging our binaries.

Some tests had to be updated due to local symbol names now appearing in
`llvm-objdump`'s output.

Reviewed By: #lld-macho, smeenai, clayborg

Differential Revision: https://reviews.llvm.org/D89285
lld/MachO/SyntheticSections.cpp
lld/MachO/SyntheticSections.h
lld/MachO/Writer.cpp
lld/test/MachO/stabs.s
lld/test/MachO/subsections-symbol-relocs.s
lld/test/MachO/symtab.s
lld/test/MachO/tlv.s