[PATCH] D50017: ELF: Add libcall symbols to the link when LTO is being used.

Peter Collingbourne via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 30 14:56:08 PDT 2018


pcc created this revision.
pcc added a reviewer: ruiu.
Herald added subscribers: dexonsmith, steven_wu, arichardson, inglorion, emaste.
Herald added a reviewer: espindola.

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.

Depends on https://reviews.llvm.org/D50016


Repository:
  rL LLVM

https://reviews.llvm.org/D50017

Files:
  lld/ELF/Driver.cpp
  lld/test/ELF/lto/Inputs/libcall-archive.ll
  lld/test/ELF/lto/libcall-archive.ll


Index: lld/test/ELF/lto/libcall-archive.ll
===================================================================
--- /dev/null
+++ lld/test/ELF/lto/libcall-archive.ll
@@ -0,0 +1,19 @@
+; 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 __cyg_profile_func_enter_bare
+; CHECK: T _start
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+define void @_start() #0 {
+entry:
+  ret void
+}
+
+attributes #0 = { "instrument-function-entry-inlined"="__cyg_profile_func_enter_bare" }
Index: lld/test/ELF/lto/Inputs/libcall-archive.ll
===================================================================
--- /dev/null
+++ lld/test/ELF/lto/Inputs/libcall-archive.ll
@@ -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 @__cyg_profile_func_enter_bare() {
+  ret void
+}
Index: lld/ELF/Driver.cpp
===================================================================
--- lld/ELF/Driver.cpp
+++ lld/ELF/Driver.cpp
@@ -1303,6 +1303,12 @@
   }
 }
 
+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) {
@@ -1369,11 +1375,21 @@
   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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50017.158090.patch
Type: text/x-patch
Size: 2752 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180730/4e67bc0b/attachment.bin>


More information about the llvm-commits mailing list