Index: lld/ELF/Config.h =================================================================== --- lld/ELF/Config.h +++ lld/ELF/Config.h @@ -144,6 +144,7 @@ std::vector undefined; std::vector dynamicList; std::vector buildIdVector; + std::vector PassPlugins; llvm::MapVector, uint64_t> callGraphProfile; Index: lld/ELF/Driver.cpp =================================================================== --- lld/ELF/Driver.cpp +++ lld/ELF/Driver.cpp @@ -1252,6 +1252,8 @@ error(arg->getSpelling() + ": unknown plugin option '" + arg->getValue() + "'"); + config->PassPlugins = args::getStrings(args, OPT_load_pass_plugins); + // Parse -mllvm options. for (auto *arg : args.filtered(OPT_mllvm)) parseClangOption(arg->getValue(), arg->getSpelling()); Index: lld/ELF/LTO.cpp =================================================================== --- lld/ELF/LTO.cpp +++ lld/ELF/LTO.cpp @@ -144,6 +144,8 @@ c.SampleProfile = std::string(config->ltoSampleProfile); c.UseNewPM = config->ltoNewPassManager; + for (llvm::StringRef &PluginFN : config->PassPlugins) + c.PassPlugins.push_back(std::string(PluginFN)); c.DebugPassManager = config->ltoDebugPassManager; c.DwoDir = std::string(config->dwoDir); Index: lld/ELF/Options.td =================================================================== --- lld/ELF/Options.td +++ lld/ELF/Options.td @@ -714,3 +714,5 @@ "Perform additional validation of the written dynamic relocations", "Do not perform additional validation of the written dynamic relocations">, Flags<[HelpHidden]>; + +defm load_pass_plugins: Eq<"load-pass-plugin", "Load passes from plugin library">; Index: llvm/examples/Bye/Bye.cpp =================================================================== --- llvm/examples/Bye/Bye.cpp +++ llvm/examples/Bye/Bye.cpp @@ -50,6 +50,11 @@ [](const llvm::PassManagerBuilder &Builder, llvm::legacy::PassManagerBase &PM) { PM.add(new LegacyBye()); }); +static llvm::RegisterStandardPasses RegisterByeLTO( + llvm::PassManagerBuilder::EP_ModuleOptimizerEarly, + [](const llvm::PassManagerBuilder &Builder, + llvm::legacy::PassManagerBase &PM) { PM.add(new LegacyBye()); }); + /* New PM Registration */ llvm::PassPluginLibraryInfo getByePluginInfo() { return {LLVM_PLUGIN_API_VERSION, "Bye", LLVM_VERSION_STRING, Index: llvm/test/Feature/load_extension.ll =================================================================== --- llvm/test/Feature/load_extension.ll +++ llvm/test/Feature/load_extension.ll @@ -5,6 +5,8 @@ ; RUN: llvm-lto2 run %t.o %loadbye -wave-goodbye -use-new-pm=0 -o %t -r %t.o,somefunk,plx -r %t.o,junk,plx 2>&1 | FileCheck %s ; RUN: llvm-lto2 run %t.o %loadbye %loadnewpmbye -wave-goodbye -use-new-pm -o %t -r %t.o,somefunk,plx -r %t.o,junk,plx 2>&1 | FileCheck %s ; RUN: llvm-lto2 run %t.o %loadbye %loadnewpmbye -opt-pipeline="goodbye" -wave-goodbye -use-new-pm -o %t -r %t.o,somefunk,plx -r %t.o,junk,plx 2>&1 | FileCheck %s +; RUN: ld.lld -%loadnewpmbye --lto-newpm-passes="goodbye" -mllvm=%loadbye -mllvm=-wave-goodbye %t.o 2>&1 | FileCheck %s +; RUN: ld.lld -mllvm=%loadbye -mllvm=-wave-goodbye -plugin-opt=legacy-pass-manager %t.o 2>&1 | FileCheck %s ; REQUIRES: plugins, examples ; UNSUPPORTED: windows ; CHECK: Bye