================
@@ -3131,7 +3113,18 @@ 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())
+
+  // 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.getLangOpts().hasAtExit() &&
+      CGM.getTarget().getTriple().isOSBinFormatELF() &&
+      !CGM.getCodeGenOpts().CXAAtExit &&
+      !CGM.getCodeGenOpts().RegisterGlobalDtorsWithAtExit &&
+      !D.isStaticLocal() && !D.getTLSKind())
     return CGF.registerGlobalDtorWithLLVM(D, dtor, addr);
----------------
zhangweize9-cyber wrote:

The original author added an extra if branch.

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

Reply via email to