[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 13:54:05 PST 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rLLD323699: Warn on nonexistent comdat sections in an /order file. (authored by ruiu, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D42658?vs=131856&id=131873#toc

Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D42658

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


Index: test/COFF/order.test
===================================================================
--- test/COFF/order.test
+++ 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: COFF/Driver.cpp
===================================================================
--- COFF/Driver.cpp
+++ 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.131873.patch
Type: text/x-patch
Size: 2271 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180129/24bda6cb/attachment.bin>


More information about the llvm-commits mailing list