Index: lld/Common/ErrorHandler.cpp =================================================================== --- lld/Common/ErrorHandler.cpp +++ lld/Common/ErrorHandler.cpp @@ -239,6 +239,9 @@ case ErrorTag::LibNotFound: scriptArgs.push_back("missing-lib"); break; + case ErrorTag::SymbolNotFound: + scriptArgs.push_back("missing-symbol"); + break; default: llvm_unreachable("unsupported ErrorTag"); } Index: lld/ELF/Relocations.cpp =================================================================== --- lld/ELF/Relocations.cpp +++ lld/ELF/Relocations.cpp @@ -919,7 +919,7 @@ if (undef.isWarning) warn(msg); else - error(msg); + error(msg, ErrorTag::SymbolNotFound, {toString(sym)}); } template void elf::reportUndefinedSymbols() { Index: lld/docs/error_handling_script.rst =================================================================== --- lld/docs/error_handling_script.rst +++ lld/docs/error_handling_script.rst @@ -25,7 +25,11 @@ :``missing-lib``: indicates that LLD failed to find a library. The library name is specified as - the first argument, e.g. ``error-handling-script missing-lib mylib`` + the second argument, e.g. ``error-handling-script missing-lib mylib`` + +:``missing-symbol``: + indicates that LLD failed to find the given symbol. The symbol name is specified as + the second argument, e.g. ``error-handling-script missing-symbol dlopen`` Return Value ============ Index: lld/include/lld/Common/ErrorHandler.h =================================================================== --- lld/include/lld/Common/ErrorHandler.h +++ lld/include/lld/Common/ErrorHandler.h @@ -89,7 +89,7 @@ llvm::raw_ostream &outs(); llvm::raw_ostream &errs(); -enum class ErrorTag { LibNotFound }; +enum class ErrorTag { LibNotFound, SymbolNotFound }; class ErrorHandler { public: Index: lld/test/ELF/error-handling-script-linux.test =================================================================== --- lld/test/ELF/error-handling-script-linux.test +++ lld/test/ELF/error-handling-script-linux.test @@ -1,14 +1,20 @@ #!/bin/sh # REQUIRES: x86 # UNSUPPORTED: system-windows -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux /dev/null -o %t.o -# RUN: not ld.lld -o /dev/null -lidontexist --error-handling-script=%s %t.o 2>&1 | FileCheck --check-prefix=CHECK-NORMAL %s -# RUN: not ld.lld -o /dev/null -lidontexist --error-handling-script=%s.nope %t.o 2>&1 | FileCheck --check-prefix=CHECK-DOES-NOT-EXIST %s -# CHECK-NORMAL: script: info: called with missing-lib idontexist -# CHECK-NORMAL-NEXT: ld.lld: error: unable to find library -lidontexist +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux /dev/null -o %t0.o +# RUN: not ld.lld -o /dev/null -lidontexist --error-handling-script=%s %t0.o 2>&1 | FileCheck --check-prefix=CHECK-LIB %s +# RUN: not ld.lld -o /dev/null -lidontexist --error-handling-script=%s.nope %t0.o 2>&1 | FileCheck --check-prefix=CHECK-SCRIPT-DOES-NOT-EXIST %s -# CHECK-DOES-NOT-EXIST: ld.lld: error: unable to find library -lidontexist -# CHECK-DOES-NOT-EXIST-NEXT: '{{.*}}': error handling script failed to execute +# RUN: echo 'bar: movl a(%rip), %eax' | llvm-mc -filetype=obj -triple=x86_64-unknown-linux - -o %t1.o +# RUN: not ld.lld -o /dev/null --error-handling-script=%s %t1.o 2>&1 | FileCheck --check-prefix=CHECK-SYM %s + +# CHECK-LIB: script: info: called with missing-lib idontexist +# CHECK-LIB-NEXT: ld.lld: error: unable to find library -lidontexist + +# CHECK-SCRIPT-DOES-NOT-EXIST: ld.lld: error: unable to find library -lidontexist +# CHECK-SCRIPT-DOES-NOT-EXIST-NEXT: '{{.*}}': error handling script failed to execute + +# CHECK-SYM: script: info: called with missing-symbol a echo "script: info: called with $*"