[lld] r323699 - Warn on nonexistent comdat sections in an /order file.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 29 13:50:53 PST 2018


Author: ruiu
Date: Mon Jan 29 13:50:53 2018
New Revision: 323699

URL: http://llvm.org/viewvc/llvm-project?rev=323699&view=rev
Log:
Warn on nonexistent comdat sections in an /order file.

I didn't implement the feature in the original patch because I didn't
come up with an idea to do that easily and efficiently. Turned out that
that is actually easy to implement.

In this patch, we collect comdat sections before gc is run and warn on
nonexistent symbols in an order file.

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

Modified:
    lld/trunk/COFF/Driver.cpp
    lld/trunk/test/COFF/order.test

Modified: lld/trunk/COFF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.cpp?rev=323699&r1=323698&r2=323699&view=diff
==============================================================================
--- lld/trunk/COFF/Driver.cpp (original)
+++ lld/trunk/COFF/Driver.cpp Mon Jan 29 13:50:53 2018
@@ -768,6 +768,13 @@ static void parseOrderFile(StringRef Arg
     return;
   }
 
+  // Get a list of all comdat sections for error checking.
+  DenseSet<StringRef> Set;
+  for (Chunk *C : Symtab->getChunks())
+    if (auto *Sec = dyn_cast<SectionChunk>(C))
+      if (Sec->Sym)
+        Set.insert(Sec->Sym->getName());
+
   // Open a file.
   StringRef Path = Arg.substr(1);
   std::unique_ptr<MemoryBuffer> MB = CHECK(
@@ -780,7 +787,11 @@ static void parseOrderFile(StringRef Arg
   for (std::string S : args::getLines(MB->getMemBufferRef())) {
     if (Config->Machine == I386 && !isDecorated(S))
       S = "_" + S;
-    Config->Order[S] = INT_MIN + Config->Order.size();
+
+    if (Set.count(S) == 0)
+      warn("/order:" + Arg + ": missing symbol: " + S);
+    else
+      Config->Order[S] = INT_MIN + Config->Order.size();
   }
 }
 
@@ -1188,10 +1199,6 @@ void LinkerDriver::link(ArrayRef<const c
     }
   }
 
-  // Handle /order
-  if (auto *Arg = Args.getLastArg(OPT_order))
-    parseOrderFile(Arg->getValue());
-
   // Handle /export
   for (auto *Arg : Args.filtered(OPT_export)) {
     Export E = parseExport(Arg->getValue());
@@ -1391,6 +1398,12 @@ void LinkerDriver::link(ArrayRef<const c
   if (Config->Manifest == Configuration::SideBySide)
     createSideBySideManifest();
 
+  // Handle /order. We want to do this at this moment because we
+  // need a complete list of comdat sections to warn on nonexistent
+  // functions.
+  if (auto *Arg = Args.getLastArg(OPT_order))
+    parseOrderFile(Arg->getValue());
+
   // Identify unreferenced COMDAT sections.
   if (Config->DoGC)
     markLive(Symtab->getChunks());

Modified: lld/trunk/test/COFF/order.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/order.test?rev=323699&r1=323698&r2=323699&view=diff
==============================================================================
--- lld/trunk/test/COFF/order.test (original)
+++ lld/trunk/test/COFF/order.test Mon Jan 29 13:50:53 2018
@@ -24,6 +24,18 @@
 # DEFAULT: fn4
 # DEFAULT: fn1
 
+# RUN: echo fn1 > %t2.order
+# RUN: echo fn2 >> %t2.order
+# RUN: echo fn3 >> %t2.order
+# RUN: echo fn4 >> %t2.order
+# RUN: echo foo >> %t2.order
+# RUN: lld-link -entry:fn1 -subsystem:console -debug %t1.obj %t2.obj \
+# RUN:   -out:%t.exe -order:@%t2.order 2>&1 | FileCheck -check-prefix=WARN %s
+# WARN: warning: /order:{{.*}} missing symbol: foo
+# WARN-NOT: f2
+# WARN-NOT: f3
+# WARN-NOT: f4
+
 --- !COFF
 header:
   Machine:         IMAGE_FILE_MACHINE_AMD64




More information about the llvm-commits mailing list