Index: lld/ELF/Driver.cpp =================================================================== --- lld/ELF/Driver.cpp +++ lld/ELF/Driver.cpp @@ -347,7 +347,7 @@ if (Args.hasArg(OPT_version)) return; - Config->ExitEarly = CanExitEarly && !Args.hasArg(OPT_full_shutdown); + Config->ExitEarly = CanExitEarly && !Args.hasArg(OPT_no_full_shutdown); errorHandler().ExitEarly = Config->ExitEarly; if (const char *Path = getReproduceOption(Args)) { Index: lld/ELF/Options.td =================================================================== --- lld/ELF/Options.td +++ lld/ELF/Options.td @@ -144,9 +144,6 @@ def fix_cortex_a53_843419: F<"fix-cortex-a53-843419">, HelpText<"Apply fixes for AArch64 Cortex-A53 erratum 843419">; -def full_shutdown : F<"full-shutdown">, Flags<[HelpHidden]>, - HelpText<"Perform a full shutdown instead of calling _exit">; - defm format: Eq<"format">, HelpText<"Change the input format of the inputs following this option">, MetaVarName<"">; @@ -206,6 +203,9 @@ def no_dynamic_linker: F<"no-dynamic-linker">, HelpText<"Inhibit output of .interp section">; +def no_full_shutdown : F<"no-full-shutdown">, Flags<[HelpHidden]>, + HelpText<"Do not perform a full shutdown instead of calling _exit">; + def noinhibit_exec: F<"noinhibit-exec">, HelpText<"Retain the executable output file whenever it is still usable">; Index: lld/test/ELF/lto/timepasses.ll =================================================================== --- lld/test/ELF/lto/timepasses.ll +++ lld/test/ELF/lto/timepasses.ll @@ -1,8 +1,7 @@ -; We use lld -flavor gnu because llvm-lit will append --full-shutdown to -; the ld.lld invocation. ; REQUIRES: x86 ; RUN: llvm-as %s -o %t.o -; RUN: lld -flavor gnu %t.o -o %t.so -shared -mllvm -time-passes 2>&1 | FileCheck %s +; RUN: ld.lld --no-full-shutdown %t.o -o %t.so -shared -mllvm \ +; RUN: -time-passes 2>&1 | FileCheck %s target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-unknown-linux-gnu" @@ -11,5 +10,5 @@ ret void } -; We should get the output of -time-passes even when --full-shutdown is not specified. +; We should get the output of -time-passes even when --no-full-shutdown is specified. ; CHECK: Total Execution Time Index: lld/test/lit.cfg.py =================================================================== --- lld/test/lit.cfg.py +++ lld/test/lit.cfg.py @@ -73,6 +73,7 @@ # Set a fake constant version so that we get consitent output. config.environment['LLD_VERSION'] = 'LLD 1.0' +config.environment['LLD_IN_TEST'] = '1' # Indirectly check if the mt.exe Microsoft utility exists by searching for # cvtres, which always accompanies it. Alternatively, check if we can use Index: lld/tools/lld/lld.cpp =================================================================== --- lld/tools/lld/lld.cpp +++ lld/tools/lld/lld.cpp @@ -24,6 +24,7 @@ #include "llvm/Support/Path.h" #include "llvm/Support/PrettyStackTrace.h" #include "llvm/Support/Signals.h" +#include using namespace lld; using namespace llvm; @@ -102,6 +103,14 @@ return parseProgname(Arg0); } +// If this function returns true, lld calls _exit() so that it quickly +// exit without invoking destructors of globally allocated objects. +// +// We don't want to do that if we are running tests though, because +// doing that breaks leak sanitizer. So, lit sets this environment variable, +// and we use it to detect whether we are running test or not. +static bool canExitEarly() { return StringRef(getenv("LLD_IN_TEST")) != "1"; } + /// Universal linker main(). This linker emulates the gnu, darwin, or /// windows linker based on the argv[0] or -flavor option. int main(int Argc, const char **Argv) { @@ -115,13 +124,13 @@ case Gnu: if (isPETarget(Args)) return !mingw::link(Args); - return !elf::link(Args, true); + return !elf::link(Args, canExitEarly()); case WinLink: - return !coff::link(Args, true); + return !coff::link(Args, canExitEarly()); case Darwin: return !mach_o::link(Args); case Wasm: - return !wasm::link(Args, true); + return !wasm::link(Args, canExitEarly()); default: die("lld is a generic driver.\n" "Invoke ld.lld (Unix), ld64.lld (macOS) or lld-link (Windows) instead."); Index: llvm/utils/lit/lit/llvm/config.py =================================================================== --- llvm/utils/lit/lit/llvm/config.py +++ llvm/utils/lit/lit/llvm/config.py @@ -465,9 +465,6 @@ self.with_environment('PATH', tool_dirs, append_path=True) self.with_environment('LD_LIBRARY_PATH', lib_dirs, append_path=True) - self.config.substitutions.append( - (r"\bld.lld\b", 'ld.lld --full-shutdown')) - tool_patterns = ['lld', 'ld.lld', 'lld-link', 'ld64.lld', 'wasm-ld'] self.add_tool_substitutions(tool_patterns, tool_dirs)