Reland "Lower `@llvm.global_dtors` using `__cxa_atexit` on MachO"
authorJulian Lettner <julian.lettner@apple.com>
Thu, 24 Mar 2022 00:37:07 +0000 (17:37 -0700)
committerJulian Lettner <julian.lettner@apple.com>
Thu, 24 Mar 2022 01:36:55 +0000 (18:36 -0700)
commit64902d335c2126e24a9d84b7410924148959e4a9
tree59cdc88c0f3836312effe230bb4ad178ebc7323f
parent39aa202affd99d1713daea00b7681571fe478a12
Reland "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/D121736
26 files changed:
clang/lib/CodeGen/BackendUtil.cpp
llvm/docs/Passes.rst
llvm/include/llvm/CodeGen/CommandFlags.h
llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
llvm/include/llvm/InitializePasses.h
llvm/include/llvm/LinkAllPasses.h
llvm/include/llvm/Target/TargetOptions.h
llvm/include/llvm/Transforms/Instrumentation/AddressSanitizerOptions.h
llvm/include/llvm/Transforms/Utils.h
llvm/include/llvm/Transforms/Utils/LowerGlobalDtors.h [new file with mode: 0644]
llvm/lib/CodeGen/CodeGen.cpp
llvm/lib/CodeGen/CommandFlags.cpp
llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
llvm/lib/CodeGen/TargetPassConfig.cpp
llvm/lib/Passes/PassBuilder.cpp
llvm/lib/Passes/PassRegistry.def
llvm/lib/Target/WebAssembly/CMakeLists.txt
llvm/lib/Target/WebAssembly/WebAssembly.h
llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
llvm/lib/Transforms/Utils/CMakeLists.txt
llvm/lib/Transforms/Utils/LowerGlobalDtors.cpp [moved from llvm/lib/Target/WebAssembly/WebAssemblyLowerGlobalDtors.cpp with 80% similarity]
llvm/lib/Transforms/Utils/Utils.cpp
llvm/test/CodeGen/ARM/ctors_dtors.ll
llvm/test/CodeGen/X86/2011-08-29-InitOrder.ll
llvm/test/Transforms/LowerGlobalDestructors/lower-global-dtors-existing-dos_handle.ll [new file with mode: 0644]
llvm/test/Transforms/LowerGlobalDestructors/lower-global-dtors.ll [new file with mode: 0644]