AIX -ffunction-sections support

David Edelsohn dje@watson.ibm.com
Tue Aug 22 12:32:00 GMT 2000


	The following patch adds -ffunction-sections support for GCC on
AIX.  -ffunction-sections currently does not work with deubgging enabled
because XCOFF debugging uses dbxout.c which doesn't support named
sections.  -fdata-sections (the default for AIX XLC compiler) will require
some delicate interaction with SELECT_SECTION macro.

	This patch also reverts text section alignment to 32-bits to match
jump tables reverting to 32-bits.

David


	* aix.h (ASM_DECLARE_FUNCTION_NAME): Call named_section() or
        text_section() as appropriate instead of emitting text csect
	pseudo-op directly.
	(TEXT_SECTION_ASM_OP): Only require default 32-bit alignment.
	(UNIQUE_SECTION): Define macro.
	(ASM_OUTPUT_SECTION_NAME): Define macro.
	* rs6000.c (rs6000_override_options): Disable -ffunction-sections
        on AIX if debugging and -fdata-sections always.

Index: aix.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/config/rs6000/aix.h,v
retrieving revision 1.6
diff -c -p -r1.6 aix.h
*** aix.h	2000/07/21 00:46:23	1.6
--- aix.h	2000/08/22 18:59:25
*************** toc_section ()						\
*** 408,415 ****
    fputs (TARGET_32BIT ? "\t.long ." : "\t.llong .", FILE);	\
    RS6000_OUTPUT_BASENAME (FILE, NAME);				\
    fputs (", TOC[tc0], 0\n", FILE);				\
!   fputs (TARGET_32BIT						\
! 	 ? "\t.csect .text[PR]\n." : "\t.csect .text[PR],3\n.", FILE); \
    RS6000_OUTPUT_BASENAME (FILE, NAME);				\
    fputs (":\n", FILE);						\
    if (write_symbols == XCOFF_DEBUG)				\
--- 408,419 ----
    fputs (TARGET_32BIT ? "\t.long ." : "\t.llong .", FILE);	\
    RS6000_OUTPUT_BASENAME (FILE, NAME);				\
    fputs (", TOC[tc0], 0\n", FILE);				\
!   in_section = no_section;					\
!   if (flag_function_sections)					\
!     named_section ((DECL), (char *) 0, 0);			\
!   else								\
!     text_section();						\
!   putc ('.', FILE);						\
    RS6000_OUTPUT_BASENAME (FILE, NAME);				\
    fputs (":\n", FILE);						\
    if (write_symbols == XCOFF_DEBUG)				\
*************** toc_section ()						\
*** 525,546 ****
    fprintf ((FILE), "\t.vbyte\t2,0x%x", (unsigned) (VALUE))
  
  #define ASM_OUTPUT_DWARF_OFFSET4(FILE, LABEL)	\
!  ASM_OUTPUT_DWARF_ADDR_VAR (FILE, LABEL, 4)
  
  #define ASM_OUTPUT_DWARF_OFFSET(FILE, LABEL)			\
!  ASM_OUTPUT_DWARF_ADDR_VAR (FILE, LABEL, DWARF_OFFSET_SIZE)
  
  /* dwarf2out keys off this, but we don't have to have a real definition.  */
  #define UNALIGNED_INT_ASM_OP bite_me
  
! /* Output before instructions.
!    Text section for 64-bit target may contain 64-bit address jump table.  */
! #define TEXT_SECTION_ASM_OP (TARGET_32BIT \
!                              ? "\t.csect .text[PR]" : "\t.csect .text[PR],3")
  
  /* Output before writable data.
     Align entire section to BIGGEST_ALIGNMENT.  */
  #define DATA_SECTION_ASM_OP "\t.csect .data[RW],3"
  
  /* __throw will restore its own return address to be the same as the
     return address of the function that the throw is being made to.
--- 529,570 ----
    fprintf ((FILE), "\t.vbyte\t2,0x%x", (unsigned) (VALUE))
  
  #define ASM_OUTPUT_DWARF_OFFSET4(FILE, LABEL)	\
!   ASM_OUTPUT_DWARF_ADDR_VAR (FILE, LABEL, 4)
  
  #define ASM_OUTPUT_DWARF_OFFSET(FILE, LABEL)			\
!   ASM_OUTPUT_DWARF_ADDR_VAR (FILE, LABEL, DWARF_OFFSET_SIZE)
  
  /* dwarf2out keys off this, but we don't have to have a real definition.  */
  #define UNALIGNED_INT_ASM_OP bite_me
  
! /* Output before instructions.  */
! #define TEXT_SECTION_ASM_OP "\t.csect .text[PR]"
  
  /* Output before writable data.
     Align entire section to BIGGEST_ALIGNMENT.  */
  #define DATA_SECTION_ASM_OP "\t.csect .data[RW],3"
+ 
+ /* Define unique section name -- functions only.  */
+ #define UNIQUE_SECTION(DECL,RELOC)			\
+   do {							\
+     int len;						\
+     const char *name;					\
+     char *string;					\
+ 							\
+     if (TREE_CODE (DECL) == FUNCTION_DECL) {		\
+       name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (DECL)); \
+       len = strlen (name) + 5;				\
+       string = alloca (len) + 1;			\
+       sprintf (string, ".%s[PR]", name);		\
+       DECL_SECTION_NAME (DECL) = build_string (len, string); \
+     }							\
+   } while (0)
+ 
+ #define ASM_OUTPUT_SECTION_NAME(ASM_OUT_FILE,DECL,NAME,RELOC)	\
+   do { fputs ("\t.csect ", ASM_OUT_FILE);			\
+        fputs (TREE_STRING_POINTER (DECL_SECTION_NAME (DECL)), ASM_OUT_FILE); \
+        putc ('\n', ASM_OUT_FILE);				\
+   } while (0)
  
  /* __throw will restore its own return address to be the same as the
     return address of the function that the throw is being made to.
Index: rs6000.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/config/rs6000/rs6000.c,v
retrieving revision 1.144
diff -c -p -r1.144 rs6000.c
*** rs6000.c	2000/08/14 20:46:16	1.144
--- rs6000.c	2000/08/22 19:18:29
*************** rs6000_override_options (default_cpu)
*** 361,366 ****
--- 361,379 ----
        flag_pic = 0;
      }
  
+   if (flag_function_sections && (write_symbols != NO_DEBUG)
+       && (DEFAULT_ABI == ABI_AIX))
+     {
+       warning ("-ffunction-sections disabled on AIX when debugging");
+       flag_function_sections = 0;
+     }
+ 
+   if (flag_data_sections && (DEFAULT_ABI == ABI_AIX))
+     {
+       warning ("-fdata-sections not supported on AIX");
+       flag_data_sections = 0;
+     }
+ 
    /* Set debug flags */
    if (rs6000_debug_name)
      {


More information about the Gcc-patches mailing list