Index: lld/ELF/Config.h =================================================================== --- lld/ELF/Config.h +++ lld/ELF/Config.h @@ -121,6 +121,7 @@ llvm::StringRef thinLTOCacheDir; llvm::StringRef thinLTOIndexOnlyArg; llvm::StringRef ltoBasicBlockSections; + llvm::StringRef errorHandlingScript; std::pair thinLTOObjectSuffixReplace; std::pair thinLTOPrefixReplace; std::string rpath; Index: lld/ELF/Driver.cpp =================================================================== --- lld/ELF/Driver.cpp +++ lld/ELF/Driver.cpp @@ -54,6 +54,7 @@ #include "llvm/Support/LEB128.h" #include "llvm/Support/Parallel.h" #include "llvm/Support/Path.h" +#include "llvm/Support/Program.h" #include "llvm/Support/TarWriter.h" #include "llvm/Support/TargetSelect.h" #include "llvm/Support/TimeProfiler.h" @@ -277,8 +278,20 @@ void LinkerDriver::addLibrary(StringRef name) { if (Optional path = searchLibrary(name)) addFile(*path, /*withLOption=*/true); - else - error("unable to find library -l" + name); + else { + if (config->errorHandlingScript.empty()) { + error("unable to find library -l" + name); + } else { + int Res = llvm::sys::ExecuteAndWait( + config->errorHandlingScript, + {config->errorHandlingScript, "missing-symbol", name}); + if (Res >= 0) + exitLld(1); + else + error("Failed to call error handling script: " + + config->errorHandlingScript); + } + } } // This function is called on startup. We need this for LTO since @@ -901,6 +914,8 @@ errorHandler().vsDiagnostics = args.hasArg(OPT_visual_studio_diagnostics_format, false); + config->errorHandlingScript = args.getLastArgValue(OPT_error_handling_script); + config->allowMultipleDefinition = args.hasFlag(OPT_allow_multiple_definition, OPT_no_allow_multiple_definition, false) || Index: lld/ELF/Options.td =================================================================== --- lld/ELF/Options.td +++ lld/ELF/Options.td @@ -179,6 +179,10 @@ def error_unresolved_symbols: F<"error-unresolved-symbols">, HelpText<"Report unresolved symbols as errors">; +defm error_handling_script: Eq<"error-handling-script", + "Specify an error handling script">; + + defm exclude_libs: Eq<"exclude-libs", "Exclude static libraries from automatic export">; defm execute_only: BB<"execute-only",