]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Darwin: Place global inits in the correct section.
authorIain Sandoe <iain@sandoe.co.uk>
Fri, 1 Sep 2023 08:04:13 +0000 (09:04 +0100)
committerIain Sandoe <iain@sandoe.co.uk>
Thu, 18 Apr 2024 14:46:36 +0000 (15:46 +0100)
This handles placement of global initializers into __TEXT,__StaticInit as used
by other platform toolchains.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
gcc/ChangeLog:

* config/darwin-sections.def (static_init_section): Add the
__TEXT,__StaticInit section.
* config/darwin.cc (darwin_function_section): Use the static init
section for global initializers, to match other platform toolchains.

(cherry picked from commit 68dc3e94fd6bd395a8b343533485616dff3fc796)

gcc/config/darwin-sections.def
gcc/config/darwin.cc

index cdd5985cc368e3f36f012250e797947da7e117b9..af7bb404688dfa14ab6efce1cf211428069c54a2 100644 (file)
@@ -98,6 +98,8 @@ DEF_SECTION (mod_init_section, 0, ".mod_init_func", 0)
 DEF_SECTION (mod_term_section, 0, ".mod_term_func", 0)
 DEF_SECTION (constructor_section, 0, ".constructor", 0)
 DEF_SECTION (destructor_section, 0, ".destructor", 0)
+DEF_SECTION (static_init_section, SECTION_CODE,
+            ".section\t__TEXT,__StaticInit,regular,pure_instructions", 0)
 
 /* Objective-C ABI=0 (Original version) sections.  */
 DEF_SECTION (objc_class_section, 0, ".objc_class", 1)
index 8aa10153cded4d66f7c8573ed905c14abd186d4a..68a692dc74e102c9066c5f6457a535a684ea8ed6 100644 (file)
@@ -3879,6 +3879,14 @@ darwin_function_section (tree decl, enum node_frequency freq,
   if (decl && DECL_SECTION_NAME (decl) != NULL)
     return get_named_section (decl, NULL, 0);
 
+  /* Intercept functions in global init; these are placed in separate sections.
+     FIXME: there should be some neater way to do this.  */
+  if (DECL_NAME (decl)
+      && (startswith (IDENTIFIER_POINTER (DECL_NAME (decl)), "_GLOBAL__sub_I")
+         || startswith (IDENTIFIER_POINTER (DECL_NAME (decl)),
+                        "__static_initialization_and_destruction")))
+    return  darwin_sections[static_init_section];
+
   /* We always put unlikely executed stuff in the cold section.  */
   if (freq == NODE_FREQUENCY_UNLIKELY_EXECUTED)
     return (use_coal) ? darwin_sections[text_cold_coal_section]