[lld] [lld-macho] Fix invalid DWARF with --icf=safe_thunks (PR #111097)

Ellis Hoag via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 4 08:43:26 PDT 2024


================
@@ -1229,6 +1229,17 @@ void SymtabSection::emitStabs() {
       if (defined->isAbsolute())
         continue;
 
+      // Never generate a STABS entry for a symbol that has been ICF'ed using a
+      // thunk - just like we do for fully ICF'ed functions. Otherwise we end up
+      // generating invalid DWARF as dsymutil will think the entire function
+      // body is at that location, when in actuality only the thunk will be
+      // present. This will end up causing overlapping DWARF entries.
+      // TODO: Find an implementation that works in combination with
+      // `--keep-icf-stabs`.
+      if (defined->identicalCodeFoldingKind == Symbol::ICFFoldKind::Thunk) {
+        continue;
+      }
----------------
ellishg wrote:

```suggestion
      if (defined->identicalCodeFoldingKind == Symbol::ICFFoldKind::Thunk)
        continue;
```


https://github.com/llvm/llvm-project/pull/111097


More information about the llvm-commits mailing list