Skip to content
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

[LLDB][ELF] LLDB gets confused if there are multiple .text sections in a binary #88001

Closed
al45tair opened this issue Apr 8, 2024 · 2 comments · Fixed by #90099
Closed

[LLDB][ELF] LLDB gets confused if there are multiple .text sections in a binary #88001

al45tair opened this issue Apr 8, 2024 · 2 comments · Fixed by #90099
Labels

Comments

@al45tair
Copy link
Contributor

al45tair commented Apr 8, 2024

I had a Swift PR open (swiftlang/swift#72061) that changes how Swift handles the metadata sections (in particular), but as a consequence causes the compiler to set SHF_GNU_RETAIN on other sections as well. At time of writing, all of the tests are passing except some LLDB API tests, which was very puzzling.

The problem appears to be that, because of the behaviour of older versions of ld.gold (prior to binutils 2.36), libswiftCore.so ends up with two .text sections, and then when LLDB tries to print a Swift object, it attempts to call Swift._DebuggerSupport.stringForPrintObject, but gets mixed up and adds the offset it found for that function to the wrong .text section, jumps into the end of an entirely unrelated function and (eventually) crashes after triggering an assertion failure.

The bug here is that LLDB appears to get confused about the presence of two .text sections, which leads to symbol lookups going awry.

I've attached a small reproducer, which doesn't need Swift (or anything to do with Swift).

lldb-two-text-sections.tar.gz

(We're tracking this internally as rdar://124467787.)

@llvmbot
Copy link
Collaborator

llvmbot commented Apr 8, 2024

@llvm/issue-subscribers-lldb

Author: Alastair Houghton (al45tair)

I had a Swift PR open (https://github.com/swiftlang/swift/pull/72061) that changes how Swift handles the metadata sections (in particular), but as a consequence causes the compiler to set `SHF_GNU_RETAIN` on other sections as well. At time of writing, all of the tests are passing *except* some LLDB API tests, which was very puzzling.

The problem appears to be that, because of the behaviour of older versions of ld.gold (prior to binutils 2.36), libswiftCore.so ends up with two .text sections, and then when LLDB tries to print a Swift object, it attempts to call Swift._DebuggerSupport.stringForPrintObject, but gets mixed up and adds the offset it found for that function to the wrong .text section, jumps into the end of an entirely unrelated function and (eventually) crashes after triggering an assertion failure.

The bug here is that LLDB appears to get confused about the presence of two .text sections, which leads to symbol lookups going awry.

I've attached a small reproducer, which doesn't need Swift (or anything to do with Swift).

lldb-two-text-sections.tar.gz

(We're tracking this internally as rdar://124467787.)

@al45tair
Copy link
Contributor Author

I found another fun symptom of the same problem. If you set a breakpoint on main and then let the child program run, if you're afflicted with the two .text sections problem, it's possible the program will stop at __start unexpectedly. (If you check the breakpoints that were created, there will be one pointing at __start!)

This happens because main ends up at the start of one of the .text sections, while __start is at the start of the other. LLDB then gets confused and installs an additional breakpoint because it finds both main in the proper place (via the debug information) and main but with the wrong section (via the symbol table).

JDevlieghere pushed a commit that referenced this issue May 1, 2024
Section unification cannot just use names, because it's valid for ELF
binaries to have multiple sections with the same name. We should check
other section properties too.

Fixes #88001.

rdar://124467787
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants