Index: lld/Common/ErrorHandler.cpp =================================================================== --- lld/Common/ErrorHandler.cpp +++ lld/Common/ErrorHandler.cpp @@ -14,6 +14,7 @@ #include "llvm/IR/DiagnosticInfo.h" #include "llvm/IR/DiagnosticPrinter.h" #include "llvm/Support/ManagedStatic.h" +#include "llvm/Support/Program.h" #include "llvm/Support/raw_ostream.h" #include #include @@ -216,6 +217,22 @@ exitLld(1); } +void ErrorHandler::error(const Twine &msg, ArrayRef Args) { + error(msg); + assert(Args.size() >= 2 && "Invalid error format"); +#ifndef NDEBUG + static const char *SupportedTags[] = {"missing-lib"}; +#endif + assert((std::find(std::begin(SupportedTags), std::end(SupportedTags), + Args[1]) != std::end(SupportedTags)) && + "Unsupported error tag"); + if (Args[0].empty()) + return; + int Res = llvm::sys::ExecuteAndWait(Args[0], Args); + if (Res < 0) + error("failed to call error handling script: " + Args[0]); +} + void ErrorHandler::fatal(const Twine &msg) { error(msg); exitLld(1); 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 @@ -277,8 +277,10 @@ void LinkerDriver::addLibrary(StringRef name) { if (Optional path = searchLibrary(name)) addFile(*path, /*withLOption=*/true); - else - error("unable to find library -l" + name); + else { + error("unable to find library -l" + name, + {config->errorHandlingScript, "missing-lib", name}); + } } // This function is called on startup. We need this for LTO since @@ -936,6 +938,8 @@ config->enableNewDtags = args.hasFlag(OPT_enable_new_dtags, OPT_disable_new_dtags, true); config->entry = args.getLastArgValue(OPT_entry); + config->errorHandlingScript = args.getLastArgValue(OPT_error_handling_script); + config->executeOnly = args.hasFlag(OPT_execute_only, OPT_no_execute_only, false); config->exportDynamic = 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: EEq<"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", Index: lld/include/lld/Common/ErrorHandler.h =================================================================== --- lld/include/lld/Common/ErrorHandler.h +++ lld/include/lld/Common/ErrorHandler.h @@ -101,6 +101,7 @@ bool vsDiagnostics = false; void error(const Twine &msg); + void error(const Twine &msg, ArrayRef); LLVM_ATTRIBUTE_NORETURN void fatal(const Twine &msg); void log(const Twine &msg); void message(const Twine &msg); @@ -118,6 +119,9 @@ ErrorHandler &errorHandler(); inline void error(const Twine &msg) { errorHandler().error(msg); } +inline void error(const Twine &msg, ArrayRef args) { + errorHandler().error(msg, args); +} inline LLVM_ATTRIBUTE_NORETURN void fatal(const Twine &msg) { errorHandler().fatal(msg); }