diff options
author | Julian Lettner <julian.lettner@apple.com> | 2022-03-09 12:33:59 -0800 |
---|---|---|
committer | Julian Lettner <julian.lettner@apple.com> | 2022-03-14 17:51:18 -0700 |
commit | 9c542a5a4e1ba36c24e48185712779df52b7f7a6 (patch) | |
tree | af7bc094dd452d4543c4151503722e7a4ad1335c /llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp | |
parent | 24ebdb6c255e0168e4518cc7f0c465b53867abf8 (diff) | |
download | llvm-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/TargetLoweringObjectFileImpl.cpp')
-rw-r--r-- | llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index 0853c7a..3b21e94 100644 --- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -1176,6 +1176,15 @@ void TargetLoweringObjectFileMachO::Initialize(MCContext &Ctx, dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4; } +MCSection *TargetLoweringObjectFileMachO::getStaticDtorSection( + unsigned Priority, const MCSymbol *KeySym) const { + // TODO(yln): Remove -lower-global-dtors-via-cxa-atexit fallback flag + // (LowerGlobalDtorsViaCxaAtExit) and always issue a fatal error here. + if (TM->Options.LowerGlobalDtorsViaCxaAtExit) + report_fatal_error("@llvm.global_dtors should have been lowered already"); + return StaticDtorSection; +} + void TargetLoweringObjectFileMachO::emitModuleMetadata(MCStreamer &Streamer, Module &M) const { // Emit the linker options if present. @@ -2175,8 +2184,7 @@ MCSection *TargetLoweringObjectFileWasm::getStaticCtorSection( MCSection *TargetLoweringObjectFileWasm::getStaticDtorSection( unsigned Priority, const MCSymbol *KeySym) const { - llvm_unreachable("@llvm.global_dtors should have been lowered already"); - return nullptr; + report_fatal_error("@llvm.global_dtors should have been lowered already"); } //===----------------------------------------------------------------------===// |