[MachO] Fix symbol merging during symtab parsing.
authorJonas Devlieghere <jonas@devlieghere.com>
Tue, 8 Oct 2019 00:13:59 +0000 (00:13 +0000)
committerJonas Devlieghere <jonas@devlieghere.com>
Tue, 8 Oct 2019 00:13:59 +0000 (00:13 +0000)
commit4bddca306a451f2577ec62dd73c30b5e91a8fb32
tree642da293793aff5e87a854b90e46c0b99252bc2c
parent2e2c93476282990ae6b4845578ced9bf51d43e43
[MachO] Fix symbol merging during symtab parsing.

The symtab parser in ObjectFileMachO has logic to coalesce debug (STAB)
and non-debug symbols, based on the address and the symbol name for
static (STSYM) and global symbols (GSYM) respectively. It makes the
assumption that the debug variant is always encountered first. Rather
than creating a second entry in the symbol table for the non-debug
symbol, the latter gets merged into the existing debug symbol.

This breaks when the linker emits the non-debug symbol first. We'd end
up with two entries in the symbol table, each containing part of the
information LLDB relies on. Indeed, commenting out the merging logic
breaks the test suite spectacularly.

This patch solves that problem by always parsing the debug symbols
first. This guarantees that the assumption for merging holds.

I'm not particularly happy with  adding a lambda, but after numerous
attempts this is the best solution I could come up with. The symtab
parsing logic is pretty complex in that it touches a lot of things. I've
experienced first hand that it's very easy to break things. I believe
this approach strikes a balance between fixing the issue while limiting
the risk of regressions.

Differential revision: https://reviews.llvm.org/D68536

llvm-svn: 373994
lldb/lit/ObjectFile/MachO/symtab.yaml [new file with mode: 0644]
lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp