[lld] r359829 - lld-link: Add /force:multipleres extension to make dupe resource diag non-fatal

Nico Weber via llvm-commits llvm-commits at lists.llvm.org
Thu May 2 14:21:55 PDT 2019


Author: nico
Date: Thu May  2 14:21:55 2019
New Revision: 359829

URL: http://llvm.org/viewvc/llvm-project?rev=359829&view=rev
Log:
lld-link: Add /force:multipleres extension to make dupe resource diag non-fatal

As a side benefit, lld-link now reports more than one duplicate resource
entry before exiting with an error even if the new flag is not passed.

Added:
    lld/trunk/test/COFF/Inputs/id.res   (with props)
    lld/trunk/test/COFF/force-multipleres.test
Modified:
    lld/trunk/COFF/Config.h
    lld/trunk/COFF/Driver.cpp
    lld/trunk/COFF/DriverUtils.cpp
    lld/trunk/COFF/Options.td
    lld/trunk/docs/ReleaseNotes.rst

Modified: lld/trunk/COFF/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Config.h?rev=359829&r1=359828&r2=359829&view=diff
==============================================================================
--- lld/trunk/COFF/Config.h (original)
+++ lld/trunk/COFF/Config.h Thu May  2 14:21:55 2019
@@ -97,6 +97,7 @@ struct Configuration {
   bool TailMerge;
   bool Relocatable = true;
   bool ForceMultiple = false;
+  bool ForceMultipleRes = false;
   bool ForceUnresolved = false;
   bool Debug = false;
   bool DebugDwarf = false;

Modified: lld/trunk/COFF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.cpp?rev=359829&r1=359828&r2=359829&view=diff
==============================================================================
--- lld/trunk/COFF/Driver.cpp (original)
+++ lld/trunk/COFF/Driver.cpp Thu May  2 14:21:55 2019
@@ -1096,6 +1096,10 @@ void LinkerDriver::link(ArrayRef<const c
   if (Args.hasArg(OPT_force, OPT_force_multiple))
     Config->ForceMultiple = true;
 
+  // Handle /force or /force:multipleres
+  if (Args.hasArg(OPT_force, OPT_force_multipleres))
+    Config->ForceMultipleRes = true;
+
   // Handle /debug
   DebugKind Debug = parseDebugKind(Args);
   if (Debug == DebugKind::Full || Debug == DebugKind::Dwarf ||

Modified: lld/trunk/COFF/DriverUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/DriverUtils.cpp?rev=359829&r1=359828&r2=359829&view=diff
==============================================================================
--- lld/trunk/COFF/DriverUtils.cpp (original)
+++ lld/trunk/COFF/DriverUtils.cpp Thu May  2 14:21:55 2019
@@ -745,8 +745,16 @@ MemoryBufferRef convertResToCOFF(ArrayRe
     object::WindowsResource *RF = dyn_cast<object::WindowsResource>(Bin.get());
     if (!RF)
       fatal("cannot compile non-resource file as resource");
-    if (auto EC = Parser.parse(RF))
+
+    std::vector<std::string> Duplicates;
+    if (auto EC = Parser.parse(RF, Duplicates))
       fatal(toString(std::move(EC)));
+
+    for (const auto &DupeDiag : Duplicates)
+      if (Config->ForceMultipleRes)
+        warn(DupeDiag);
+      else
+        error(DupeDiag);
   }
 
   Expected<std::unique_ptr<MemoryBuffer>> E =

Modified: lld/trunk/COFF/Options.td
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Options.td?rev=359829&r1=359828&r2=359829&view=diff
==============================================================================
--- lld/trunk/COFF/Options.td (original)
+++ lld/trunk/COFF/Options.td Thu May  2 14:21:55 2019
@@ -118,6 +118,8 @@ def force_unresolved : F<"force:unresolv
     HelpText<"Allow undefined symbols when creating executables">;
 def force_multiple : F<"force:multiple">,
     HelpText<"Allow multiply defined symbols when creating executables">;
+def force_multipleres : F<"force:multipleres">,
+    HelpText<"Allow multiply defined resources when creating executables">;
 defm WX : B<"WX", "Treat warnings as errors", "Don't treat warnings as errors">;
 
 defm allowbind : B<"allowbind", "Enable DLL binding (default)",

Modified: lld/trunk/docs/ReleaseNotes.rst
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/docs/ReleaseNotes.rst?rev=359829&r1=359828&r2=359829&view=diff
==============================================================================
--- lld/trunk/docs/ReleaseNotes.rst (original)
+++ lld/trunk/docs/ReleaseNotes.rst Thu May  2 14:21:55 2019
@@ -34,6 +34,7 @@ COFF Improvements
 
 * lld-link now correctly reports duplicate symbol errors when several res
   input files define resources with the same type, name, and language.
+  This can be demoted to a warning using ``/force:multipleres``.
 
 * Having more than two ``/natvis:`` now works correctly; it used to not
   work for larger binaries before.

Added: lld/trunk/test/COFF/Inputs/id.res
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/Inputs/id.res?rev=359829&view=auto
==============================================================================
Binary file - no diff available.

Propchange: lld/trunk/test/COFF/Inputs/id.res
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: lld/trunk/test/COFF/force-multipleres.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/force-multipleres.test?rev=359829&view=auto
==============================================================================
--- lld/trunk/test/COFF/force-multipleres.test (added)
+++ lld/trunk/test/COFF/force-multipleres.test Thu May  2 14:21:55 2019
@@ -0,0 +1,21 @@
+// Check that lld-link rejects duplicate resources, unless
+// /force or /force:multipleres is passed.
+// The input was generated with the following command, using the original Windows
+// rc.exe:
+// > rc /fo id.res /nologo id.rc
+// > rc /fo name.res /nologo name.rc
+
+RUN: rm -rf %t.dir
+RUN: mkdir %t.dir
+RUN: cp %S/Inputs/id.res %t.dir/id1.res
+RUN: cp %S/Inputs/id.res %t.dir/id2.res
+
+RUN: not lld-link /machine:x64 /nodefaultlib /noentry /dll %t.dir/id1.res %t.dir/id2.res 2>&1 | \
+RUN:     FileCheck -check-prefix=ERR %s
+ERR: error: duplicate resource: type STRINGTABLE (ID 6)/name ID 3/language 1033, in {{.*}}id1.res and in {{.*}}id2.res
+
+RUN: lld-link /force /machine:x64 /nodefaultlib /noentry /dll %t.dir/id1.res %t.dir/id2.res 2>&1 | \
+RUN:     FileCheck -check-prefix=WARN %s
+RUN: lld-link /force:multipleres /machine:x64 /nodefaultlib /noentry /dll %t.dir/id1.res %t.dir/id2.res 2>&1 | \
+RUN:     FileCheck -check-prefix=WARN %s
+WARN: warning: duplicate resource: type STRINGTABLE (ID 6)/name ID 3/language 1033, in {{.*}}id1.res and in {{.*}}id2.res




More information about the llvm-commits mailing list