Author: Fangrui Song Date: 2025-02-17T16:14:33-08:00 New Revision: a2b502050302a4cf8a9c4e623331810eed51bb81
URL: https://github.com/llvm/llvm-project/commit/a2b502050302a4cf8a9c4e623331810eed51bb81 DIFF: https://github.com/llvm/llvm-project/commit/a2b502050302a4cf8a9c4e623331810eed51bb81.diff LOG: [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. (cherry picked from commit 45f538ecba1a51768002a5bc0c194b5af4cd9c27) Added: Modified: lld/ELF/Driver.cpp lld/test/ELF/icf-safe.s Removed: ################################################################################ diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index 2d8a5ade2fece..6121a4254453c 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -2434,7 +2434,7 @@ static void findKeepUniqueSections(Ctx &ctx, opt::InputArgList &args) { // or DSOs, so we conservatively mark them as address-significant. bool icfSafe = ctx.arg.icf == ICFLevel::Safe; for (Symbol *sym : ctx.symtab->getSymbols()) - if (sym->includeInDynsym(ctx)) + if (sym->isExported) markAddrsig(icfSafe, sym); // Visit the address-significance table in each object file and mark each diff --git a/lld/test/ELF/icf-safe.s b/lld/test/ELF/icf-safe.s index 96776feccbc67..5381532609938 100644 --- a/lld/test/ELF/icf-safe.s +++ b/lld/test/ELF/icf-safe.s @@ -1,16 +1,19 @@ # REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64 %S/Inputs/shared.s -o %ta.o +# RUN: ld.lld -shared -soname=ta %ta.o -o %ta.so # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o # RUN: llvm-objcopy %t1.o %t1copy.o # RUN: llvm-objcopy --localize-symbol=h1 %t1.o %t1changed.o # RUN: ld.lld -r %t1.o -o %t1reloc.o # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %S/Inputs/icf-safe.s -o %t2.o -# RUN: ld.lld %t1.o %t2.o -o %t2 --icf=safe --print-icf-sections | FileCheck %s +# RUN: ld.lld %t1.o %t2.o -o %t2 --icf=safe --print-icf-sections --export-dynamic | FileCheck %s # RUN: ld.lld %t1copy.o %t2.o -o %t2 --icf=safe --print-icf-sections | FileCheck %s # RUN: ld.lld %t1.o %t2.o -o %t3 --icf=safe --print-icf-sections -shared | FileCheck --check-prefix=EXPORT %s -# RUN: ld.lld %t1.o %t2.o -o %t3 --icf=safe --print-icf-sections --export-dynamic | FileCheck --check-prefix=EXPORT %s +## Exported symbols are suppressed for ICF when dynamic linking is enabled. +# RUN: ld.lld %t1.o %t2.o %ta.so -o %t3 --icf=safe --print-icf-sections --export-dynamic | FileCheck --check-prefix=EXPORT %s # RUN: ld.lld %t1.o %t2.o -o %t2 --icf=all --print-icf-sections | FileCheck --check-prefix=ALL %s -# RUN: ld.lld %t1.o %t2.o -o %t2 --icf=all --print-icf-sections --export-dynamic | FileCheck --check-prefix=ALL-EXPORT %s +# RUN: ld.lld %t1.o %t2.o %ta.so -o %t2 --icf=all --print-icf-sections --export-dynamic | FileCheck --check-prefix=ALL-EXPORT %s # RUN: ld.lld %t1changed.o -o %t4 --icf=safe 2>&1 | FileCheck --check-prefix=SH_LINK_0 %s # RUN: ld.lld %t1reloc.o -o %t4 --icf=safe 2>&1 | FileCheck --check-prefix=SH_LINK_0 %s _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits