[lld] r198104 - [PECOFF] Warn only when /export options are not compatible.

Rui Ueyama ruiu at google.com
Sat Dec 28 00:40:37 PST 2013


Author: ruiu
Date: Sat Dec 28 02:40:37 2013
New Revision: 198104

URL: http://llvm.org/viewvc/llvm-project?rev=198104&view=rev
Log:
[PECOFF] Warn only when /export options are not compatible.

Currently LLD always print a warning message if the same symbol is specified
more than once for /export option. It's a bit annoying because specifying the
same symbol with compatible options is actually safe and considered as a
normal use case. This patch makes LLD to warn only when incompatible export
options are given.

Added:
    lld/trunk/test/pecoff/export-warning.test
Modified:
    lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp

Modified: lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp?rev=198104&r1=198103&r2=198104&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp Sat Dec 28 02:40:37 2013
@@ -231,13 +231,30 @@ uint32_t PECOFFLinkingContext::getSectio
   return (flags | setMask) & ~clearMask;
 }
 
+// Returns true if two export descriptors have conflicting contents,
+// e.g. different export ordinals.
+static bool exportConflicts(const PECOFFLinkingContext::ExportDesc &a,
+                            const PECOFFLinkingContext::ExportDesc &b) {
+  if (a.ordinal > 0 && b.ordinal > 0 && a.ordinal != b.ordinal)
+    return true;
+  if (a.noname != b.noname)
+    return true;
+  if (a.isData != b.isData)
+    return true;
+  return false;
+}
+
 void PECOFFLinkingContext::addDllExport(ExportDesc &desc) {
-  auto exists = _dllExports.insert(desc);
-  if (!exists.second) {
-    llvm::errs() << "Export symbol '" << desc.name
-                 << "' specified more than once.\n";
+  auto existing = _dllExports.insert(desc);
+  if (existing.second)
+    return;
+  if (!exportConflicts(*existing.first, desc)) {
+    _dllExports.erase(existing.first);
+    _dllExports.insert(desc);
     return;
   }
+  llvm::errs() << "Export symbol '" << desc.name
+               << "' specified more than once.\n";
 }
 
 void PECOFFLinkingContext::addPasses(PassManager &pm) {

Added: lld/trunk/test/pecoff/export-warning.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/export-warning.test?rev=198104&view=auto
==============================================================================
--- lld/trunk/test/pecoff/export-warning.test (added)
+++ lld/trunk/test/pecoff/export-warning.test Sat Dec 28 02:40:37 2013
@@ -0,0 +1,16 @@
+# RUN: yaml2obj %p/Inputs/export.obj.yaml > %t.obj
+#
+# RUN: lld -flavor link /out:%t1.dll /dll /entry:init \
+# RUN:   /export:exportfn1 /export:exportfn1 -- %t.obj 2> t1.log
+# RUN: FileCheck -check-prefix=CHECK1 %s < t1.log
+CHECK1-NOT: Export symbol '_exportfn1' specified more than once.
+
+# RUN: lld -flavor link /out:%t2.dll /dll /entry:init \
+# RUN:   /export:exportfn1 /export:exportfn1, at 5 -- %t.obj 2> t2.log
+# RUN: FileCheck -check-prefix=CHECK2 %s < t2.log
+CHECK2-NOT: Export symbol '_exportfn1' specified more than once.
+
+# RUN: lld -flavor link /out:%t3.dll /dll /entry:init \
+# RUN:   /export:exportfn1, at 8 /export:exportfn1, at 5 -- %t.obj 2> t3.log
+# RUN: FileCheck -check-prefix=CHECK3 %s < t3.log
+CHECK3: Export symbol '_exportfn1' specified more than once.





More information about the llvm-commits mailing list