Skip to content

Commit 9a3d581

Browse files
committed
[lld][ICF] Prevent merging two sections when they point to non-globals
1 parent 8389d6f commit 9a3d581

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

lld/ELF/ICF.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,18 @@ bool ICF<ELFT>::variableEq(const InputSection *secA, Relocs<RelTy> ra,
375375
auto *da = cast<Defined>(&sa);
376376
auto *db = cast<Defined>(&sb);
377377

378+
// Merging sections here also means that we would mark corresponding
379+
// relocation target symbols as equivalent, done later in ICF during section
380+
// folding. To preserve correctness for such symbol equivalence (see
381+
// GH#129122 for details), we also have to disable section merging here:
382+
// 1. We don't merge local symbols into global symbols, or vice-versa. There
383+
// are post-icf passes that assert on this behavior.
384+
// 2. We also don't merge two local symbols together. There are post-icf
385+
// passes that expect to see no duplicates when iterating over local
386+
// symbols.
387+
if (!da->isGlobal() || !db->isGlobal())
388+
return false;
389+
378390
// We already dealt with absolute and non-InputSection symbols in
379391
// constantEq, and for InputSections we have already checked everything
380392
// except the equivalence class.

0 commit comments

Comments
 (0)