public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Darwin: Place global inits in the correct section.
@ 2023-09-04 11:29 Iain Sandoe
  0 siblings, 0 replies; only message in thread
From: Iain Sandoe @ 2023-09-04 11:29 UTC (permalink / raw)
  To: gcc-patches

Tested on x86_64-darwin21, i686-darwin9, aarch64-darwin21 and
powerpc-darwin9, pushed to trunk, thanks
Iain

--- 8< ---

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.
---
 gcc/config/darwin-sections.def | 2 ++
 gcc/config/darwin.cc           | 8 ++++++++
 2 files changed, 10 insertions(+)

diff --git a/gcc/config/darwin-sections.def b/gcc/config/darwin-sections.def
index de2334f4a7a..7e1b4710bd6 100644
--- a/gcc/config/darwin-sections.def
+++ b/gcc/config/darwin-sections.def
@@ -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)
diff --git a/gcc/config/darwin.cc b/gcc/config/darwin.cc
index b435bb2b80a..95d6194cf22 100644
--- a/gcc/config/darwin.cc
+++ b/gcc/config/darwin.cc
@@ -3893,6 +3893,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]
-- 
2.39.2 (Apple Git-143)


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-09-04 11:30 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-04 11:29 [PATCH] Darwin: Place global inits in the correct section Iain Sandoe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).