Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions clang/lib/CodeGen/ItaniumCXXABI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,14 @@ class FuchsiaCXXABI final : public ItaniumCXXABI {
explicit FuchsiaCXXABI(CodeGen::CodeGenModule &CGM)
: ItaniumCXXABI(CGM) {}

// Rather than using the defaul [__cxa_]atexit, instead use llvm.global_dtors
// which will result in .fini_array being used.
void registerGlobalDtor(CodeGenFunction &CGF, const VarDecl &D,
llvm::FunctionCallee dtor,
llvm::Constant *addr) override {
return CGM.AddCXXDtorEntry(dtor, addr);
}

private:
bool constructorsAndDestructorsReturnThis() const override { return true; }
};
Expand Down
25 changes: 25 additions & 0 deletions clang/test/CodeGenCXX/fuchsia-global-dtor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/// Global destructors targetting Fuchsia should not use [__cxa_]atexit. Instead
/// they should be invoked through llvm.global_dtors.

// RUN: %clang_cc1 %s -triple aarch64-unknown-fuchsia -emit-llvm -o - | FileCheck %s

// CHECK-NOT: atexit

// CHECK: @llvm.global_dtors = appending global [1 x { i32, ptr, ptr }]
// CHECK-SAME: [{ i32, ptr, ptr } { i32 {{.*}}, ptr [[MODULE_DTOR:@.*]], ptr {{.*}} }]

// CHECK: define internal void [[MODULE_DTOR]]() {{.*}}{
// CHECK-NEXT: entry:
// CHECK-NEXT: %0 = call ptr @_ZN1AD1Ev(ptr @DestroyFirst)
// CHECK-NEXT: %1 = call ptr @_ZN1AD1Ev(ptr @DestroySecond)
// CHECK-NEXT: %2 = call ptr @_ZN1AD1Ev(ptr @DestroyThird)
// CHECK-NEXT: ret void
// CHECK-NEXT: }

struct A {
~A() {}
};

A DestroyThird;
A DestroySecond;
A DestroyFirst;
Loading