[PATCH] D17867: [gold] Handle modules that are not included in the link.

Evgeniy Stepanov via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 3 14:01:40 PST 2016


eugenis created this revision.
eugenis added a reviewer: rafael.
eugenis added a subscriber: llvm-commits.
eugenis set the repository for this revision to rL LLVM.

Gold has a newly added LDPT_GET_SYMBOLS_V3 callback that can
distinguish between a module that is not included in the link, and
one that is included but has its entire interface preempted by others.

Fixes PR26674.


Repository:
  rL LLVM

http://reviews.llvm.org/D17867

Files:
  tools/gold/gold-plugin.cpp

Index: tools/gold/gold-plugin.cpp
===================================================================
--- tools/gold/gold-plugin.cpp
+++ tools/gold/gold-plugin.cpp
@@ -55,6 +55,8 @@
 # define LDPO_PIE 3
 #endif
 
+#define LDPT_GET_SYMBOLS_V3 28
+
 using namespace llvm;
 
 static ld_plugin_status discard_message(int level, const char *format, ...) {
@@ -212,7 +214,10 @@
   bool RegisteredAllSymbolsRead = false;
 
   for (; tv->tv_tag != LDPT_NULL; ++tv) {
-    switch (tv->tv_tag) {
+    // Cast tv_tag to int to allow values not in "enum ld_plugin_tag", like, for
+    // example, LDPT_GET_SYMBOLS_V3 when building against an older plugin-api.h
+    // header.
+    switch (static_cast<int>(tv->tv_tag)) {
       case LDPT_OUTPUT_NAME:
         output_name = tv->tv_u.tv_string;
         break;
@@ -269,6 +274,10 @@
         add_symbols = tv->tv_u.tv_add_symbols;
         break;
       case LDPT_GET_SYMBOLS_V2:
+        // Do not override get_symbols_v3 with get_symbols_v2.
+        if (!get_symbols) get_symbols = tv->tv_u.tv_get_symbols;
+        break;
+      case LDPT_GET_SYMBOLS_V3:
         get_symbols = tv->tv_u.tv_get_symbols;
         break;
       case LDPT_ADD_INPUT_FILE:
@@ -562,8 +571,11 @@
 
 static std::unique_ptr<FunctionInfoIndex>
 getFunctionIndexForFile(claimed_file &F, ld_plugin_input_file &Info) {
+  ld_plugin_status status = get_symbols(F.handle, F.syms.size(), &F.syms[0]);
+  if (status == LDPS_NO_SYMS)
+    return nullptr;
 
-  if (get_symbols(F.handle, F.syms.size(), &F.syms[0]) != LDPS_OK)
+  if (status != LDPS_OK)
     message(LDPL_FATAL, "Failed to get symbol information");
 
   const void *View;
@@ -597,7 +609,11 @@
                  StringSet<> &Internalize, StringSet<> &Maybe,
                  std::vector<GlobalValue *> &Keep) {
 
-  if (get_symbols(F.handle, F.syms.size(), F.syms.data()) != LDPS_OK)
+  ld_plugin_status status = get_symbols(F.handle, F.syms.size(), F.syms.data());
+  if (status == LDPS_NO_SYMS)
+    return nullptr;
+
+  if (status != LDPS_OK)
     message(LDPL_FATAL, "Failed to get symbol information");
 
   const void *View;
@@ -901,6 +917,7 @@
     std::vector<GlobalValue *> Keep;
     std::unique_ptr<Module> M = getModuleForFile(
         Context, F, InputFile.file(), ApiFile, Internalize, Maybe, Keep);
+    if (!M.get()) continue;
     if (!options::triple.empty())
       M->setTargetTriple(options::triple.c_str());
     else if (M->getTargetTriple().empty())


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D17867.49775.patch
Type: text/x-patch
Size: 2446 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160303/e2a280fb/attachment.bin>


More information about the llvm-commits mailing list