Index: lld/ELF/Driver.cpp =================================================================== --- lld/ELF/Driver.cpp +++ lld/ELF/Driver.cpp @@ -510,6 +510,12 @@ ELFOptTable parser; opt::InputArgList args = parser.parse(argsArr.slice(1)); + + if (::getenv("FORCE_LLD_DIAGNOSTICS_CRASH")) { + message ("Crashing due to environment variable FORCE_LLD_DIAGNOSTICS_CRASH"); + LLVM_BUILTIN_TRAP; + } + // Interpret these flags early because error()/warn() depend on them. errorHandler().errorLimit = args::getInteger(args, OPT_error_limit, 20); errorHandler().fatalWarnings = Index: lld/test/ELF/crash-report.test =================================================================== --- /dev/null +++ lld/test/ELF/crash-report.test @@ -0,0 +1,9 @@ +//// Test the diagnostics produced when LLD crashes. + +//// Unset LLD_IN_TEST as its engages a crash recovery context. +// RUN: env -u LLD_IN_TEST FORCE_LLD_DIAGNOSTICS_CRASH=1 not --crash ld.lld -o /dev/null 2>&1 | FileCheck %s + +//// Check the crash text has the correct structure. +// CHECK: Crashing due to environment variable FORCE_LLD_DIAGNOSTICS_CRASH +// CHECK: PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace. +// CHECK: Stack dump: