Index: include/llvm/LTO/LTO.h =================================================================== --- include/llvm/LTO/LTO.h +++ include/llvm/LTO/LTO.h @@ -82,6 +82,7 @@ // FIXME: Remove the LLVMContext once we have bitcode symbol tables. LLVMContext Ctx; struct InputModule; + std::string LinkerOpts; std::vector Mods; ModuleSymbolTable SymTab; @@ -220,6 +221,9 @@ symbol_iterator(SymTab.symbols().end(), SymTab, this)); } + /// Returns linker options specified in the input file. + StringRef getLinkerOpts() const; + /// Returns the path to the InputFile. StringRef getName() const; Index: lib/LTO/LTO.cpp =================================================================== --- lib/LTO/LTO.cpp +++ lib/LTO/LTO.cpp @@ -20,6 +20,7 @@ #include "llvm/IR/AutoUpgrade.h" #include "llvm/IR/DiagnosticPrinter.h" #include "llvm/IR/LegacyPassManager.h" +#include "llvm/IR/Metadata.h" #include "llvm/LTO/LTOBackend.h" #include "llvm/Linker/IRMover.h" #include "llvm/Object/ModuleSummaryIndexObjectFile.h" @@ -248,9 +249,10 @@ // Create an InputModule for each module in the InputFile, and add it to the // ModuleSymbolTable. + raw_string_ostream LOS(File->LinkerOpts); for (auto BM : *BMsOrErr) { Expected> MOrErr = - BM.getLazyModule(File->Ctx, /*ShouldLazyLoadMetadata*/ true, + BM.getLazyModule(File->Ctx, /*ShouldLazyLoadMetadata*/ false, /*IsImporting*/ false); if (!MOrErr) return MOrErr.takeError(); @@ -267,6 +269,19 @@ File->Comdats.push_back(C.first()); } + // Extract linker options. + if (Metadata *Val = (*MOrErr)->getModuleFlag("Linker Options")) { + MDNode *LinkerOptions = cast(Val); + for (unsigned i = 0, e = LinkerOptions->getNumOperands(); i != e; ++i) { + MDNode *MDOptions = cast(LinkerOptions->getOperand(i)); + for (unsigned ii = 0, ie = MDOptions->getNumOperands(); ii != ie; + ++ii) { + MDString *MDOption = cast(MDOptions->getOperand(ii)); + LOS << " " << MDOption->getString(); + } + } + } + File->Mods.push_back({BM, std::move(*MOrErr), SymBegin, SymEnd}); } @@ -288,6 +303,8 @@ return -1; } +StringRef InputFile::getLinkerOpts() const { return LinkerOpts; } + StringRef InputFile::getName() const { return Mods[0].BM.getModuleIdentifier(); }