public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch] Fix anonymous code atoms problem on Darwin.
@ 2010-12-20 12:03 IainS
  2010-12-20 21:49 ` Richard Henderson
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: IainS @ 2010-12-20 12:03 UTC (permalink / raw)
  To: GCC Patches; +Cc: Richard Henderson, Mike Stump, Jan Hubicka

[-- Attachment #1: Type: text/plain, Size: 1476 bytes --]

Hi,

This problem became apparent during the resolution of PR46904/46916  
(we have had to switch off freorder-and-partition to avoid regression).

--

Darwin's toolchain will not allow us to have code fragments that are  
anonymous (i.e. isolated by section and preceded only by a local label).

The rule [as quoted by Mike] is:
All sections have zero or more atoms.  An atom is 1 or more bytes with  
a label (non-L) on the front of it.

function reordering or partitioning breaks this, manifesting in linker  
warnings and non-functional debug.

The following patch creates and calls a target hook after mid-function  
section switches that gives the target an opportunity to do whatever  
is necessary to avoid orphan code fragments.  The darwin  
implementation of the hook post-fixes the function name with _$hot$ or  
_$cold$ as appropriate.

OK for trunk?
Iain

gcc:

	* target.def (function_switched_text_sections): New Hook.
	* doc/tm.texi Regenerated.
	* doc/tm.texi.in (TARGET_ASM_FUNCTION_SWITCHED_TEXT_SECTIONS)
	New.
	* final.c (default_function_switched_text_sections): New.
	(final_scan_insn): Call function_switched_text_sections when a mid- 
function section
	change occurs.
	* output.h (default_function_switched_text_sections): Declare.
	* config/darwin-protos.h (darwin_function_switched_text_sections) :  
Likewise.
	* config/darwin.c (darwin_function_switched_text_sections): New.
	* config/darwin.h (TARGET_ASM_FUNCTION_SWITCHED_TEXT_SECTIONS)
	New.


[-- Attachment #2: 168084-code-atoms.txt --]
[-- Type: text/plain, Size: 6221 bytes --]

Index: gcc/target.def
===================================================================
--- gcc/target.def	(revision 168084)
+++ gcc/target.def	(working copy)
@@ -294,6 +294,17 @@ DEFHOOK
  section *, (tree decl, enum node_frequency freq, bool startup, bool exit),
  default_function_section)
 
+/* Output the assembler code for function exit.  */
+DEFHOOK
+(function_switched_text_sections,
+ "Used by the target to emit any assembler directives or additional\
+  labels needed when a function is partitioned between different\
+  sections.  Output should be written to @var{file}.  The function\
+  decl is available as @var{decl} and the new section is `cold' if\
+  @var{new_is_cold} is @code{true}.",
+ void, (FILE *file, tree decl, bool new_is_cold),
+ default_function_switched_text_sections)
+
 /* Return a mask describing how relocations should be treated when
    selecting sections.  Bit 1 should be set if global relocations
    should be placed in a read-write section; bit 0 should be set if
Index: gcc/doc/tm.texi
===================================================================
--- gcc/doc/tm.texi	(revision 168084)
+++ gcc/doc/tm.texi	(working copy)
@@ -7325,6 +7325,10 @@ at startup (from static constructors or it is @cod
 Return NULL if function should go to default text section.
 @end deftypefn
 
+@deftypefn {Target Hook} void TARGET_ASM_FUNCTION_SWITCHED_TEXT_SECTIONS (FILE *@var{file}, tree @var{decl}, bool @var{new_is_cold})
+Used by the target to emit any assembler directives or additional  labels needed when a function is partitioned between different  sections.  Output should be written to @var{file}.  The function  decl is available as @var{decl} and the new section is `cold' if  @var{new_is_cold} is @code{true}.
+@end deftypefn
+
 @deftypevr {Target Hook} bool TARGET_HAVE_NAMED_SECTIONS
 This flag is true if the target supports @code{TARGET_ASM_NAMED_SECTION}.
 It must not be modified by command-line option processing.
Index: gcc/doc/tm.texi.in
===================================================================
--- gcc/doc/tm.texi.in	(revision 168084)
+++ gcc/doc/tm.texi.in	(working copy)
@@ -7298,6 +7298,8 @@ at startup (from static constructors or it is @cod
 Return NULL if function should go to default text section.
 @end deftypefn
 
+@hook TARGET_ASM_FUNCTION_SWITCHED_TEXT_SECTIONS
+
 @hook TARGET_HAVE_NAMED_SECTIONS
 This flag is true if the target supports @code{TARGET_ASM_NAMED_SECTION}.
 It must not be modified by command-line option processing.
Index: gcc/final.c
===================================================================
--- gcc/final.c	(revision 168084)
+++ gcc/final.c	(working copy)
@@ -256,6 +256,13 @@ default_function_pro_epilogue (FILE *file ATTRIBUT
 {
 }
 
+void
+default_function_switched_text_sections (FILE *file ATTRIBUTE_UNUSED,
+					 tree decl ATTRIBUTE_UNUSED,
+					 bool new_is_cold ATTRIBUTE_UNUSED)
+{
+}
+
 /* Default target hook that outputs nothing to a stream.  */
 void
 no_asm_to_stream (FILE *file ATTRIBUTE_UNUSED)
@@ -1841,6 +1848,9 @@ final_scan_insn (rtx insn, FILE *file, int optimiz
 	    debug_hooks->switch_text_section ();
 
 	  switch_to_section (current_function_section ());
+	  targetm.asm_out.function_switched_text_sections (asm_out_file,
+							   current_function_decl,
+							   in_cold_section_p);
 	  break;
 
 	case NOTE_INSN_BASIC_BLOCK:
Index: gcc/output.h
===================================================================
--- gcc/output.h	(revision 168084)
+++ gcc/output.h	(working copy)
@@ -417,6 +417,9 @@ extern const char *user_label_prefix;
 /* Default target function prologue and epilogue assembler output.  */
 extern void default_function_pro_epilogue (FILE *, HOST_WIDE_INT);
 
+/* Default target function switched text sections.  */
+extern void default_function_switched_text_sections (FILE *, tree, bool);
+
 /* Default target hook that outputs nothing to a stream.  */
 extern void no_asm_to_stream (FILE *);
 
Index: gcc/config/darwin-protos.h
===================================================================
--- gcc/config/darwin-protos.h	(revision 168084)
+++ gcc/config/darwin-protos.h	(working copy)
@@ -58,6 +58,8 @@ extern section *machopic_select_rtx_section (enum
 					     unsigned HOST_WIDE_INT);
 
 extern section *darwin_function_section (tree, enum node_frequency, bool, bool); 
+extern void darwin_function_switched_text_sections (FILE *, tree, bool);
+
 extern void darwin_unique_section (tree decl, int reloc);
 extern void darwin_asm_named_section (const char *, unsigned int, tree);
 extern void darwin_non_lazy_pcrel (FILE *, rtx);
Index: gcc/config/darwin.c
===================================================================
--- gcc/config/darwin.c	(revision 168084)
+++ gcc/config/darwin.c	(working copy)
@@ -3066,4 +3047,22 @@ darwin_function_section (tree decl, enum node_freq
     }
 }
 
+/* When a function is partitioned between sections, we need to insert a label
+   at the start of each new chunk - so that it may become a valid 'atom' for
+   eh and debug purposes.  Without this the linker will emit warnings if one 
+   tries to add line location information (since the switched fragment will 
+   be anonymous).  */
+
+void
+darwin_function_switched_text_sections (FILE *fp, tree decl, bool new_is_cold)
+{
+  char buf[128];
+  snprintf (buf, 128, "%s%s",
+	    IDENTIFIER_POINTER (DECL_NAME (decl)),
+	    new_is_cold?"_$cold$":"_$hot$");
+  /* Make sure we pick up all the relevant quotes etc.  */
+  assemble_name_raw (fp, (const char *) buf);
+  fputs (":\n", fp);
+}
+
 #include "gt-darwin.h"
Index: gcc/config/darwin.h
===================================================================
--- gcc/config/darwin.h	(revision 168084)
+++ gcc/config/darwin.h	(working copy)
@@ -673,6 +673,10 @@ extern GTY(()) section * darwin_sections[NUM_DARWI
 #undef	TARGET_ASM_FUNCTION_SECTION
 #define TARGET_ASM_FUNCTION_SECTION darwin_function_section
 
+#undef	TARGET_ASM_FUNCTION_SWITCHED_TEXT_SECTIONS
+#define TARGET_ASM_FUNCTION_SWITCHED_TEXT_SECTIONS \
+	darwin_function_switched_text_sections
+
 #undef	TARGET_ASM_SELECT_RTX_SECTION
 #define TARGET_ASM_SELECT_RTX_SECTION machopic_select_rtx_section
 #undef  TARGET_ASM_UNIQUE_SECTION

[-- Attachment #3: Type: text/plain, Size: 3 bytes --]





^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2011-02-12 10:54 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-20 12:03 [Patch] Fix anonymous code atoms problem on Darwin IainS
2010-12-20 21:49 ` Richard Henderson
2010-12-23 20:50 ` Mike Stump
2011-01-07 14:12   ` IainS
2011-02-08  3:01 ` Mike Stump
2011-02-08  8:19   ` IainS
2011-02-08  9:14     ` IainS
2011-02-08 13:35       ` IainS
2011-02-08 20:50         ` Mike Stump
2011-02-12 11:21           ` IainS

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).