public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [pushed] Darwin: Partial reversion of r14-3648 (Inits Section).
@ 2023-09-10 14:10 Iain Sandoe
  0 siblings, 0 replies; only message in thread
From: Iain Sandoe @ 2023-09-10 14:10 UTC (permalink / raw)
  To: gcc-patches

Tested on x86_64-darwin21 and i686-darwin9 with both dwarfutils and
llvm-based dsymutil implementations.  Pushed to trunk, thanks
Iain

--- 8< ---

Although the Darwin ABI places both hot and cold partitions in the same
section (the linker can partition by name), this does not work with the
current dwarf2out implementation.

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.

TODO: figure out a way to allow us to match the ABI fully.

gcc/ChangeLog:

	* config/darwin.cc (darwin_function_section): Place unlikely
	executed global init code into the standard cold section.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
---
 gcc/config/darwin.cc | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/gcc/config/darwin.cc b/gcc/config/darwin.cc
index 95d6194cf22..154a2b2755a 100644
--- a/gcc/config/darwin.cc
+++ b/gcc/config/darwin.cc
@@ -3893,19 +3893,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 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: 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];
 
-  /* 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]
-		      : darwin_sections[text_cold_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).  */
-- 
2.39.2 (Apple Git-143)


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

only message in thread, other threads:[~2023-09-10 14:10 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-10 14:10 [pushed] Darwin: Partial reversion of r14-3648 (Inits 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).