[committed] Fix handling of function sections on PA

Message ID 20101208015431.GA13736@hiauly1.hia.nrc.ca
State New
Headers show

Commit Message

John David Anglin Dec. 8, 2010, 1:54 a.m.
The patch below fixes two regressions introduced by commit r167085.

The first is the middle-end no longer supports targets without named
sections.  default_function_section is elf specific.  I have no idea
why this change was made during stage3.  The patch author has
refused to discuss the regressions caused by the commit.

The second is the commit placed nested functions into text.unlikely
by default.  The pa backend assumes nonlocal labels are in the same
section as the containing function.  Accessing a nonlocal label in
a different section would require a dynamic relocation.  There doesn't
seem any reason to support this extra inefficiency, so the suggestion
of Jakub Jelinek has been adopted to force nested functions into
the same section as the containing function.

The new sections introduced by commit r167085 had the potential to
break call branch handling on the PA.  The branch emitted for a call
depends on the distance to the beginning of the current section.
The code currently handles unnamed text sections and function sections.
After examining the situation, I concluded that the new sections
only result in an over estimate of the branch distance to the beginning
of the current section.  flag_function_sections appears to be handled
correctly.  The concern that I had was whether or not to use
default_function_section on PA elf targets.

Tested on hppa2.0w-hp-hpux11.11, hppa64-hp-hpux11.11 and
hppa-unknown-linux-gnu.  Committed to trunk.



Index: config/pa/pa.c
--- config/pa/pa.c	(revision 167472)
+++ config/pa/pa.c	(working copy)
@@ -181,6 +181,7 @@ 
 static rtx pa_internal_arg_pointer (void);
 static bool pa_can_eliminate (const int, const int);
 static void pa_conditional_register_usage (void);
+static section *pa_function_section (tree, enum node_frequency, bool, bool);
 /* The following extra sections are only used for SOM.  */
 static GTY(()) section *som_readonly_data_section;
@@ -388,6 +389,8 @@ 
 #define TARGET_CAN_ELIMINATE pa_can_eliminate
 #define TARGET_CONDITIONAL_REGISTER_USAGE pa_conditional_register_usage
+#define TARGET_ASM_FUNCTION_SECTION pa_function_section
 struct gcc_target targetm = TARGET_INITIALIZER;
@@ -10200,4 +10203,27 @@ 
     fixed_regs[PIC_OFFSET_TABLE_REGNUM] = 1;
+/* Target hook for function_section.  */
+static section *
+pa_function_section (tree decl, enum node_frequency freq,
+		     bool startup, bool exit)
+  /* Put functions in text section if target doesn't have named sections.  */
+  if (!targetm.have_named_sections)
+    return text_section;
+  /* Force nested functions into the same section as the containing
+     function.  */
+  if (decl
+      && DECL_SECTION_NAME (decl) == NULL_TREE
+      && DECL_CONTEXT (decl) != NULL_TREE
+    return function_section (DECL_CONTEXT (decl));
+  /* Otherwise, use the default function section.  */
+  return default_function_section (decl, freq, startup, exit);
 #include "gt-pa.h"