[clang] [Clang] Place constructor/destructor functions in .text.startup/.text… (PR #200221)
Fangrui Song via cfe-commits
cfe-commits at lists.llvm.org
Fri May 29 19:30:53 PDT 2026
================
@@ -6860,6 +6860,18 @@ void CodeGenModule::HandleCXXStaticMemberVarInstantiation(VarDecl *VD) {
EmitTopLevelDecl(VD);
}
+/// Return the ELF section prefix for a function based on the function's
+/// code-region affinity: "startup" for functions that run exclusively at
+/// program startup, "exit" for functions that run exclusively at program
+/// exit. Returns nullptr when the function has no such affinity.
+static const char *getCodeRegionSectionPrefix(const FunctionDecl *D) {
+ if (D->hasAttr<ConstructorAttr>())
+ return "startup";
+ if (D->hasAttr<DestructorAttr>())
----------------
MaskRay wrote:
We should use `.text.startup.` and `.text.exit.` if we accept this change. `.text.exit` can be confused with the function `exit` compiled in -ffunction-sections mode.
https://github.com/llvm/llvm-project/pull/200221
More information about the cfe-commits
mailing list