Lower `@llvm.global_dtors` using `__cxa_atexit` on MachO
authorJulian Lettner <julian.lettner@apple.com>
Wed, 9 Mar 2022 20:33:59 +0000 (12:33 -0800)
committerJulian Lettner <julian.lettner@apple.com>
Thu, 17 Mar 2022 17:47:13 +0000 (10:47 -0700)
commit22570bac694396514fff18dec926558951643fa6
treefe7b974db046775fc5b146c56775f2157ed0ddc5
parent414ed019acba67e914583fdc51eb3d1328696114
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
25 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 85% 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.ll [new file with mode: 0644]