diff --git a/llvm/tools/gold/CMakeLists.txt b/llvm/tools/gold/CMakeLists.txt --- a/llvm/tools/gold/CMakeLists.txt +++ b/llvm/tools/gold/CMakeLists.txt @@ -13,6 +13,9 @@ add_llvm_library(LLVMgold MODULE gold-plugin.cpp + + ENABLE_PLUGINS ) + export_executable_symbols_for_plugins(LLVMgold) endif() diff --git a/llvm/tools/gold/gold-plugin.cpp b/llvm/tools/gold/gold-plugin.cpp --- a/llvm/tools/gold/gold-plugin.cpp +++ b/llvm/tools/gold/gold-plugin.cpp @@ -23,6 +23,7 @@ #include "llvm/Object/Error.h" #include "llvm/Support/CachePruning.h" #include "llvm/Support/CommandLine.h" +#include "llvm/Support/DynamicLibrary.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/MemoryBuffer.h" @@ -207,6 +208,8 @@ static std::string stats_file; // Asserts that LTO link has whole program visibility static bool whole_program_visibility = false; + // List of new PM pass plugins + static std::vector pass_plugins; // Optimization remarks filename, accepted passes and hotness options static std::string RemarksFilename; @@ -306,6 +309,14 @@ RemarksFormat = std::string(opt.substr(strlen("opt-remarks-format="))); } else if (opt.startswith("stats-file=")) { stats_file = std::string(opt.substr(strlen("stats-file="))); + } else if (opt.startswith("load=")) { + std::string Error, Path(opt.substr(strlen("load="))); + + if (sys::DynamicLibrary::LoadLibraryPermanently(Path.c_str(), &Error)) + message(LDPL_ERROR, "Unable to load plugin: %s", Error.c_str()); + } else if (opt.startswith("load-pass-plugin=")) { + pass_plugins.push_back( + std::string(opt.substr(strlen("load-pass-plugin=")))); } else { // Save this option to pass to the code generator. // ParseCommandLineOptions() expects argv[0] to be program name. Lazily @@ -941,6 +952,8 @@ Conf.UseNewPM = options::new_pass_manager; // Debug new pass manager if requested Conf.DebugPassManager = options::debug_pass_manager; + // Pass plugins to load + Conf.PassPlugins = std::move(options::pass_plugins); Conf.HasWholeProgramVisibility = options::whole_program_visibility;