aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/CommandFlags.cpp
diff options
context:
space:
mode:
authorJulian Lettner <julian.lettner@apple.com>2022-03-09 12:33:59 -0800
committerJulian Lettner <julian.lettner@apple.com>2022-03-14 17:51:18 -0700
commit9c542a5a4e1ba36c24e48185712779df52b7f7a6 (patch)
treeaf7bc094dd452d4543c4151503722e7a4ad1335c /llvm/lib/CodeGen/CommandFlags.cpp
parent24ebdb6c255e0168e4518cc7f0c465b53867abf8 (diff)
downloadllvm-9c542a5a4e1ba36c24e48185712779df52b7f7a6.zip
llvm-9c542a5a4e1ba36c24e48185712779df52b7f7a6.tar.gz
llvm-9c542a5a4e1ba36c24e48185712779df52b7f7a6.tar.bz2
Lower `@llvm.global_dtors` using `__cxa_atexit` on MachO
For MachO, lower `@llvm.global_dtors` into `@llvm_global_ctors` with `__cxa_atexit` calls to avoid emitting the deprecated `__mod_term_func`. Reuse the existing `WebAssemblyLowerGlobalDtors.cpp` to accomplish this. Enable fallback to the old behavior via Clang driver flag (`-fregister-global-dtors-with-atexit`) or llc / code generation flag (`-lower-global-dtors-via-cxa-atexit`). This escape hatch will be removed in the future. Differential Revision: https://reviews.llvm.org/D121327
Diffstat (limited to 'llvm/lib/CodeGen/CommandFlags.cpp')
-rw-r--r--llvm/lib/CodeGen/CommandFlags.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/CommandFlags.cpp b/llvm/lib/CodeGen/CommandFlags.cpp
index 87758c4..0743b34 100644
--- a/llvm/lib/CodeGen/CommandFlags.cpp
+++ b/llvm/lib/CodeGen/CommandFlags.cpp
@@ -74,6 +74,7 @@ CGOPT(bool, StackSymbolOrdering)
CGOPT(bool, StackRealign)
CGOPT(std::string, TrapFuncName)
CGOPT(bool, UseCtors)
+CGOPT(bool, LowerGlobalDtorsViaCxaAtExit)
CGOPT(bool, RelaxELFRelocations)
CGOPT_EXP(bool, DataSections)
CGOPT_EXP(bool, FunctionSections)
@@ -341,6 +342,12 @@ codegen::RegisterCodeGenFlags::RegisterCodeGenFlags() {
cl::init(false));
CGBINDOPT(UseCtors);
+ static cl::opt<bool> LowerGlobalDtorsViaCxaAtExit(
+ "lower-global-dtors-via-cxa-atexit",
+ cl::desc("Lower llvm.global_dtors (global destructors) via __cxa_atexit"),
+ cl::init(true));
+ CGBINDOPT(LowerGlobalDtorsViaCxaAtExit);
+
static cl::opt<bool> RelaxELFRelocations(
"relax-elf-relocations",
cl::desc(
@@ -524,6 +531,7 @@ codegen::InitTargetOptionsFromCodeGenFlags(const Triple &TheTriple) {
Options.GuaranteedTailCallOpt = getEnableGuaranteedTailCallOpt();
Options.StackSymbolOrdering = getStackSymbolOrdering();
Options.UseInitArray = !getUseCtors();
+ Options.LowerGlobalDtorsViaCxaAtExit = getLowerGlobalDtorsViaCxaAtExit();
Options.RelaxELFRelocations = getRelaxELFRelocations();
Options.DataSections =
getExplicitDataSections().getValueOr(TheTriple.hasDefaultDataSections());