Skip to content

Commit 34d8046

Browse files
[LTO][Legacy] Add new C inferface to query libcall functions
Summary: This is needed to implemented the same approach as lld (implemented in r338434) for how to handling symbols that can be generated by LTO code generator but not present in the symbol table for linker that uses legacy C APIs. libLTO is in charge of providing the list of symbols. Linker is in charge of implementing the eager loading from static libraries using the list of symbols. rdar://problem/52853974 Reviewers: tejohnson, bd1976llvm, deadalnix, espindola Reviewed By: tejohnson Subscribers: emaste, arichardson, hiraditya, MaskRay, dang, kledzik, mehdi_amini, inglorion, jkorous, dexonsmith, ributzka, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D67568 llvm-svn: 372021
1 parent 32837a0 commit 34d8046

File tree

5 files changed

+30
-1
lines changed

5 files changed

+30
-1
lines changed

llvm/include/llvm-c/lto.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ typedef bool lto_bool_t;
4444
* @{
4545
*/
4646

47-
#define LTO_API_VERSION 24
47+
#define LTO_API_VERSION 25
4848

4949
/**
5050
* \since prior to LTO_API_VERSION=3
@@ -592,6 +592,14 @@ extern const char * lto_input_get_dependent_library(lto_input_t input,
592592
size_t index,
593593
size_t *size);
594594

595+
/**
596+
* Returns the list of libcall symbols that can be generated by LTO
597+
* that might not be visible from the symbol table of bitcode files.
598+
*
599+
* \since prior to LTO_API_VERSION=25
600+
*/
601+
extern const char *const *lto_runtime_lib_symbols_list(size_t *size);
602+
595603
/**
596604
* @} // endgoup LLVMCLTO
597605
* @defgroup LLVMCTLTO ThinLTO

llvm/include/llvm/LTO/LTO.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,10 @@ class LTO {
298298
/// Cache) for each task identifier.
299299
Error run(AddStreamFn AddStream, NativeObjectCache Cache = nullptr);
300300

301+
/// Static method that returns a list of libcall symbols that can be generated
302+
/// by LTO but might not be visible from bitcode symbol table.
303+
static ArrayRef<const char*> getRuntimeLibcallSymbols();
304+
301305
private:
302306
Config Conf;
303307

llvm/lib/LTO/LTO.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,16 @@ Error LTO::runRegularLTO(AddStreamFn AddStream) {
10111011
std::move(RegularLTO.CombinedModule), ThinLTO.CombinedIndex);
10121012
}
10131013

1014+
static const char *libcallRoutineNames[] = {
1015+
#define HANDLE_LIBCALL(code, name) name,
1016+
#include "llvm/IR/RuntimeLibcalls.def"
1017+
#undef HANDLE_LIBCALL
1018+
};
1019+
1020+
ArrayRef<const char*> LTO::getRuntimeLibcallSymbols() {
1021+
return makeArrayRef(libcallRoutineNames);
1022+
}
1023+
10141024
/// This class defines the interface to the ThinLTO backend.
10151025
class lto::ThinBackendProc {
10161026
protected:

llvm/tools/lto/lto.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,3 +652,9 @@ extern const char *lto_input_get_dependent_library(lto_input_t input,
652652
size_t *size) {
653653
return LTOModule::getDependentLibrary(unwrap(input), index, size);
654654
}
655+
656+
extern const char *const *lto_runtime_lib_symbols_list(size_t *size) {
657+
auto symbols = lto::LTO::getRuntimeLibcallSymbols();
658+
*size = symbols.size();
659+
return symbols.data();
660+
}

llvm/tools/lto/lto.exports

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,4 @@ lto_input_create
7676
lto_input_dispose
7777
lto_input_get_num_dependent_libraries
7878
lto_input_get_dependent_library
79+
lto_runtime_lib_symbols_list

0 commit comments

Comments
 (0)