Skip to content

Commit 45f538e

Browse files
committed
[ELF] ICF: replace includeInDynsym with isExported
Similar to the change to MarkLive.cpp when isExported was introduced. includeInDynsym might return true even when isExported is false for statically linked executables.
1 parent 8af24ce commit 45f538e

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

lld/ELF/Driver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2413,7 +2413,7 @@ static void findKeepUniqueSections(Ctx &ctx, opt::InputArgList &args) {
24132413
// or DSOs, so we conservatively mark them as address-significant.
24142414
bool icfSafe = ctx.arg.icf == ICFLevel::Safe;
24152415
for (Symbol *sym : ctx.symtab->getSymbols())
2416-
if (sym->includeInDynsym(ctx))
2416+
if (sym->isExported)
24172417
markAddrsig(icfSafe, sym);
24182418

24192419
// Visit the address-significance table in each object file and mark each

lld/test/ELF/icf-safe.s

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
# REQUIRES: x86
2+
# RUN: llvm-mc -filetype=obj -triple=x86_64 %S/Inputs/shared.s -o %ta.o
3+
# RUN: ld.lld -shared -soname=ta %ta.o -o %ta.so
24

35
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o
46
# RUN: llvm-objcopy %t1.o %t1copy.o
57
# RUN: llvm-objcopy --localize-symbol=h1 %t1.o %t1changed.o
68
# RUN: ld.lld -r %t1.o -o %t1reloc.o
79
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %S/Inputs/icf-safe.s -o %t2.o
8-
# RUN: ld.lld %t1.o %t2.o -o %t2 --icf=safe --print-icf-sections | FileCheck %s
10+
# RUN: ld.lld %t1.o %t2.o -o %t2 --icf=safe --print-icf-sections --export-dynamic | FileCheck %s
911
# RUN: ld.lld %t1copy.o %t2.o -o %t2 --icf=safe --print-icf-sections | FileCheck %s
1012
# RUN: ld.lld %t1.o %t2.o -o %t3 --icf=safe --print-icf-sections -shared | FileCheck --check-prefix=EXPORT %s
11-
# RUN: ld.lld %t1.o %t2.o -o %t3 --icf=safe --print-icf-sections --export-dynamic | FileCheck --check-prefix=EXPORT %s
13+
## Exported symbols are suppressed for ICF when dynamic linking is enabled.
14+
# RUN: ld.lld %t1.o %t2.o %ta.so -o %t3 --icf=safe --print-icf-sections --export-dynamic | FileCheck --check-prefix=EXPORT %s
1215
# RUN: ld.lld %t1.o %t2.o -o %t2 --icf=all --print-icf-sections | FileCheck --check-prefix=ALL %s
13-
# RUN: ld.lld %t1.o %t2.o -o %t2 --icf=all --print-icf-sections --export-dynamic | FileCheck --check-prefix=ALL-EXPORT %s
16+
# RUN: ld.lld %t1.o %t2.o %ta.so -o %t2 --icf=all --print-icf-sections --export-dynamic | FileCheck --check-prefix=ALL-EXPORT %s
1417
# RUN: ld.lld %t1changed.o -o %t4 --icf=safe 2>&1 | FileCheck --check-prefix=SH_LINK_0 %s
1518
# RUN: ld.lld %t1reloc.o -o %t4 --icf=safe 2>&1 | FileCheck --check-prefix=SH_LINK_0 %s
1619

0 commit comments

Comments
 (0)