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("undefined-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/ld.lld.1 =================================================================== --- lld/docs/ld.lld.1 +++ lld/docs/ld.lld.1 @@ -184,15 +184,15 @@ .It Fl -error-handing-script Ns = Ns Ar script_path Call script .Ar script_path -when failing to find a library, with +upon some error, with .Ar tag -as first argument, and the name of the missing library as second argument. -The script is expected to return 0 on success, 1 if -.Ar tag -is not supported. Any other value is considered a generic error. +as first argument, and an extra parameter as second argument. The script is expected to return 0 on success, any other value is considered a generic error. .Ar tag may be -.Cm missing-lib. +.Cm missing-lib +followed by the name of the missing library, or +.Cm undefined-symbol +followed by the name of the undefined symbol. .It Fl -execute-only Mark executable sections unreadable. This option is currently only supported on AArch64. 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 @@ -6,10 +6,21 @@ # 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 +# 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-C %s + +# RUN: echo 'bar: movl _Z1av(%rip), %eax' | llvm-mc -filetype=obj -triple=x86_64-unknown-linux - -o %t1.o +# RUN: not ld.lld -o /dev/null --demangle --error-handling-script=%s %t1.o 2>&1 | FileCheck --check-prefix=CHECK-SYM-CXX-DEMANGLE %s +# RUN: not ld.lld -o /dev/null --no-demangle --error-handling-script=%s %t1.o 2>&1 | FileCheck --check-prefix=CHECK-SYM-CXX-NO-DEMANGLE %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-C: script: info: called with undefined-symbol a +# CHECK-SYM-CXX-DEMANGLE: script: info: called with undefined-symbol a +# CHECK-SYM-CXX-NO-DEMANGLE: script: info: called with undefined-symbol _Z1av + echo "script: info: called with $*"