Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 103b4dc

Browse files
committed
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 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@338434 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent cee6e82 commit 103b4dc

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-3
lines changed

ELF/Driver.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,6 +1313,12 @@ static void findKeepUniqueSections(opt::InputArgList &Args) {
13131313
}
13141314
}
13151315

1316+
static const char *LibcallRoutineNames[] = {
1317+
#define HANDLE_LIBCALL(code, name) name,
1318+
#include "llvm/IR/RuntimeLibcalls.def"
1319+
#undef HANDLE_LIBCALL
1320+
};
1321+
13161322
// Do actual linking. Note that when this function is called,
13171323
// all linker scripts have already been parsed.
13181324
template <class ELFT> void LinkerDriver::link(opt::InputArgList &Args) {
@@ -1379,11 +1385,21 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &Args) {
13791385
for (StringRef S : Config->Undefined)
13801386
handleUndefined<ELFT>(S);
13811387

1382-
// If an entry symbol is in a static archive, pull out that file now
1383-
// to complete the symbol table. After this, no new names except a
1384-
// few linker-synthesized ones will be added to the symbol table.
1388+
// If an entry symbol is in a static archive, pull out that file now.
13851389
handleUndefined<ELFT>(Config->Entry);
13861390

1391+
// If any of our inputs are bitcode files, the LTO code generator may create
1392+
// references to certain library functions that might not be explicit in the
1393+
// bitcode file's symbol table. If any of those library functions are defined
1394+
// in a bitcode file in an archive member, we need to arrange to use LTO to
1395+
// compile those archive members by adding them to the link beforehand.
1396+
//
1397+
// With this the symbol table should be complete. After this, no new names
1398+
// except a few linker-synthesized ones will be added to the symbol table.
1399+
if (!BitcodeFiles.empty())
1400+
for (const char *S : LibcallRoutineNames)
1401+
handleUndefined<ELFT>(S);
1402+
13871403
// Return if there were name resolution errors.
13881404
if (errorCount())
13891405
return;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
2+
target triple = "x86_64-unknown-linux-gnu"
3+
4+
define void @memcpy() {
5+
ret void
6+
}

test/ELF/lto/libcall-archive.ll

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
; RUN: rm -f %t.a
2+
; RUN: llvm-as -o %t.o %s
3+
; RUN: llvm-as -o %t2.o %S/Inputs/libcall-archive.ll
4+
; RUN: llvm-ar rcs %t.a %t2.o
5+
; RUN: ld.lld -o %t %t.o %t.a
6+
; RUN: llvm-nm %t | FileCheck %s
7+
8+
; CHECK: T _start
9+
; CHECK: T memcpy
10+
11+
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
12+
target triple = "x86_64-unknown-linux-gnu"
13+
14+
define void @_start(i8* %a, i8* %b) {
15+
entry:
16+
call void @llvm.memcpy.p0i8.p0i8.i64(i8* %a, i8* %b, i64 1024, i1 false)
17+
ret void
18+
}
19+
20+
declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i1)

0 commit comments

Comments
 (0)