[lld] r318682 - COFF: Stop requiring comdat sections to have an external leader to participate in ICF.
Peter Collingbourne via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 20 10:51:29 PST 2017
Author: pcc
Date: Mon Nov 20 10:51:29 2017
New Revision: 318682
URL: http://llvm.org/viewvc/llvm-project?rev=318682&view=rev
Log:
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
Added:
lld/trunk/test/COFF/icf-executable.s
Modified:
lld/trunk/COFF/ICF.cpp
Modified: lld/trunk/COFF/ICF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/ICF.cpp?rev=318682&r1=318681&r2=318682&view=diff
==============================================================================
--- lld/trunk/COFF/ICF.cpp (original)
+++ lld/trunk/COFF/ICF.cpp Mon Nov 20 10:51:29 2017
@@ -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.
Added: lld/trunk/test/COFF/icf-executable.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/icf-executable.s?rev=318682&view=auto
==============================================================================
--- lld/trunk/test/COFF/icf-executable.s (added)
+++ lld/trunk/test/COFF/icf-executable.s Mon Nov 20 10:51:29 2017
@@ -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
More information about the llvm-commits
mailing list