[lld] r321512 - [COFF] support /ignore:4217

Bob Haarman via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 27 23:02:14 PST 2017


Author: inglorion
Date: Wed Dec 27 23:02:13 2017
New Revision: 321512

URL: http://llvm.org/viewvc/llvm-project?rev=321512&view=rev
Log:
[COFF] support /ignore:4217

Summary:
lld-link accepts link.exe's /ignore option, but used to ignore
it. This can lead to semantic differences when warnings are treated as
fatal errors. One such case is when we resolve an __imp_ symbol to a
local definition. We emit a warning in that case, which /wx turns into
a fatal. This change makes lld-link accept /ignore:4217 to suppress
that warning, so that code that links with link.exe /wx /ignore:4217
links with lld-link, too.

Fixes PR35762.

Reviewers: rnk, ruiu

Reviewed By: ruiu

Subscribers: llvm-commits

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

Added:
    lld/trunk/test/COFF/ignore4217.yaml
Modified:
    lld/trunk/COFF/Config.h
    lld/trunk/COFF/Driver.cpp
    lld/trunk/COFF/Options.td
    lld/trunk/COFF/SymbolTable.cpp

Modified: lld/trunk/COFF/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Config.h?rev=321512&r1=321511&r2=321512&view=diff
==============================================================================
--- lld/trunk/COFF/Config.h (original)
+++ lld/trunk/COFF/Config.h Wed Dec 27 23:02:13 2017
@@ -174,6 +174,7 @@ struct Configuration {
   bool HighEntropyVA = false;
   bool AppContainer = false;
   bool MinGW = false;
+  bool WarnLocallyDefinedImported = true;
 };
 
 extern Configuration *Config;

Modified: lld/trunk/COFF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.cpp?rev=321512&r1=321511&r2=321512&view=diff
==============================================================================
--- lld/trunk/COFF/Driver.cpp (original)
+++ lld/trunk/COFF/Driver.cpp Wed Dec 27 23:02:13 2017
@@ -795,6 +795,13 @@ void LinkerDriver::link(ArrayRef<const c
     SearchPaths.push_back(Arg->getValue());
   addLibSearchPaths();
 
+  // Handle /ignore
+  for (auto *Arg : Args.filtered(OPT_ignore)) {
+    if (StringRef(Arg->getValue()) == "4217")
+      Config->WarnLocallyDefinedImported = false;
+    // Other warning numbers are ignored.
+  }
+
   // Handle /out
   if (auto *Arg = Args.getLastArg(OPT_out))
     Config->OutputFile = Arg->getValue();

Modified: lld/trunk/COFF/Options.td
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Options.td?rev=321512&r1=321511&r2=321512&view=diff
==============================================================================
--- lld/trunk/COFF/Options.td (original)
+++ lld/trunk/COFF/Options.td Wed Dec 27 23:02:13 2017
@@ -29,6 +29,7 @@ def export  : P<"export", "Export a func
 // No help text because /failifmismatch is not intended to be used by the user.
 def failifmismatch : P<"failifmismatch", "">;
 def heap    : P<"heap", "Size of the heap">;
+def ignore : P<"ignore", "Specify warning codes to ignore">;
 def implib  : P<"implib", "Import library name">;
 def libpath : P<"libpath", "Additional library search path">;
 def linkrepro : P<"linkrepro", "Dump linker invocation and input files for debugging">;
@@ -155,7 +156,6 @@ def fastfail : F<"fastfail">;
 def delay : QF<"delay">;
 def errorreport : QF<"errorreport">;
 def idlout : QF<"idlout">;
-def ignore : QF<"ignore">;
 def maxilksize : QF<"maxilksize">;
 def natvis : QF<"natvis">;
 def pdbaltpath : QF<"pdbaltpath">;

Modified: lld/trunk/COFF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/SymbolTable.cpp?rev=321512&r1=321511&r2=321512&view=diff
==============================================================================
--- lld/trunk/COFF/SymbolTable.cpp (original)
+++ lld/trunk/COFF/SymbolTable.cpp Wed Dec 27 23:02:13 2017
@@ -117,9 +117,10 @@ void SymbolTable::reportRemainingUndefin
   for (Symbol *B : Config->GCRoot) {
     if (Undefs.count(B))
       errorOrWarn("<root>: undefined symbol: " + B->getName());
-    if (Symbol *Imp = LocalImports.lookup(B))
-      warn("<root>: locally defined symbol imported: " + Imp->getName() +
-           " (defined in " + toString(Imp->getFile()) + ")");
+    if (Config->WarnLocallyDefinedImported)
+      if (Symbol *Imp = LocalImports.lookup(B))
+        warn("<root>: locally defined symbol imported: " + Imp->getName() +
+             " (defined in " + toString(Imp->getFile()) + ")");
   }
 
   for (ObjFile *File : ObjFile::Instances) {
@@ -128,9 +129,11 @@ void SymbolTable::reportRemainingUndefin
         continue;
       if (Undefs.count(Sym))
         errorOrWarn(toString(File) + ": undefined symbol: " + Sym->getName());
-      if (Symbol *Imp = LocalImports.lookup(Sym))
-        warn(toString(File) + ": locally defined symbol imported: " +
-             Imp->getName() + " (defined in " + toString(Imp->getFile()) + ")");
+      if (Config->WarnLocallyDefinedImported)
+        if (Symbol *Imp = LocalImports.lookup(Sym))
+          warn(toString(File) + ": locally defined symbol imported: " +
+               Imp->getName() + " (defined in " + toString(Imp->getFile()) +
+               ")");
     }
   }
 }

Added: lld/trunk/test/COFF/ignore4217.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/ignore4217.yaml?rev=321512&view=auto
==============================================================================
--- lld/trunk/test/COFF/ignore4217.yaml (added)
+++ lld/trunk/test/COFF/ignore4217.yaml Wed Dec 27 23:02:13 2017
@@ -0,0 +1,72 @@
+# Tests that /ignore:4217 suppresses "locally defined symbol imported" warnings.
+# RUN: yaml2obj < %s > %t.obj
+
+# RUN: lld-link -entry:main -out:%t.exe %t.obj 2>&1 \
+# RUN:     | FileCheck -check-prefix=WARNINGS %s
+# RUN: lld-link -ignore:4217 -entry:main -out:%t.exe %t.obj 2>&1 \
+# RUN:     | FileCheck -allow-empty -check-prefix=SUPPRESSED %s
+
+# WARNINGS: locally defined symbol imported
+# SUPPRESSED-NOT: locally defined symbol imported
+
+--- !COFF
+header:
+  Machine:         IMAGE_FILE_MACHINE_AMD64
+  Characteristics: [  ]
+sections:
+  - Name:            .text
+    Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+    Alignment:       16
+    SectionData:     B82A000000C3662E0F1F8400000000004883EC28C744242400000000E800000000904883C428C3
+    Relocations:
+      - VirtualAddress:  29
+        SymbolName:      __imp_foo
+        Type:            IMAGE_REL_AMD64_REL32
+  - Name:            .data
+    Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
+    Alignment:       4
+    SectionData:     ''
+symbols:
+  - Name:            .text
+    Value:           0
+    SectionNumber:   1
+    SimpleType:      IMAGE_SYM_TYPE_NULL
+    ComplexType:     IMAGE_SYM_DTYPE_NULL
+    StorageClass:    IMAGE_SYM_CLASS_STATIC
+    SectionDefinition:
+      Length:          39
+      NumberOfRelocations: 1
+      NumberOfLinenumbers: 0
+      CheckSum:        3087210877
+      Number:          1
+  - Name:            .data
+    Value:           0
+    SectionNumber:   2
+    SimpleType:      IMAGE_SYM_TYPE_NULL
+    ComplexType:     IMAGE_SYM_DTYPE_NULL
+    StorageClass:    IMAGE_SYM_CLASS_STATIC
+    SectionDefinition:
+      Length:          0
+      NumberOfRelocations: 0
+      NumberOfLinenumbers: 0
+      CheckSum:        0
+      Number:          2
+  - Name:            foo
+    Value:           0
+    SectionNumber:   1
+    SimpleType:      IMAGE_SYM_TYPE_NULL
+    ComplexType:     IMAGE_SYM_DTYPE_FUNCTION
+    StorageClass:    IMAGE_SYM_CLASS_EXTERNAL
+  - Name:            main
+    Value:           16
+    SectionNumber:   1
+    SimpleType:      IMAGE_SYM_TYPE_NULL
+    ComplexType:     IMAGE_SYM_DTYPE_FUNCTION
+    StorageClass:    IMAGE_SYM_CLASS_EXTERNAL
+  - Name:            __imp_foo
+    Value:           0
+    SectionNumber:   0
+    SimpleType:      IMAGE_SYM_TYPE_NULL
+    ComplexType:     IMAGE_SYM_DTYPE_NULL
+    StorageClass:    IMAGE_SYM_CLASS_EXTERNAL
+...




More information about the llvm-commits mailing list