This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: rs6000_flag_pic


On Wed, Mar 12, 2003 at 07:46:43PM -0500, David Edelsohn wrote:
> but I believe the original problem was more common
> than those examples.

Yeah, it happens for -fno-pic app typeinfo referencing a vtable in a
shared lib.  Ick.  Does anyone know if this is a generic bug?  I'm
seeing stuff like

Disassembly of section .gnu.linkonce.r._ZTI1A:

0000000000000000 <typeinfo for A>:
   0:   00 00 00 00     .long 0x0
                        0: R_PPC64_ADDR64       vtable for __cxxabiv1::__class_type_info+0x10
   4:   00 00 00 10     .long 0x10
   8:   00 00 00 00     .long 0x0
                        8: R_PPC64_ADDR64       typeinfo name for A
   c:   00 00 00 00     .long 0x0

Anyway, that's fairly convincing that we need to keep rs6000_elf_*
section handling twiddles for ABI_AIX, at least in the short term, and
have added a comment to say why.  Currently regression testing the
following.

	* config/rs6000/rs6000.c (rs6000_flag_pic): Delete.
	(rs6000_xcoff_encode_section_info): #ifdef TARGET_XCOFF.
	(rs6000_binds_local_p, TARGET_BINDS_LOCAL_P): #if TARGET_MACHO.
	(rs6000_override_options): Don't clear flag_pic for ABI_AIX.
	(rs6000_legitimize_address): Formatting.
	(rs6000_emit_move): Likewise.
	(rs6000_return_addr): Test ABI_AIX as well as flag_pic.
	(rs6000_emit_prologue <save_LR_around_toc_setup>): Likewise.
	(rs6000_elf_select_section): Comment reason for shlib being
	set for ABI_AIX.
	(rs6000_elf_unique_section): Likewise.
	(rs6000_elf_encode_section_info): Test !TARGET_AIX as well as ABI_AIX.
	* config/rs6000/rs6000.h (LEGITIMATE_LO_SUM_ADDRESS_P): Test ABI_AIX
	as well as flag_pic.
	* config/rs6000/sysv4.h (SUBTARGET_OVERRIDE_OPTIONS): Likewise.
	(MINIMAL_TOC_SECTION_ASM_OP): Likewise.
	* config/rs6000/linux64.h (TARGET_ENCODE_SECTION_INFO): Don't define.

diff -urp -xCVS -x'*~' gcc-rs6000.orig/gcc/config/rs6000/rs6000.c gcc-rs6000/gcc/config/rs6000/rs6000.c
--- gcc-rs6000.orig/gcc/config/rs6000/rs6000.c	2003-03-11 10:58:06.000000000 +1030
+++ gcc-rs6000/gcc/config/rs6000/rs6000.c	2003-03-13 12:06:15.000000000 +1030
@@ -97,9 +97,6 @@ const char *rs6000_isel_string;
 /* Set to nonzero once AIX common-mode calls have been defined.  */
 static GTY(()) int common_mode_defined;
 
-/* Private copy of original value of flag_pic for ABI_AIX.  */
-static int rs6000_flag_pic;
-
 /* Save information from a "cmpxx" operation until the branch or scc is
    emitted.  */
 rtx rs6000_compare_op0, rs6000_compare_op1;
@@ -225,10 +222,12 @@ static void rs6000_xcoff_select_rtx_sect
 						     unsigned HOST_WIDE_INT));
 static const char * rs6000_xcoff_strip_name_encoding PARAMS ((const char *));
 static unsigned int rs6000_xcoff_section_type_flags PARAMS ((tree, const char *, int));
-#endif
 static void rs6000_xcoff_encode_section_info PARAMS ((tree, int))
      ATTRIBUTE_UNUSED;
+#endif
+#if TARGET_MACHO
 static bool rs6000_binds_local_p PARAMS ((tree));
+#endif
 static int rs6000_use_dfa_pipeline_interface PARAMS ((void));
 static int rs6000_variable_issue PARAMS ((FILE *, int, rtx, int));
 static bool rs6000_rtx_costs PARAMS ((rtx, int, int, int *));
@@ -403,8 +402,10 @@ static const char alt_reg_names[][8] =
 #undef TARGET_EXPAND_BUILTIN
 #define TARGET_EXPAND_BUILTIN rs6000_expand_builtin
 
+#if TARGET_MACHO
 #undef TARGET_BINDS_LOCAL_P
 #define TARGET_BINDS_LOCAL_P rs6000_binds_local_p
+#endif
 
 #undef TARGET_ASM_OUTPUT_MI_THUNK
 #define TARGET_ASM_OUTPUT_MI_THUNK rs6000_output_mi_thunk
@@ -637,12 +638,6 @@ rs6000_override_options (default_cpu)
 	}
     }
 
-  if (flag_pic != 0 && DEFAULT_ABI == ABI_AIX)
-    {
-      rs6000_flag_pic = flag_pic;
-      flag_pic = 0;
-    }
-
   /* For Darwin, always silently make -fpic and -fPIC identical.  */
   if (flag_pic == 1 && DEFAULT_ABI == ABI_DARWIN)
     flag_pic = 2;
@@ -2214,7 +2209,10 @@ rs6000_legitimize_address (x, oldx, mode
 
       return force_reg (Pmode, x);
     }
-  else if (TARGET_ELF && TARGET_32BIT && TARGET_NO_TOC && ! flag_pic
+  else if (TARGET_ELF
+	   && TARGET_32BIT
+	   && TARGET_NO_TOC
+	   && ! flag_pic
 	   && GET_CODE (x) != CONST_INT
 	   && GET_CODE (x) != CONST_DOUBLE 
 	   && CONSTANT_P (x)
@@ -2752,7 +2750,8 @@ rs6000_emit_move (dest, source, mode)
 	}
 
       if ((TARGET_ELF || DEFAULT_ABI == ABI_DARWIN)
-	  && TARGET_NO_TOC && ! flag_pic
+	  && TARGET_NO_TOC
+	  && ! flag_pic
 	  && mode == Pmode
 	  && CONSTANT_P (operands[1])
 	  && GET_CODE (operands[1]) != HIGH
@@ -9615,7 +9614,7 @@ rs6000_return_addr (count, frame)
   /* Currently we don't optimize very well between prolog and body
      code and for PIC code the code can be actually quite bad, so
      don't try to be too clever here.  */
-  if (count != 0 || flag_pic != 0)
+  if (count != 0 || (DEFAULT_ABI != ABI_AIX && flag_pic))
     {
       cfun->machine->ra_needs_full_frame = 1;
 
@@ -10727,7 +10726,9 @@ rs6000_emit_prologue ()
        it.  We use R11 for this purpose because emit_load_toc_table
        can use register 0.  This allows us to use a plain 'blr' to return
        from the procedure more often.  */
-    int save_LR_around_toc_setup = (TARGET_ELF && flag_pic != 0
+    int save_LR_around_toc_setup = (TARGET_ELF
+				    && DEFAULT_ABI != ABI_AIX
+				    && flag_pic
 				    && ! info->lr_save_p
 				    && EXIT_BLOCK_PTR->pred != NULL);
     if (save_LR_around_toc_setup)
@@ -12681,6 +12682,10 @@ rs6000_elf_select_section (decl, reloc, 
      int reloc;
      unsigned HOST_WIDE_INT align;
 {
+  /* Pretend that we're always building for a shared library when
+     ABI_AIX, because otherwise we end up with dynamic relocations
+     in read-only sections.  In particular, this happens for
+     references to vtables in typeinfo.  */
   default_elf_select_section_1 (decl, reloc, align,
 				flag_pic || DEFAULT_ABI == ABI_AIX);
 }
@@ -12698,10 +12703,11 @@ rs6000_elf_unique_section (decl, reloc)
      tree decl;
      int reloc;
 {
+  /* As above, pretend that we're always building for a shared library
+     when ABI_AIX, to avoid dynamic relocations in read-only sections.  */
   default_unique_section_1 (decl, reloc,
 			    flag_pic || DEFAULT_ABI == ABI_AIX);
 }
-
 
 /* If we are referencing a function that is static or is known to be
    in this file, make the SYMBOL_REF special.  We can use this to indicate
@@ -12725,7 +12731,7 @@ rs6000_elf_encode_section_info (decl, fi
       if ((*targetm.binds_local_p) (decl))
 	SYMBOL_REF_FLAG (sym_ref) = 1;
 
-      if (DEFAULT_ABI == ABI_AIX)
+      if (!TARGET_AIX && DEFAULT_ABI == ABI_AIX)
 	{
 	  size_t len1 = (DEFAULT_ABI == ABI_AIX) ? 1 : 2;
 	  size_t len2 = strlen (XSTR (sym_ref, 0));
@@ -13399,10 +13405,6 @@ rs6000_xcoff_section_type_flags (decl, n
   return flags | (exact_log2 (align) & SECTION_ENTSIZE);
 }
 
-#endif /* TARGET_XCOFF */
-
-/* Note that this is also used for PPC64 Linux.  */
-
 static void
 rs6000_xcoff_encode_section_info (decl, first)
      tree decl;
@@ -13412,18 +13414,19 @@ rs6000_xcoff_encode_section_info (decl, 
       && (*targetm.binds_local_p) (decl))
     SYMBOL_REF_FLAG (XEXP (DECL_RTL (decl), 0)) = 1;
 }
+#endif /* TARGET_XCOFF */
 
-/* Cross-module name binding.  For AIX and PPC64 Linux, which always are
-   PIC, use private copy of flag_pic.  Darwin does not support overriding
+#if TARGET_MACHO
+/* Cross-module name binding.  Darwin does not support overriding
    functions at dynamic-link time.  */
 
 static bool
 rs6000_binds_local_p (decl)
      tree decl;
 {
-  return default_binds_local_p_1 (decl, 
-	DEFAULT_ABI == ABI_DARWIN ? 0 : flag_pic || rs6000_flag_pic);
+  return default_binds_local_p_1 (decl, 0);
 }
+#endif
 
 /* Compute a (partial) cost for rtx X.  Return true if the complete
    cost has been computed, and false if subexpressions should be
diff -urp -xCVS -x'*~' gcc-rs6000.orig/gcc/config/rs6000/rs6000.h gcc-rs6000/gcc/config/rs6000/rs6000.h
--- gcc-rs6000.orig/gcc/config/rs6000/rs6000.h	2003-03-11 10:58:06.000000000 +1030
+++ gcc-rs6000/gcc/config/rs6000/rs6000.h	2003-03-11 14:27:23.000000000 +1030
@@ -2091,7 +2091,8 @@ typedef struct rs6000_args
 
 #define LEGITIMATE_LO_SUM_ADDRESS_P(MODE, X, STRICT)	\
   (TARGET_ELF						\
-   && ! flag_pic && ! TARGET_TOC			\
+   && (DEFAULT_ABI == ABI_AIX || ! flag_pic)		\
+   && ! TARGET_TOC					\
    && GET_MODE_NUNITS (MODE) == 1			\
    && (GET_MODE_BITSIZE (MODE) <= 32 			\
        || (TARGET_HARD_FLOAT && TARGET_FPRS && (MODE) == DFmode))	\
diff -urp -xCVS -x'*~' gcc-rs6000.orig/gcc/config/rs6000/sysv4.h gcc-rs6000/gcc/config/rs6000/sysv4.h
--- gcc-rs6000.orig/gcc/config/rs6000/sysv4.h	2003-02-23 16:45:33.000000000 +1030
+++ gcc-rs6000/gcc/config/rs6000/sysv4.h	2003-03-13 12:07:02.000000000 +1030
@@ -247,8 +247,9 @@ do {									\
 	     rs6000_sdata_name);					\
     }									\
 									\
-  else if (flag_pic &&							\
-	   (rs6000_sdata == SDATA_EABI || rs6000_sdata == SDATA_SYSV))	\
+  else if (flag_pic && DEFAULT_ABI != ABI_AIX				\
+	   && (rs6000_sdata == SDATA_EABI				\
+	       || rs6000_sdata == SDATA_SYSV))				\
     {									\
       rs6000_sdata = SDATA_DATA;					\
       error ("-f%s and -msdata=%s are incompatible",			\
@@ -292,7 +293,7 @@ do {									\
     }									\
 									\
   /* Treat -fPIC the same as -mrelocatable.  */				\
-  if (flag_pic > 1)							\
+  if (flag_pic > 1 && DEFAULT_ABI != ABI_AIX)				\
     target_flags |= MASK_RELOCATABLE | MASK_MINIMAL_TOC | MASK_NO_FP_IN_TOC; \
 									\
   else if (TARGET_RELOCATABLE)						\
@@ -421,7 +422,8 @@ do {									\
 
 /* Put PC relative got entries in .got2.  */
 #define	MINIMAL_TOC_SECTION_ASM_OP \
-  ((TARGET_RELOCATABLE || flag_pic) ? "\t.section\t\".got2\",\"aw\"" : "\t.section\t\".got1\",\"aw\"")
+  (TARGET_RELOCATABLE || (flag_pic && DEFAULT_ABI != ABI_AIX)		\
+   ? "\t.section\t\".got2\",\"aw\"" : "\t.section\t\".got1\",\"aw\"")
 
 #define	SDATA_SECTION_ASM_OP "\t.section\t\".sdata\",\"aw\""
 #define	SDATA2_SECTION_ASM_OP "\t.section\t\".sdata2\",\"a\""
diff -urp -xCVS -x'*~' gcc-rs6000.orig/gcc/config/rs6000/linux64.h gcc-rs6000/gcc/config/rs6000/linux64.h
--- gcc-rs6000.orig/gcc/config/rs6000/linux64.h	2003-01-06 13:59:04.000000000 +1030
+++ gcc-rs6000/gcc/config/rs6000/linux64.h	2003-03-12 21:19:50.000000000 +1030
@@ -221,9 +221,6 @@ Boston, MA 02111-1307, USA.  */
 #undef  PREFERRED_DEBUGGING_TYPE
 #define PREFERRED_DEBUGGING_TYPE DWARF2_DEBUG
 
-#undef  TARGET_ENCODE_SECTION_INFO
-#define TARGET_ENCODE_SECTION_INFO  rs6000_xcoff_encode_section_info
-
 /* This is how to output a reference to a user-level label named NAME.
    `assemble_name' uses this.  */
 


-- 
Alan Modra
IBM OzLabs - Linux Technology Centre


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]