[llvm-branch-commits] [lld] r369883 - Merging r369694:

Hans Wennborg via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Aug 26 01:36:43 PDT 2019


Author: hans
Date: Mon Aug 26 01:36:43 2019
New Revision: 369883

URL: http://llvm.org/viewvc/llvm-project?rev=369883&view=rev
Log:
Merging r369694:
------------------------------------------------------------------------
r369694 | akhuang | 2019-08-22 21:40:07 +0200 (Thu, 22 Aug 2019) | 1 line

[COFF] Add libcall symbols to the link when LTO is being used
------------------------------------------------------------------------

Added:
    lld/branches/release_90/test/COFF/Inputs/libcall-archive.ll
      - copied unchanged from r369694, lld/trunk/test/COFF/Inputs/libcall-archive.ll
    lld/branches/release_90/test/COFF/Inputs/libcall-archive.s
      - copied unchanged from r369694, lld/trunk/test/COFF/Inputs/libcall-archive.s
    lld/branches/release_90/test/COFF/libcall-archive.ll
      - copied unchanged from r369694, lld/trunk/test/COFF/libcall-archive.ll
Modified:
    lld/branches/release_90/   (props changed)
    lld/branches/release_90/COFF/Driver.cpp
    lld/branches/release_90/COFF/SymbolTable.cpp
    lld/branches/release_90/COFF/SymbolTable.h
    lld/branches/release_90/COFF/Symbols.cpp
    lld/branches/release_90/COFF/Symbols.h

Propchange: lld/branches/release_90/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Aug 26 01:36:43 2019
@@ -1 +1 @@
-/lld/trunk:366445,366500,366504,366573,366780,366784,366836,367836-367837,368041,368078,368145,369445
+/lld/trunk:366445,366500,366504,366573,366780,366784,366836,367836-367837,368041,368078,368145,369445,369694

Modified: lld/branches/release_90/COFF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/branches/release_90/COFF/Driver.cpp?rev=369883&r1=369882&r2=369883&view=diff
==============================================================================
--- lld/branches/release_90/COFF/Driver.cpp (original)
+++ lld/branches/release_90/COFF/Driver.cpp Mon Aug 26 01:36:43 2019
@@ -1055,6 +1055,12 @@ void LinkerDriver::maybeExportMinGWSymbo
   });
 }
 
+static const char *libcallRoutineNames[] = {
+#define HANDLE_LIBCALL(code, name) name,
+#include "llvm/IR/RuntimeLibcalls.def"
+#undef HANDLE_LIBCALL
+};
+
 void LinkerDriver::link(ArrayRef<const char *> argsArr) {
   // Needed for LTO.
   InitializeAllTargetInfos();
@@ -1757,6 +1763,15 @@ void LinkerDriver::link(ArrayRef<const c
           u->weakAlias = symtab->addUndefined(to);
     }
 
+    // If any inputs are bitcode files, the LTO code generator may create
+    // references to library functions that are not explicit in the bitcode
+    // file's symbol table. If any of those library functions are defined in a
+    // bitcode file in an archive member, we need to arrange to use LTO to
+    // compile those archive members by adding them to the link beforehand.
+    if (!BitcodeFile::instances.empty())
+      for (const char *s : libcallRoutineNames)
+        symtab->addLibcall(s);
+
     // Windows specific -- if __load_config_used can be resolved, resolve it.
     if (symtab->findUnderscore("_load_config_used"))
       addUndefined(mangle("_load_config_used"));

Modified: lld/branches/release_90/COFF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/branches/release_90/COFF/SymbolTable.cpp?rev=369883&r1=369882&r2=369883&view=diff
==============================================================================
--- lld/branches/release_90/COFF/SymbolTable.cpp (original)
+++ lld/branches/release_90/COFF/SymbolTable.cpp Mon Aug 26 01:36:43 2019
@@ -505,6 +505,18 @@ Symbol *SymbolTable::addImportThunk(Stri
   return nullptr;
 }
 
+void SymbolTable::addLibcall(StringRef name) {
+  Symbol *sym = findUnderscore(name);
+  if (!sym)
+    return;
+
+  if (Lazy *l = dyn_cast<Lazy>(sym)) {
+    MemoryBufferRef mb = l->getMemberBuffer();
+    if (identify_magic(mb.getBuffer()) == llvm::file_magic::bitcode)
+      addUndefined(sym->getName());
+  }
+}
+
 std::vector<Chunk *> SymbolTable::getChunks() {
   std::vector<Chunk *> res;
   for (ObjFile *file : ObjFile::instances) {

Modified: lld/branches/release_90/COFF/SymbolTable.h
URL: http://llvm.org/viewvc/llvm-project/lld/branches/release_90/COFF/SymbolTable.h?rev=369883&r1=369882&r2=369883&view=diff
==============================================================================
--- lld/branches/release_90/COFF/SymbolTable.h (original)
+++ lld/branches/release_90/COFF/SymbolTable.h Mon Aug 26 01:36:43 2019
@@ -97,6 +97,7 @@ public:
   Symbol *addImportData(StringRef n, ImportFile *f);
   Symbol *addImportThunk(StringRef name, DefinedImportData *s,
                          uint16_t machine);
+  void addLibcall(StringRef name);
 
   void reportDuplicate(Symbol *existing, InputFile *newFile);
 

Modified: lld/branches/release_90/COFF/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/branches/release_90/COFF/Symbols.cpp?rev=369883&r1=369882&r2=369883&view=diff
==============================================================================
--- lld/branches/release_90/COFF/Symbols.cpp (original)
+++ lld/branches/release_90/COFF/Symbols.cpp Mon Aug 26 01:36:43 2019
@@ -118,5 +118,14 @@ Defined *Undefined::getWeakAlias() {
       return d;
   return nullptr;
 }
+
+MemoryBufferRef Lazy::getMemberBuffer() {
+  Archive::Child c =
+    CHECK(sym.getMember(),
+          "could not get the member for symbol " + toCOFFString(sym));
+  return CHECK(c.getMemoryBufferRef(),
+      "could not get the buffer for the member defining symbol " +
+      toCOFFString(sym));
+}
 } // namespace coff
 } // namespace lld

Modified: lld/branches/release_90/COFF/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/branches/release_90/COFF/Symbols.h?rev=369883&r1=369882&r2=369883&view=diff
==============================================================================
--- lld/branches/release_90/COFF/Symbols.h (original)
+++ lld/branches/release_90/COFF/Symbols.h Mon Aug 26 01:36:43 2019
@@ -265,6 +265,8 @@ public:
 
   static bool classof(const Symbol *s) { return s->kind() == LazyKind; }
 
+  MemoryBufferRef getMemberBuffer();
+
   ArchiveFile *file;
 
 private:




More information about the llvm-branch-commits mailing list