diff options
author | Ben Dunbobbin <bd1976llvm@gmail.com> | 2019-06-12 11:07:56 +0000 |
---|---|---|
committer | Ben Dunbobbin <bd1976llvm@gmail.com> | 2019-06-12 11:07:56 +0000 |
commit | 564d248ec2f2a1dc0245ee7942a32fb72e7e1c84 (patch) | |
tree | f776b3fa7eab5f6e645330164488d7a08a61128c /llvm/tools/llvm-lto/llvm-lto.cpp | |
parent | f6efac67e18c5ea66305b2cbc561705eab4ee776 (diff) | |
download | bcm5719-llvm-564d248ec2f2a1dc0245ee7942a32fb72e7e1c84.tar.gz bcm5719-llvm-564d248ec2f2a1dc0245ee7942a32fb72e7e1c84.zip |
[ThinLTO]LTO]Legacy] Fix dependent libraries support by adding querying of the IRSymtab
Dependent libraries support for the legacy api was committed in a
broken state (see: https://reviews.llvm.org/D60274). This was missed
due to the painful nature of having to integrate the changes into a
linker in order to test. This change implements support for dependent
libraries in the legacy LTO api:
- I have removed the current api function, which returns a single
string, and added functions to access each dependent library
specifier individually.
- To reduce the testing pain, I have made the api functions as thin as
possible to maximize coverage from llvm-lto.
- When doing ThinLTO the system linker will load the modules lazily
when scanning the input files. Unfortunately, when modules are
lazily loaded there is no access to module level named metadata. To
fix this I have added api functions that allow querying the IRSymtab
for the dependent libraries. I hope to expand the api in the future
so that, eventually, all the information needed by a client linker
during scan can be retrieved from the IRSymtab.
Differential Revision: https://reviews.llvm.org/D62935
llvm-svn: 363140
Diffstat (limited to 'llvm/tools/llvm-lto/llvm-lto.cpp')
-rw-r--r-- | llvm/tools/llvm-lto/llvm-lto.cpp | 43 |
1 files changed, 37 insertions, 6 deletions
diff --git a/llvm/tools/llvm-lto/llvm-lto.cpp b/llvm/tools/llvm-lto/llvm-lto.cpp index 9aabe0a4282..585207b2518 100644 --- a/llvm/tools/llvm-lto/llvm-lto.cpp +++ b/llvm/tools/llvm-lto/llvm-lto.cpp @@ -204,6 +204,10 @@ static cl::opt<bool> ListSymbolsOnly( "list-symbols-only", cl::init(false), cl::desc("Instead of running LTO, list the symbols in each IR file")); +static cl::opt<bool> ListDependentLibrariesOnly( + "list-dependent-libraries-only", cl::init(false), + cl::desc("Instead of running LTO, list the dependent libraries in each IR file")); + static cl::opt<bool> SetMergedModule( "set-merged-module", cl::init(false), cl::desc("Use the first input module as the merged module")); @@ -372,6 +376,34 @@ static void listSymbols(const TargetOptions &Options) { } } +static std::unique_ptr<MemoryBuffer> loadFile(StringRef Filename) { + ExitOnError ExitOnErr("llvm-lto: error loading file '" + Filename.str() + + "': "); + return ExitOnErr(errorOrToExpected(MemoryBuffer::getFileOrSTDIN(Filename))); +} + +static void listDependentLibraries() { + for (auto &Filename : InputFilenames) { + auto Buffer = loadFile(Filename); + std::string E; + std::unique_ptr<lto::InputFile> Input(LTOModule::createInputFile( + Buffer->getBufferStart(), Buffer->getBufferSize(), Filename.c_str(), + E)); + if (!Input) + error(E); + + // List the dependent libraries. + outs() << Filename << ":\n"; + for (size_t I = 0, C = LTOModule::getDependentLibraryCount(Input.get()); + I != C; ++I) { + size_t L = 0; + const char *S = LTOModule::getDependentLibrary(Input.get(), I, &L); + assert(S); + outs() << StringRef(S, L) << "\n"; + } + } +} + /// Create a combined index file from the input IR files and write it. /// /// This is meant to enable testing of ThinLTO combined index generation, @@ -449,12 +481,6 @@ std::unique_ptr<ModuleSummaryIndex> loadCombinedIndex() { return ExitOnErr(getModuleSummaryIndexForFile(ThinLTOIndex)); } -static std::unique_ptr<MemoryBuffer> loadFile(StringRef Filename) { - ExitOnError ExitOnErr("llvm-lto: error loading file '" + Filename.str() + - "': "); - return ExitOnErr(errorOrToExpected(MemoryBuffer::getFileOrSTDIN(Filename))); -} - static std::unique_ptr<lto::InputFile> loadInputFile(MemoryBufferRef Buffer) { ExitOnError ExitOnErr("llvm-lto: error loading input '" + Buffer.getBufferIdentifier().str() + "': "); @@ -854,6 +880,11 @@ int main(int argc, char **argv) { return 0; } + if (ListDependentLibrariesOnly) { + listDependentLibraries(); + return 0; + } + if (IndexStats) { printIndexStats(); return 0; |