[PATCH] D102684: [LLD] Allow disabling the early exit codepath as a build configuration

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 18 05:35:00 PDT 2021


mstorsjo created this revision.
mstorsjo added reviewers: rnk, MaskRay.
Herald added a subscriber: mgorny.
mstorsjo requested review of this revision.
Herald added a project: LLVM.

In certain cases, the early exit codepath can be brittle and cause
rare deadlocks: On Windows, when exiting bypassing destructors, all
loaded DLLs are still unintiailized normally, running their
destructors. This is known to cause problems if e.g. building with
LLVM_LINK_LLVM_DYLIB (where the destructors within the LLVM Support
threadpool classes are run), and also seems to cause rare (0.05% of
executions) hangs if LLD is linked against libc++ in the form of a DLL.

Alternatively, should we disable the early exit codepath altogether
when running on Windows?


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102684

Files:
  lld/CMakeLists.txt
  lld/tools/lld/lld.cpp


Index: lld/tools/lld/lld.cpp
===================================================================
--- lld/tools/lld/lld.cpp
+++ lld/tools/lld/lld.cpp
@@ -103,6 +103,14 @@
 #endif
 }
 
+static bool useEarlyExit() {
+#ifdef LLD_USE_EARLY_EXIT
+  return true;
+#else
+  return false;
+#endif
+}
+
 static Flavor parseProgname(StringRef progname) {
   // Use GNU driver for "ld" by default.
   if (progname == "ld")
@@ -203,7 +211,7 @@
   // Not running in lit tests, just take the shortest codepath with global
   // exception handling and no memory cleanup on exit.
   if (!inTestVerbosity())
-    return lldMain(argc, argv, llvm::outs(), llvm::errs());
+    return lldMain(argc, argv, llvm::outs(), llvm::errs(), useEarlyExit());
 
   Optional<int> mainRet;
   CrashRecoveryContext::Enable();
Index: lld/CMakeLists.txt
===================================================================
--- lld/CMakeLists.txt
+++ lld/CMakeLists.txt
@@ -172,6 +172,12 @@
   add_definitions("-DLLD_DEFAULT_LD_LLD_IS_MINGW=1")
 endif()
 
+option(LLD_USE_EARLY_EXIT
+    "Use the early exit codepath, bypassing destructors." ON)
+if (LLD_USE_EARLY_EXIT)
+  add_definitions("-DLLD_USE_EARLY_EXIT")
+endif()
+
 if (MSVC)
   add_definitions(-wd4530) # Suppress 'warning C4530: C++ exception handler used, but unwind semantics are not enabled.'
   add_definitions(-wd4062) # Suppress 'warning C4062: enumerator X in switch of enum Y is not handled' from system header.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102684.346149.patch
Type: text/x-patch
Size: 1443 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210518/3e7e1c39/attachment.bin>


More information about the llvm-commits mailing list