[LLD][ELF] Add FORCE_LLD_DIAGNOSTICS_CRASH to force LLD to crash

Add FORCE_LLD_DIAGNOSTICS_CRASH inspired by the existing
FORCE_CLANG_DIAGNOSTICS_CRASH.

This is particularly useful for people customizing LLD as they may
want to modify the crash reporting behavior.

Differential Revision: https://reviews.llvm.org/D128195
This commit is contained in:
Ben Dunbobbin 2022-07-01 16:45:09 +01:00
parent 774fc63490
commit dfb77f2e99
5 changed files with 22 additions and 0 deletions

View File

@ -29,6 +29,8 @@ ELF Improvements
* ``-z pack-relative-relocs`` is now available to support ``DT_RELR`` for glibc 2.36+.
(`D120701 <https://reviews.llvm.org/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 <https://reviews.llvm.org/D128195>`_)
Breaking changes
----------------

View File

@ -0,0 +1,10 @@
# REQUIRES: backtrace
## Test the diagnostics produced when LLD crashes.
# RUN: env 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:

View File

@ -104,6 +104,9 @@ if (lit.util.which('cvtres', config.environment['PATH']) or
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')

View File

@ -10,6 +10,7 @@ config.llvm_libs_dir = lit_config.substitute("@LLVM_LIBS_DIR@")
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@")

View File

@ -214,6 +214,12 @@ int main(int argc, const char **argv) {
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())