diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp --- a/lld/COFF/Driver.cpp +++ b/lld/COFF/Driver.cpp @@ -27,6 +27,7 @@ #include "llvm/ADT/Optional.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/BinaryFormat/Magic.h" +#include "llvm/LTO/LTO.h" #include "llvm/Object/ArchiveWriter.h" #include "llvm/Object/COFFImportFile.h" #include "llvm/Object/COFFModuleDefinition.h" @@ -1070,12 +1071,6 @@ }); } -static const char *libcallRoutineNames[] = { -#define HANDLE_LIBCALL(code, name) name, -#include "llvm/IR/RuntimeLibcalls.def" -#undef HANDLE_LIBCALL -}; - void LinkerDriver::link(ArrayRef argsArr) { // Needed for LTO. InitializeAllTargetInfos(); @@ -1804,7 +1799,7 @@ // 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. if (!BitcodeFile::instances.empty()) - for (const char *s : libcallRoutineNames) + for (auto *s : lto::LTO::getRuntimeLibcallSymbols()) symtab->addLibcall(s); // Windows specific -- if __load_config_used can be resolved, resolve it. diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -48,6 +48,7 @@ #include "llvm/ADT/SetVector.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringSwitch.h" +#include "llvm/LTO/LTO.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Compression.h" #include "llvm/Support/GlobPattern.h" @@ -1668,12 +1669,6 @@ return ret; } -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 void LinkerDriver::link(opt::InputArgList &args) { @@ -1764,7 +1759,7 @@ // libcall symbols will be added to the link after LTO when we add the LTO // object file to the link. if (!bitcodeFiles.empty()) - for (const char *s : libcallRoutineNames) + for (auto *s : lto::LTO::getRuntimeLibcallSymbols()) handleLibcall(s); // Return if there were name resolution errors. diff --git a/llvm/include/llvm-c/lto.h b/llvm/include/llvm-c/lto.h --- a/llvm/include/llvm-c/lto.h +++ b/llvm/include/llvm-c/lto.h @@ -44,7 +44,7 @@ * @{ */ -#define LTO_API_VERSION 24 +#define LTO_API_VERSION 25 /** * \since prior to LTO_API_VERSION=3 @@ -592,6 +592,14 @@ size_t index, size_t *size); +/** + * Returns the list of libcall symbols that can be generated by LTO + * that might not be visible from the symbol table of bitcode files. + * + * \since prior to LTO_API_VERSION=25 + */ +extern const char *const *lto_runtime_lib_symbols_list(size_t *size); + /** * @} // endgoup LLVMCLTO * @defgroup LLVMCTLTO ThinLTO diff --git a/llvm/include/llvm/LTO/LTO.h b/llvm/include/llvm/LTO/LTO.h --- a/llvm/include/llvm/LTO/LTO.h +++ b/llvm/include/llvm/LTO/LTO.h @@ -298,6 +298,10 @@ /// Cache) for each task identifier. Error run(AddStreamFn AddStream, NativeObjectCache Cache = nullptr); + /// Static method that returns a list of libcall symbols that can be generated + /// by LTO but might not be visible from bitcode symbol table. + static ArrayRef getRuntimeLibcallSymbols(); + private: Config Conf; diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp --- a/llvm/lib/LTO/LTO.cpp +++ b/llvm/lib/LTO/LTO.cpp @@ -1011,6 +1011,16 @@ std::move(RegularLTO.CombinedModule), ThinLTO.CombinedIndex); } +static const char *libcallRoutineNames[] = { +#define HANDLE_LIBCALL(code, name) name, +#include "llvm/IR/RuntimeLibcalls.def" +#undef HANDLE_LIBCALL +}; + +ArrayRef LTO::getRuntimeLibcallSymbols() { + return makeArrayRef(libcallRoutineNames); +} + /// This class defines the interface to the ThinLTO backend. class lto::ThinBackendProc { protected: diff --git a/llvm/tools/lto/lto.cpp b/llvm/tools/lto/lto.cpp --- a/llvm/tools/lto/lto.cpp +++ b/llvm/tools/lto/lto.cpp @@ -652,3 +652,9 @@ size_t *size) { return LTOModule::getDependentLibrary(unwrap(input), index, size); } + +extern const char *const *lto_runtime_lib_symbols_list(size_t *size) { + auto symbols = lto::LTO::getRuntimeLibcallSymbols(); + *size = symbols.size(); + return symbols.data(); +} diff --git a/llvm/tools/lto/lto.exports b/llvm/tools/lto/lto.exports --- a/llvm/tools/lto/lto.exports +++ b/llvm/tools/lto/lto.exports @@ -76,3 +76,4 @@ lto_input_dispose lto_input_get_num_dependent_libraries lto_input_get_dependent_library +lto_runtime_lib_symbols_list