[gcc r13-8532] Darwin: Place global inits in the correct section.
Iain D Sandoe
iains@gcc.gnu.org
Sun Mar 31 08:59:31 GMT 2024
https://gcc.gnu.org/g:be95ee81bc934d6b22e5639eb7b5f9603fa1443d
commit r13-8532-gbe95ee81bc934d6b22e5639eb7b5f9603fa1443d
Author: Iain Sandoe <iain@sandoe.co.uk>
Date: Fri Sep 1 09:04:13 2023 +0100
Darwin: Place global inits in the correct section.
This handles placement of global initializers into __TEXT,__StaticInit as used
by other platform toolchains.
Since we do see global initialization code getting hot/cold splits, this
patch places the cold parts into text_cold, and keeps the hot part in
the correct Init section per ABI.
This includes the update from 5b33b364652866165431aef1810af1e890229c5e.
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.
Place unlikely executed global init code into the standard cold
section.
(cherry picked from commit 68dc3e94fd6bd395a8b343533485616dff3fc796)
Diff:
---
gcc/config/darwin-sections.def | 2 ++
gcc/config/darwin.cc | 13 ++++++++++++-
2 files changed, 14 insertions(+), 1 deletion(-)
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 c5c0fb034af..5e1b8ccd4eb 100644
--- a/gcc/config/darwin.cc
+++ b/gcc/config/darwin.cc
@@ -3854,11 +3854,22 @@ darwin_function_section (tree decl, enum node_frequency freq,
if (decl && DECL_SECTION_NAME (decl) != NULL)
return get_named_section (decl, NULL, 0);
- /* We always put unlikely executed stuff in the cold section. */
+ /* We always put unlikely executed stuff in the cold section; we have to put
+ this ahead of the global init section, since partitioning within a section
+ breaks some assumptions made in the DWARF handling. */
if (freq == NODE_FREQUENCY_UNLIKELY_EXECUTED)
return (use_coal) ? darwin_sections[text_cold_coal_section]
: darwin_sections[text_cold_section];
+ /* Intercept functions in global init; these are placed in separate sections.
+ FIXME: there should be some neater way to do this, FIXME we should be able
+ to partition within a section. */
+ 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];
+
/* If we have LTO *and* feedback information, then let LTO handle
the function ordering, it makes a better job (for normal, hot,
startup and exit - hence the bailout for cold above). */
More information about the Gcc-cvs
mailing list