<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/88001>88001</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[LLDB][ELF] LLDB gets confused if there are multiple .text sections in a binary
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
al45tair
</td>
</tr>
</table>
<pre>
I had a Swift PR open (https://github.com/apple/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](https://github.com/llvm/llvm-project/files/14906932/lldb-two-text-sections.tar.gz)
(We're tracking this internally as rdar://124467787.)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUlU-P2zgPxj-NciHGcJR_9iGHTNO87wBFt-h0scdCtmhbrSxpJWrc9NMvqMx0WixQYC8JYNMkn4c_USolMzrEo9jdi915pTJNPh6V3e5ImbjqvL4eH2BSGhQ8LmYg-PARfEAHQjYTUUhicxLyIuRlNDTlrur9LORFhWBRyEvib4S8hGytkJeDrPdrIVugSRH0k3IjJpj88px8Uk5bTEATwoyktCIFCXsy3iUuaRwEFcn02aooZCvkG-gygUqgoPcu4d8ZXY_Qq5yeE_V-DsZiBPKQkEDs68f_Xz7_7_2fnz--_XR6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