[lld] [lld][ICF] Prevent merging two sections when they point to non-globals (PR #136641)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 25 07:33:33 PDT 2025


MaskRay wrote:

(I'm currently traveling with limited computer access, so I haven't been able to fully analyze the details-my apologies.)

The ICF ground is relatively thin, and we rely on a few heuristics to manage the safe portion. Issue #129122 exposed a flaw in these heuristics, and #134342 (the third approach to #129122) provided an accepted fix.
I accepted it because it looked reasonable and did not dabble with specific relocation types.

This PR resembles the second proposed patch to #129122, adding checks for relocation types to prevent folding.
The check may align with `llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCExpr.h:Specifier` (symbol location specifications).
However, as I noted in https://github.com/llvm/llvm-project/pull/131630#issuecomment-2739039788, I'm skeptical about adopting this nuanced linker code.

While the `MachineOutliner` transform is valid and relocations tied to specific symbol locations could theoretically be isolated-and the psABI doesn't prohibit this separation-in practice, we could restrict compiler transforms to simplify the linker's ICF code significantly.
As an occasional contributor to the RISC-V psABI, I note that it hasn't faced this ICF issue yet. If it did, I would advocate prohibiting such compiler-generated code to simplify the linker's ICF implementation.


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


More information about the llvm-commits mailing list