https://github.com/zhangweize9-cyber updated 
https://github.com/llvm/llvm-project/pull/216611

>From 70c8c59840424b3d10aac1b78cc57db1fd7ab1d3 Mon Sep 17 00:00:00 2001
From: pyxherb <[email protected]>
Date: Sat, 25 Jul 2026 07:29:53 +0800
Subject: [PATCH 1/2] [Clang] Ensure that .fini_array is also available while
 __cxa_atexit() and atexit() are available This conservative PR fixes the
 inconsistency of behaviors of '-fno-use-cxa-atexit' to GCC, which blocks user
 to use .fini_array instead of __cxa_atexit() and atexit() on ELF-based
 platforms. This PR currently fixes this bug on the ELF-based platforms only,
 but perhaps also applicable on COFF.

---
 clang/lib/CodeGen/ItaniumCXXABI.cpp | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp 
b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index 5c5fefe32c06c..59374b13abe0f 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -3136,6 +3136,18 @@ void ItaniumCXXABI::registerGlobalDtor(CodeGenFunction 
&CGF, const VarDecl &D,
   if (!CGM.getLangOpts().hasAtExit() && !D.isStaticLocal())
     return CGF.registerGlobalDtorWithLLVM(D, dtor, addr);
 
+  // If '-fno-use-cxa-atexit' and '-fno-register-global-dtors-with-atexit' are 
also sepcified,
+  // this means the user does not want any invocation to __cxa_atexit or 
atexit,
+  // but we still have to check if the declaration is static-local or 
thread-local,
+  // which should not be supported by this case.
+  // As we investigated, ELF has its .fini_array section to support the global 
destructors.
+  // So we can safely apply this to ELF.
+  if (CGM.getTarget().getTriple().isOSBinFormatELF() &&
+    !CGM.getCodeGenOpts().CXAAtExit &&
+    !CGM.getCodeGenOpts().RegisterGlobalDtorsWithAtExit &&
+    !D.isStaticLocal() && !D.getTLSKind())
+    return CGF.registerGlobalDtorWithLLVM(D, dtor, addr);
+
   // emitGlobalDtorWithCXAAtExit will emit a call to either __cxa_thread_atexit
   // or __cxa_atexit depending on whether this VarDecl is a thread-local 
storage
   // or not. CXAAtExit controls only __cxa_atexit, so use it if it is enabled.

>From f32f6e573d2891283080f69606ca43221eb8515a Mon Sep 17 00:00:00 2001
From: zhangweize9-cyber <[email protected]>
Date: Mon, 17 Aug 2026 07:58:10 +0800
Subject: [PATCH 2/2] refix: #211963

---
 clang/lib/CodeGen/ItaniumCXXABI.cpp | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp 
b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index 59374b13abe0f..767df557176df 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -3133,8 +3133,6 @@ void ItaniumCXXABI::registerGlobalDtor(CodeGenFunction 
&CGF, const VarDecl &D,
   // destructors which we can handle directly in the runtime. Note that this is
   // not strictly 1-to-1 with using `atexit` because we no longer tear down
   // globals in reverse order of when they were constructed.
-  if (!CGM.getLangOpts().hasAtExit() && !D.isStaticLocal())
-    return CGF.registerGlobalDtorWithLLVM(D, dtor, addr);
 
   // If '-fno-use-cxa-atexit' and '-fno-register-global-dtors-with-atexit' are 
also sepcified,
   // this means the user does not want any invocation to __cxa_atexit or 
atexit,
@@ -3142,10 +3140,11 @@ void ItaniumCXXABI::registerGlobalDtor(CodeGenFunction 
&CGF, const VarDecl &D,
   // which should not be supported by this case.
   // As we investigated, ELF has its .fini_array section to support the global 
destructors.
   // So we can safely apply this to ELF.
-  if (CGM.getTarget().getTriple().isOSBinFormatELF() &&
-    !CGM.getCodeGenOpts().CXAAtExit &&
-    !CGM.getCodeGenOpts().RegisterGlobalDtorsWithAtExit &&
-    !D.isStaticLocal() && !D.getTLSKind())
+  if (!CGM.getLangOpts().hasAtExit() &&
+      CGM.getTarget().getTriple().isOSBinFormatELF() &&
+      !CGM.getCodeGenOpts().CXAAtExit &&
+      !CGM.getCodeGenOpts().RegisterGlobalDtorsWithAtExit &&
+      !D.isStaticLocal() && !D.getTLSKind())
     return CGF.registerGlobalDtorWithLLVM(D, dtor, addr);
 
   // emitGlobalDtorWithCXAAtExit will emit a call to either __cxa_thread_atexit

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to