[lld] r323930 - [COFF] make /incremental control overwriting unchanged import libraries

Bob Haarman via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 31 15:44:00 PST 2018


Author: inglorion
Date: Wed Jan 31 15:44:00 2018
New Revision: 323930

URL: http://llvm.org/viewvc/llvm-project?rev=323930&view=rev
Log:
[COFF] make /incremental control overwriting unchanged import libraries

Summary:
r323164 made lld-link not overwrite import libraries when their
contents haven't changed. MSVC's link.exe does this only when
performing incremental linking. This change makes lld-link's import
library overwriting similarly dependent on whether or not incremental
linking is being performed. This is controlled by the /incremental or
/incremental:no options. In addition, /opt:icf, /opt:ref, and /order
turn off /incremental and issue a warning if /incremental was
specified on the command line.

Reviewers: rnk, ruiu, zturner

Reviewed By: ruiu

Subscribers: llvm-commits

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

Added:
    lld/trunk/test/COFF/incremental.test
Removed:
    lld/trunk/test/COFF/unchanged-importlib.test
Modified:
    lld/trunk/COFF/Config.h
    lld/trunk/COFF/Driver.cpp
    lld/trunk/COFF/Options.td

Modified: lld/trunk/COFF/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Config.h?rev=323930&r1=323929&r2=323930&view=diff
==============================================================================
--- lld/trunk/COFF/Config.h (original)
+++ lld/trunk/COFF/Config.h Wed Jan 31 15:44:00 2018
@@ -179,6 +179,7 @@ struct Configuration {
   bool AppContainer = false;
   bool MinGW = false;
   bool WarnLocallyDefinedImported = true;
+  bool Incremental = true;
 };
 
 extern Configuration *Config;

Modified: lld/trunk/COFF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.cpp?rev=323930&r1=323929&r2=323930&view=diff
==============================================================================
--- lld/trunk/COFF/Driver.cpp (original)
+++ lld/trunk/COFF/Driver.cpp Wed Jan 31 15:44:00 2018
@@ -547,6 +547,12 @@ static void createImportLibrary(bool AsL
   std::string LibName = getImportName(AsLib);
   std::string Path = getImplibPath();
 
+  if (!Config->Incremental) {
+    HandleError(writeImportLibrary(LibName, Path, Exports, Config->Machine,
+                                   false, Config->MinGW));
+    return;
+  }
+
   // If the import library already exists, replace it only if the contents
   // have changed.
   ErrorOr<std::unique_ptr<MemoryBuffer>> OldBuf = MemoryBuffer::getFile(Path);
@@ -907,6 +913,7 @@ void LinkerDriver::link(ArrayRef<const c
   // Handle /debug
   if (Args.hasArg(OPT_debug, OPT_debug_dwarf, OPT_debug_ghash)) {
     Config->Debug = true;
+    Config->Incremental = true;
     if (auto *Arg = Args.getLastArg(OPT_debugtype))
       Config->DebugTypes = parseDebugType(Arg->getValue());
     else
@@ -1113,6 +1120,9 @@ void LinkerDriver::link(ArrayRef<const c
   Config->AllowBind = Args.hasFlag(OPT_allowbind, OPT_allowbind_no, true);
   Config->AllowIsolation =
       Args.hasFlag(OPT_allowisolation, OPT_allowisolation_no, true);
+  Config->Incremental =
+      Args.hasFlag(OPT_incremental, OPT_incremental_no,
+                   !Config->DoGC && !Config->DoICF && !Args.hasArg(OPT_order));
   Config->NxCompat = Args.hasFlag(OPT_nxcompat, OPT_nxcompat_no, true);
   Config->TerminalServerAware = Args.hasFlag(OPT_tsaware, OPT_tsaware_no, true);
   Config->DebugDwarf = Args.hasArg(OPT_debug_dwarf);
@@ -1120,6 +1130,23 @@ void LinkerDriver::link(ArrayRef<const c
 
   Config->MapFile = getMapFile(Args);
 
+  if (Config->Incremental && Config->DoGC) {
+    warn("ignoring '/INCREMENTAL' because REF is enabled; use '/OPT:NOREF' to "
+         "disable");
+    Config->Incremental = false;
+  }
+
+  if (Config->Incremental && Config->DoICF) {
+    warn("ignoring '/INCREMENTAL' because ICF is enabled; use '/OPT:NOICF' to "
+         "disable");
+    Config->Incremental = false;
+  }
+
+  if (Config->Incremental && Args.hasArg(OPT_order)) {
+    warn("ignoring '/INCREMENTAL' due to '/ORDER' specification");
+    Config->Incremental = false;
+  }
+
   if (errorCount())
     return;
 

Modified: lld/trunk/COFF/Options.td
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Options.td?rev=323930&r1=323929&r2=323930&view=diff
==============================================================================
--- lld/trunk/COFF/Options.td (original)
+++ lld/trunk/COFF/Options.td Wed Jan 31 15:44:00 2018
@@ -103,6 +103,9 @@ defm fixed : B<"fixed", "Disable base re
 defm highentropyva : B<"highentropyva",
                        "Enable 64-bit ASLR (default on 64-bit)",
                        "Disable 64-bit ASLR">;
+defm incremental : B<"incremental",
+                     "Keep original import library if contents are unchanged",
+                     "Replace import library file even if contents are unchanged">;
 defm largeaddressaware : B<"largeaddressaware",
                            "Enable large addresses (default on 64-bit)",
                            "Disable large addresses (default on 32-bit)">;
@@ -148,8 +151,6 @@ multiclass QB<string name> {
 
 def functionpadmin : F<"functionpadmin">;
 def ignoreidl : F<"ignoreidl">;
-def incremental : F<"incremental">;
-def no_incremental : F<"incremental:no">;
 def nologo : F<"nologo">;
 def throwingnew : F<"throwingnew">;
 def editandcontinue : F<"editandcontinue">;

Added: lld/trunk/test/COFF/incremental.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/incremental.test?rev=323930&view=auto
==============================================================================
--- lld/trunk/test/COFF/incremental.test (added)
+++ lld/trunk/test/COFF/incremental.test Wed Jan 31 15:44:00 2018
@@ -0,0 +1,66 @@
+# RUN: yaml2obj < %p/Inputs/export.yaml > %t.obj
+# RUN: lld-link -out:%t.dll -dll %t.obj 2>&1 \
+# RUN:   | FileCheck -allow-empty -check-prefix=NOWARN %s
+# RUN: touch -t 198002011200.00 %t.lib
+# RUN: lld-link -out:%t.dll -dll %t.obj
+# RUN: ls -l %t.lib | FileCheck -check-prefix=NOKEEP %s
+
+# RUN: lld-link -out:%t.dll -dll -incremental %t.obj 2>&1 \
+# RUN:   | FileCheck -allow-empty -check-prefix=WARN-REF %s
+# RUN: touch -t 198002011200.00 %t.lib
+# RUN: lld-link -out:%t.dll -dll -incremental %t.obj
+# RUN: ls -l %t.lib | FileCheck -check-prefix=NOKEEP %s
+
+# RUN: lld-link -out:%t.dll -dll -debug %t.obj 2>&1 \
+# RUN:   | FileCheck -allow-empty -check-prefix=NOWARN %s
+# RUN: touch -t 198002011200.00 %t.lib
+# RUN: lld-link -out:%t.dll -dll -debug %t.obj
+# RUN: ls -l %t.lib | FileCheck -check-prefix=KEEP %s
+
+# RUN: lld-link -out:%t.dll -dll -debug -incremental:no %t.obj 2>&1 \
+# RUN:   | FileCheck -allow-empty -check-prefix=NOWARN %s
+# RUN: touch -t 198002011200.00 %t.lib
+# RUN: lld-link -out:%t.dll -dll -debug -incremental:no %t.obj
+# RUN: ls -l %t.lib | FileCheck -check-prefix=NOKEEP %s
+
+# RUN: lld-link -out:%t.dll -dll -opt:icf %t.obj 2>&1 \
+# RUN:   | FileCheck -allow-empty -check-prefix=NOWARN %s
+# RUN: touch -t 198002011200.00 %t.lib
+# RUN: lld-link -out:%t.dll -dll -opt:icf %t.obj
+# RUN: ls -l %t.lib | FileCheck -check-prefix=NOKEEP %s
+
+# RUN: lld-link -out:%t.dll -dll -incremental -opt:noref,icf %t.obj 2>&1 \
+# RUN:   | FileCheck -check-prefix=WARN-ICF %s
+# RUN: touch -t 198002011200.00 %t.lib
+# RUN: lld-link -out:%t.dll -dll -incremental -opt:noref,icf %t.obj
+# RUN: ls -l %t.lib | FileCheck -check-prefix=NOKEEP %s
+
+# RUN: lld-link -out:%t.dll -dll -debug -opt:icf %t.obj 2>&1 \
+# RUN:   | FileCheck -allow-empty -check-prefix=NOWARN %s
+# RUN: touch -t 198002011200.00 %t.lib
+# RUN: lld-link -out:%t.dll -dll -debug -opt:icf %t.obj
+# RUN: ls -l %t.lib | FileCheck -check-prefix=NOKEEP %s
+
+# RUN: lld-link -out:%t.dll -dll -opt:ref %t.obj 2>&1 \
+# RUN:   | FileCheck -allow-empty -check-prefix=NOWARN %s
+# RUN: touch -t 198002011200.00 %t.lib
+# RUN: lld-link -out:%t.dll -dll -opt:ref %t.obj
+# RUN: ls -l %t.lib | FileCheck -check-prefix=NOKEEP %s
+
+# RUN: lld-link -out:%t.dll -dll -incremental -opt:ref %t.obj 2>&1 \
+# RUN:   | FileCheck -check-prefix=WARN-REF %s
+# RUN: touch -t 198002011200.00 %t.lib
+# RUN: lld-link -out:%t.dll -dll -incremental -opt:ref %t.obj
+# RUN: ls -l %t.lib | FileCheck -check-prefix=NOKEEP %s
+
+# RUN: lld-link -out:%t.dll -dll -debug -opt:ref %t.obj 2>&1 \
+# RUN:   | FileCheck -allow-empty -check-prefix=NOWARN %s
+# RUN: touch -t 198002011200.00 %t.lib
+# RUN: lld-link -out:%t.dll -dll -debug -opt:ref %t.obj
+# RUN: ls -l %t.lib | FileCheck -check-prefix=NOKEEP %s
+
+# NOWARN-NOT: ignoring '/INCREMENTAL'
+# WARN-ICF: ignoring '/INCREMENTAL' because ICF is enabled; use '/OPT:NOICF' to disable
+# WARN-REF: ignoring '/INCREMENTAL' because REF is enabled; use '/OPT:NOREF' to disable
+# KEEP: {{Feb 1 1980|1980-02-01}}
+# NOKEEP-NOT: {{Feb 1 1980|1980-02-01}}

Removed: lld/trunk/test/COFF/unchanged-importlib.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/unchanged-importlib.test?rev=323929&view=auto
==============================================================================
--- lld/trunk/test/COFF/unchanged-importlib.test (original)
+++ lld/trunk/test/COFF/unchanged-importlib.test (removed)
@@ -1,7 +0,0 @@
-# RUN: yaml2obj < %p/Inputs/export.yaml > %t.obj
-# RUN: lld-link -out:%t.dll -dll %t.obj
-# RUN: touch -t 198002011200.00 %t.lib
-# RUN: lld-link -out:%t.dll -dll %t.obj
-# RUN: ls -l %t.lib | FileCheck --check-prefix=CHECK %s
-
-# CHECK: {{Feb 1 1980|1980-02-01}}




More information about the llvm-commits mailing list