diff options
author | serge-sans-paille <sguelton@redhat.com> | 2020-10-19 13:19:52 +0200 |
---|---|---|
committer | serge-sans-paille <sguelton@redhat.com> | 2020-11-03 11:01:29 +0100 |
commit | cfc32267e27f77211ee5eb6e30c52ab2c7740e6e (patch) | |
tree | 54ae7faabdeb831bf136f040b7efe659aac6ccf0 /lld/Common | |
parent | 90131e3ecb753c38cc99e060aa69ca1766d96432 (diff) | |
download | llvm-cfc32267e27f77211ee5eb6e30c52ab2c7740e6e.tar.gz |
Provide a hook to customize missing library error handling
Make it possible for lld users to provide a custom script that would help to
find missing libraries. A possible scenario could be:
% clang /tmp/a.c -fuse-ld=lld -loauth -Wl,--error-handling-script=/tmp/addLibrary.py
unable to find library -loauth
looking for relevant packages to provides that library
liboauth-0.9.7-4.el7.i686
liboauth-devel-0.9.7-4.el7.i686
liboauth-0.9.7-4.el7.x86_64
liboauth-devel-0.9.7-4.el7.x86_64
pix-1.6.1-3.el7.x86_64
Where addLibrary would be called with the missing library name as first argument
(in that case addLibrary.py oauth)
Differential Revision: https://reviews.llvm.org/D87758
Diffstat (limited to 'lld/Common')
-rw-r--r-- | lld/Common/ErrorHandler.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/lld/Common/ErrorHandler.cpp b/lld/Common/ErrorHandler.cpp index 3c3609e00743..4d6a039b8959 100644 --- a/lld/Common/ErrorHandler.cpp +++ b/lld/Common/ErrorHandler.cpp @@ -16,6 +16,7 @@ #include "llvm/Support/CrashRecoveryContext.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/Process.h" +#include "llvm/Support/Program.h" #include "llvm/Support/raw_ostream.h" #include <mutex> #include <regex> @@ -226,6 +227,50 @@ void ErrorHandler::error(const Twine &msg) { exitLld(1); } +void ErrorHandler::error(const Twine &msg, ErrorTag tag, + ArrayRef<StringRef> args) { + if (errorHandlingScript.empty()) { + error(msg); + return; + } + SmallVector<StringRef, 4> scriptArgs; + scriptArgs.push_back(errorHandlingScript); + switch (tag) { + case ErrorTag::LibNotFound: + scriptArgs.push_back("missing-lib"); + break; + default: + llvm_unreachable("unsupported ErrorTag"); + } + scriptArgs.insert(scriptArgs.end(), args.begin(), args.end()); + int res = llvm::sys::ExecuteAndWait(errorHandlingScript, scriptArgs); + if (res == 0) { + return error(msg); + } else { + // Temporarily disable error limit to make sure the two calls to error(...) + // only count as one. + uint64_t currentErrorLimit = errorLimit; + errorLimit = 0; + error(msg); + errorLimit = currentErrorLimit; + --errorCount; + + switch (res) { + case -1: + error("error handling script '" + errorHandlingScript + + "' failed to execute"); + break; + case -2: + error("error handling script '" + errorHandlingScript + + "' crashed or timeout"); + break; + default: + error("error handling script '" + errorHandlingScript + + "' exited with code " + Twine(res)); + } + } +} + void ErrorHandler::fatal(const Twine &msg) { error(msg); exitLld(1); |