Index: lld/docs/ReleaseNotes.rst =================================================================== --- lld/docs/ReleaseNotes.rst +++ lld/docs/ReleaseNotes.rst @@ -29,6 +29,7 @@ * ``-z pack-relative-relocs`` is now available to support ``DT_RELR`` for glibc 2.36+. (`D120701 `_) * ``--no-fortran-common`` (pre 12.0.0 behavior) is now the default. +* ``FORCE_LLD_DIAGNOSTICS_CRASH`` environment variable is now available to force LLD to crash. Breaking changes ---------------- 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 it 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: Index: lld/tools/lld/lld.cpp =================================================================== --- lld/tools/lld/lld.cpp +++ lld/tools/lld/lld.cpp @@ -214,6 +214,12 @@ InitLLVM x(argc, argv); sys::Process::UseANSIEscapeCodes(true); + if (::getenv("FORCE_LLD_DIAGNOSTICS_CRASH")) { + llvm::errs() + << "crashing due to environment variable FORCE_LLD_DIAGNOSTICS_CRASH\n"; + LLVM_BUILTIN_TRAP; + } + // Not running in lit tests, just take the shortest codepath with global // exception handling and no memory cleanup on exit. if (!inTestVerbosity())