Skip to content

[MachO] Fix symbol merging during symtab parsing #465

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Dec 13, 2019
Merged

[MachO] Fix symbol merging during symtab parsing #465

merged 7 commits into from
Dec 13, 2019

Conversation

JDevlieghere
Copy link

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.

This file really suffered from the Great Reformat. I'm adding a few
early returns to give the deeply nested code some more breathing room.
git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@373803 91177308-0d34-0410-b5e6-96231b3b80d8
(cherry picked from commit 582965dc3ea03188e87738d83cef2912da6545ea)
(cherry picked from commit 5e0386a1400c009afe99e217e89e085f742bafc4)

apple-llvm-split-commit: cfd351c8d978959b5263f6fdb467569f39e5c0d4
apple-llvm-split-dir: lldb/
(cherry picked from commit af2e99e)
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

git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@373994 91177308-0d34-0410-b5e6-96231b3b80d8
(cherry picked from commit a8446221d1f565cbd2696ab71d42b4bf29b994e1)
(cherry picked from commit 569ae2622aeca76cc79285686b742ba89055944d)

apple-llvm-split-commit: c7ca5246795eb58c3cbd272368c667510efbbe20
apple-llvm-split-dir: lldb/
(cherry picked from commit e341a70)
@JDevlieghere
Copy link
Author

@swift-ci please test

1 similar comment
@JDevlieghere
Copy link
Author

@swift-ci please test

@shahmishal
Copy link
Member

@swift-ci please test macOS

@shahmishal
Copy link
Member

@swift-ci test Linux

@fredriss fredriss merged commit 198fa1e into swiftlang:swift/swift-5.1-branch Dec 13, 2019
@JDevlieghere JDevlieghere deleted the rdar57884467 branch December 13, 2019 04:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants