diff --git a/lld/COFF/ICF.cpp b/lld/COFF/ICF.cpp --- a/lld/COFF/ICF.cpp +++ b/lld/COFF/ICF.cpp @@ -76,9 +76,10 @@ // section is insignificant to the user program and the behaviour matches that // of the Visual C++ linker. bool ICF::isEligible(SectionChunk *c) { - // Non-comdat chunks, dead chunks, and writable chunks are not eligible. + // Non-comdat chunks, dead chunks, writable chunks and chunks in the + // address-significance table are not eligible. bool writable = c->getOutputCharacteristics() & llvm::COFF::IMAGE_SCN_MEM_WRITE; - if (!c->isCOMDAT() || !c->live || writable) + if (!c->isCOMDAT() || !c->live || writable || c->keepUnique) return false; // Code sections are eligible. @@ -94,8 +95,8 @@ if (c->sym && c->sym->getName().startswith("??_7")) return true; - // Anything else not in an address-significance table is eligible. - return !c->keepUnique; + // Anything else is eligible. + return true; } // Split an equivalence class into smaller classes. diff --git a/lld/test/COFF/icf-safe.s b/lld/test/COFF/icf-safe.s --- a/lld/test/COFF/icf-safe.s +++ b/lld/test/COFF/icf-safe.s @@ -2,11 +2,13 @@ # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-win32 %s -o %t1.obj # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-win32 %S/Inputs/icf-safe.s -o %t2.obj # RUN: lld-link /dll /noentry /out:%t.dll /verbose /opt:noref,icf %t1.obj %t2.obj 2>&1 | FileCheck %s -# RUN: lld-link /dll /noentry /out:%t.dll /verbose /opt:noref,icf /export:g3 /export:g4 %t1.obj %t2.obj 2>&1 | FileCheck --check-prefix=EXPORT %s +# RUN: lld-link /dll /noentry /out:%t.dll /verbose /opt:noref,icf /export:g3 /export:g4 /export:f3 /export:f4 %t1.obj %t2.obj 2>&1 | FileCheck --check-prefix=EXPORT %s # CHECK-NOT: Selected # CHECK: Selected g3 # CHECK-NEXT: Removed g4 +# CHECK: Selected f3 +# CHECK-NEXT: Removed f4 # CHECK-NOT: Removed # CHECK-NOT: Selected @@ -32,6 +34,28 @@ g4: .byte 2 +.section .text,"xr",one_only,f1 +.globl f1 +f1: + nop + +.section .text,"xr",one_only,f2 +.globl f2 +f2: + nop + +.section .text,"xr",one_only,f3 +.globl f3 +f3: + nop + +.section .text,"xr",one_only,f4 +.globl f4 +f4: + nop + .addrsig .addrsig_sym g1 .addrsig_sym g2 +.addrsig_sym f1 +.addrsig_sym f2 \ No newline at end of file