Skip to content

Commit 9e0c494

Browse files
committed
[LLVM][LTO] Factor out RTLib calls and allow them to be dropped
Summary: The LTO pass and LLD linker have logic in them that forces extraction and prevent internalization of needed runtime calls. However, these currently take all RTLibcalls into account, even if the target does not support them. The target opts-out of a libcall if it sets its name to nullptr. This patch pulls this logic out into a class in the header so that LTO / lld can use it to determine if a symbol actually needs to be kept. This is important for targets like AMDGPU that want to be able to use `lld` to perform the final link step, but cannot maintain the overhead of several unused function calls.
1 parent 3f1a767 commit 9e0c494

File tree

9 files changed

+479
-417
lines changed

9 files changed

+479
-417
lines changed

lld/COFF/Driver.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2428,9 +2428,12 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
24282428
// file's symbol table. If any of those library functions are defined in a
24292429
// bitcode file in an archive member, we need to arrange to use LTO to
24302430
// compile those archive members by adding them to the link beforehand.
2431-
if (!ctx.bitcodeFileInstances.empty())
2432-
for (auto *s : lto::LTO::getRuntimeLibcallSymbols())
2431+
if (!ctx.bitcodeFileInstances.empty()) {
2432+
llvm::Triple TT(
2433+
ctx.bitcodeFileInstances.front()->obj->getTargetTriple());
2434+
for (auto *s : lto::LTO::getRuntimeLibcallSymbols(TT))
24332435
ctx.symtab.addLibcall(s);
2436+
}
24342437

24352438
// Windows specific -- if __load_config_used can be resolved, resolve it.
24362439
if (ctx.symtab.findUnderscore("_load_config_used"))

lld/ELF/Driver.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2883,9 +2883,11 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &args) {
28832883
// to, i.e. if the symbol's definition is in bitcode. Any other required
28842884
// libcall symbols will be added to the link after LTO when we add the LTO
28852885
// object file to the link.
2886-
if (!ctx.bitcodeFiles.empty())
2887-
for (auto *s : lto::LTO::getRuntimeLibcallSymbols())
2886+
if (!ctx.bitcodeFiles.empty()) {
2887+
llvm::Triple TT(ctx.bitcodeFiles.front()->obj->getTargetTriple());
2888+
for (auto *s : lto::LTO::getRuntimeLibcallSymbols(TT))
28882889
handleLibcall(s);
2890+
}
28892891

28902892
// Archive members defining __wrap symbols may be extracted.
28912893
std::vector<WrappedSymbol> wrapped = addWrappedSymbols(args);

lld/wasm/Driver.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,9 +1319,11 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
13191319
// We only need to add libcall symbols to the link before LTO if the symbol's
13201320
// definition is in bitcode. Any other required libcall symbols will be added
13211321
// to the link after LTO when we add the LTO object file to the link.
1322-
if (!ctx.bitcodeFiles.empty())
1323-
for (auto *s : lto::LTO::getRuntimeLibcallSymbols())
1322+
if (!ctx.bitcodeFiles.empty()) {
1323+
llvm::Triple TT(ctx.bitcodeFiles.front()->obj->getTargetTriple());
1324+
for (auto *s : lto::LTO::getRuntimeLibcallSymbols(TT))
13241325
handleLibcall(s);
1326+
}
13251327
if (errorCount())
13261328
return;
13271329

0 commit comments

Comments
 (0)