diff options
| author | Peter Collingbourne <peter@pcc.me.uk> | 2017-11-20 18:51:29 +0000 |
|---|---|---|
| committer | Peter Collingbourne <peter@pcc.me.uk> | 2017-11-20 18:51:29 +0000 |
| commit | d01571353dfadbe5fb16f76b94ea591cc45f5b85 (patch) | |
| tree | 935dde53458055c5cba3b14e139a82b9e8890be4 | |
| parent | 8f54ae15a0d3f822ac834776665bf5676a7d24f7 (diff) | |
| download | llvm-d01571353dfadbe5fb16f76b94ea591cc45f5b85.zip llvm-d01571353dfadbe5fb16f76b94ea591cc45f5b85.tar.gz llvm-d01571353dfadbe5fb16f76b94ea591cc45f5b85.tar.bz2 | |
COFF: Stop requiring comdat sections to have an external leader to participate in ICF.
This requirement was added in r254578 to fix pr25686. However, it
appears to have originated from a misdiagnosis of the problem: link.exe
refused to merge the two sections because they are non-executable,
not because they have internal leaders. If I set up a similar scenario
with functions instead of globals I see that link.exe merges them.
Differential Revision: https://reviews.llvm.org/D40236
llvm-svn: 318682
| -rw-r--r-- | lld/COFF/ICF.cpp | 6 | ||||
| -rw-r--r-- | lld/test/COFF/icf-executable.s | 18 |
2 files changed, 20 insertions, 4 deletions
diff --git a/lld/COFF/ICF.cpp b/lld/COFF/ICF.cpp index 5253911..3626743 100644 --- a/lld/COFF/ICF.cpp +++ b/lld/COFF/ICF.cpp @@ -82,10 +82,8 @@ bool ICF::isEligible(SectionChunk *C) { if (!C->isCOMDAT() || !C->isLive() || Writable) return false; - // Code sections with external symbols are eligible. - bool Global = C->Sym && C->Sym->isExternal(); - bool Executable = C->getPermissions() & llvm::COFF::IMAGE_SCN_MEM_EXECUTE; - if (Global && Executable) + // Code sections are eligible. + if (C->getPermissions() & llvm::COFF::IMAGE_SCN_MEM_EXECUTE) return true; // .xdata unwind info sections are eligble. diff --git a/lld/test/COFF/icf-executable.s b/lld/test/COFF/icf-executable.s new file mode 100644 index 0000000..7f923d2 --- /dev/null +++ b/lld/test/COFF/icf-executable.s @@ -0,0 +1,18 @@ +# RUN: llvm-mc -triple=x86_64-windows-msvc %s -filetype=obj -o %t.obj +# RUN: lld-link -entry:main %t.obj -out:%t.exe -verbose 2>&1 | FileCheck %s + +# CHECK: Selected internal +# CHECK: Removed f2 + +.section .text,"xr",one_only,internal +internal: +.globl main +main: +call f2 +ret + +.section .text,"xr",one_only,f2 +.globl f2 +f2: +call main +ret |
