[PATCH] D42658: Warn on nonexistent comdat sections in an /order file.

Rui Ueyama via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 29 12:42:14 PST 2018


ruiu created this revision.
ruiu added a reviewer: pcc.

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.


https://reviews.llvm.org/D42658

Files:
  lld/COFF/Driver.cpp
  lld/test/COFF/order.test


Index: lld/test/COFF/order.test
===================================================================
--- lld/test/COFF/order.test
+++ lld/test/COFF/order.test
@@ -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
Index: lld/COFF/Driver.cpp
===================================================================
--- lld/COFF/Driver.cpp
+++ lld/COFF/Driver.cpp
@@ -768,6 +768,13 @@
     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 @@
   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 @@
     }
   }
 
-  // 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 @@
   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());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42658.131856.patch
Type: text/x-patch
Size: 2295 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180129/0c98c82a/attachment.bin>


More information about the llvm-commits mailing list