[lld] r338434 - ELF: Add libcall symbols to the link when LTO is being used.

Peter Collingbourne via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 31 13:36:17 PDT 2018


Author: pcc
Date: Tue Jul 31 13:36:17 2018
New Revision: 338434

URL: http://llvm.org/viewvc/llvm-project?rev=338434&view=rev
Log:
ELF: Add libcall symbols to the link when LTO is being used.

If any of our inputs are bitcode files, the LTO code generator may create
references to certain library functions that might not be 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.

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

Added:
    lld/trunk/test/ELF/lto/Inputs/libcall-archive.ll
    lld/trunk/test/ELF/lto/libcall-archive.ll
Modified:
    lld/trunk/ELF/Driver.cpp

Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=338434&r1=338433&r2=338434&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Tue Jul 31 13:36:17 2018
@@ -1313,6 +1313,12 @@ static void findKeepUniqueSections(opt::
   }
 }
 
+static const char *LibcallRoutineNames[] = {
+#define HANDLE_LIBCALL(code, name) name,
+#include "llvm/IR/RuntimeLibcalls.def"
+#undef HANDLE_LIBCALL
+};
+
 // Do actual linking. Note that when this function is called,
 // all linker scripts have already been parsed.
 template <class ELFT> void LinkerDriver::link(opt::InputArgList &Args) {
@@ -1379,11 +1385,21 @@ template <class ELFT> void LinkerDriver:
   for (StringRef S : Config->Undefined)
     handleUndefined<ELFT>(S);
 
-  // If an entry symbol is in a static archive, pull out that file now
-  // to complete the symbol table. After this, no new names except a
-  // few linker-synthesized ones will be added to the symbol table.
+  // If an entry symbol is in a static archive, pull out that file now.
   handleUndefined<ELFT>(Config->Entry);
 
+  // If any of our inputs are bitcode files, the LTO code generator may create
+  // references to certain library functions that might not be 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.
+  //
+  // With this the symbol table should be complete. After this, no new names
+  // except a few linker-synthesized ones will be added to the symbol table.
+  if (!BitcodeFiles.empty())
+    for (const char *S : LibcallRoutineNames)
+      handleUndefined<ELFT>(S);
+
   // Return if there were name resolution errors.
   if (errorCount())
     return;

Added: lld/trunk/test/ELF/lto/Inputs/libcall-archive.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/lto/Inputs/libcall-archive.ll?rev=338434&view=auto
==============================================================================
--- lld/trunk/test/ELF/lto/Inputs/libcall-archive.ll (added)
+++ lld/trunk/test/ELF/lto/Inputs/libcall-archive.ll Tue Jul 31 13:36:17 2018
@@ -0,0 +1,6 @@
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+define void @memcpy() {
+  ret void
+}

Added: lld/trunk/test/ELF/lto/libcall-archive.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/lto/libcall-archive.ll?rev=338434&view=auto
==============================================================================
--- lld/trunk/test/ELF/lto/libcall-archive.ll (added)
+++ lld/trunk/test/ELF/lto/libcall-archive.ll Tue Jul 31 13:36:17 2018
@@ -0,0 +1,20 @@
+; RUN: rm -f %t.a
+; RUN: llvm-as -o %t.o %s
+; RUN: llvm-as -o %t2.o %S/Inputs/libcall-archive.ll
+; RUN: llvm-ar rcs %t.a %t2.o
+; RUN: ld.lld -o %t %t.o %t.a
+; RUN: llvm-nm %t | FileCheck %s
+
+; CHECK: T _start
+; CHECK: T memcpy
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+define void @_start(i8* %a, i8* %b) {
+entry:
+  call void @llvm.memcpy.p0i8.p0i8.i64(i8* %a, i8* %b, i64 1024, i1 false)
+  ret void
+}
+
+declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i1)




More information about the llvm-commits mailing list