[lld] r327563 - [COFF] Enable per-function and data sections in LTO

Reid Kleckner via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 14 13:25:42 PDT 2018


Author: rnk
Date: Wed Mar 14 13:25:41 2018
New Revision: 327563

URL: http://llvm.org/viewvc/llvm-project?rev=327563&view=rev
Log:
[COFF] Enable per-function and data sections in LTO

Summary: This allows post-LTO symbol reordering and ICF.

Reviewers: inglorion

Subscribers: mehdi_amini, llvm-commits

Differential Revision: https://reviews.llvm.org/D44492

Added:
    lld/trunk/test/COFF/lto-icf.ll
Modified:
    lld/trunk/COFF/LTO.cpp

Modified: lld/trunk/COFF/LTO.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/LTO.cpp?rev=327563&r1=327562&r2=327563&view=diff
==============================================================================
--- lld/trunk/COFF/LTO.cpp (original)
+++ lld/trunk/COFF/LTO.cpp Wed Mar 14 13:25:41 2018
@@ -64,6 +64,12 @@ static void saveBuffer(StringRef Buffer,
 static std::unique_ptr<lto::LTO> createLTO() {
   lto::Config Conf;
   Conf.Options = InitTargetOptionsFromCodeGenFlags();
+
+  // Always emit a section per function/datum with LTO. LLVM LTO should get most
+  // of the benefit of linker GC, but there are still opportunities for ICF.
+  Conf.Options.FunctionSections = true;
+  Conf.Options.DataSections = true;
+
   // Use static reloc model on 32-bit x86 because it usually results in more
   // compact code, and because there are also known code generation bugs when
   // using the PIC model (see PR34306).

Added: lld/trunk/test/COFF/lto-icf.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/lto-icf.ll?rev=327563&view=auto
==============================================================================
--- lld/trunk/test/COFF/lto-icf.ll (added)
+++ lld/trunk/test/COFF/lto-icf.ll Wed Mar 14 13:25:41 2018
@@ -0,0 +1,26 @@
+; Test that ICF works after LTO, i.e. both functions have the same address.
+; Previously, when we didn't enable function sections, ICF didn't work.
+
+; RUN: llvm-as %s -o %t.bc
+; RUN: lld-link -opt:icf -dll -noentry %t.bc -out:%t.dll
+; RUN: llvm-readobj -coff-exports %t.dll | FileCheck %s
+
+; CHECK: Export {
+; CHECK: Export {
+; CHECK:   RVA: 0x[[RVA:.*]]
+; CHECK: Export {
+; CHECK:   RVA: 0x[[RVA]]
+; CHECK-NOT: Export
+
+target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc19.12.25835"
+
+define dllexport i8* @icf_ptr() {
+entry:
+  ret i8* null
+}
+
+define dllexport i64 @icf_int() {
+entry:
+  ret i64 0
+}




More information about the llvm-commits mailing list