Index: lld/docs/ReleaseNotes.rst =================================================================== --- lld/docs/ReleaseNotes.rst +++ lld/docs/ReleaseNotes.rst @@ -29,6 +29,8 @@ * ``-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. + (`D128195 `_) Breaking changes ---------------- Index: lld/test/ELF/crash-report.test =================================================================== --- /dev/null +++ lld/test/ELF/crash-report.test @@ -0,0 +1,11 @@ +# REQUIRES: backtrace + +## 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 {{.*}} and include the crash backtrace. +# CHECK: Stack dump: Index: lld/test/lit.cfg.py =================================================================== --- lld/test/lit.cfg.py +++ lld/test/lit.cfg.py @@ -104,6 +104,9 @@ config.have_libxml2): config.available_features.add('manifest_tool') +if config.enable_backtrace: + config.available_features.add('backtrace') + if config.have_libxar: config.available_features.add('xar') Index: lld/test/lit.site.cfg.py.in =================================================================== --- lld/test/lit.site.cfg.py.in +++ lld/test/lit.site.cfg.py.in @@ -10,6 +10,7 @@ config.llvm_shlib_dir = "@SHLIBDIR@" config.llvm_shlib_ext = "@SHLIBEXT@" config.lit_tools_dir = "@LLVM_LIT_TOOLS_DIR@" +config.enable_backtrace = @ENABLE_BACKTRACES@ config.errc_messages = "@LLVM_LIT_ERRC_MESSAGES@" config.lld_obj_root = "@LLD_BINARY_DIR@" config.lld_libs_dir = lit_config.substitute("@CURRENT_LIBS_DIR@") 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())