[PATCH] Enable -mpcrel on PowerPC -mcpu=future ELF v2 systems, V3

Michael Meissner meissner@linux.ibm.com
Fri Apr 3 00:36:59 GMT 2020


Enable -mpcrel on PowerPC -mcpu=future ELF v2 systems, V3

This patch changes the default for -mcpu=future to be -mpcrel (i.e. use
PC-relative addressing) if the ABI allows PC-relative relocations and the user
did not use either -mno-pcrel or -mno-prefixed.

I have changed the spelling of the macro to PCREL_SUPPORTED_BY_ABI (from
PCREL_SUPPORTED_BY_OS) since you pointed out it is more properly a function of
the particular ABI, rather than just an OS choice.  I have changed the various
comments to make it clearer.

I have done a bootstrap and a make check with and without the patch and there
were no regressions by adding the patch on a little endian PowerPC Linux
system.

I also tested by hand that if I use:

	-mcpu=power9
	-mcpu=future -mno-prefixed
	-mcpu=future -mno-pcrel
	-mcpu=future -mabi=elfv1	(or)
	-mcpu=future -mcmodel=large

that PC-relative addressing is not enabled by default.  Variants of this patch
have been used since December, building power8/power9 code on big endian
systems, and power8/power9/future on little endian systems.  Can I check this
into the master branch?

2020-04-02  Michael Meissner  <meissner@linux.ibm.com>

	* config/rs6000/linux64.h (PCREL_SUPPORTED_BY_ABI): Enable
	prefixed PC-relative addressing if the ABI supports it.
	* config/rs6000/rs6000-cpus.def (ISA_FUTURE_MASKS_SERVER): Do not
	set OPTION_MASK_FUTURE here.
	* config/rs6000/rs6000.c (rs6000_option_override_internal): Enable
	OPTION_MASK_PREFIXED and OPTION_MASK_PREFIXED on -mcpu=future by
	default if the current ABI allows the options.

--- /tmp/IPB30g_linux64.h	2020-04-02 15:23:19.977060411 -0500
+++ gcc/config/rs6000/linux64.h	2020-04-02 15:23:01.016474023 -0500
@@ -640,3 +640,11 @@ extern int dot_symbols;
    enabling the __float128 keyword.  */
 #undef	TARGET_FLOAT128_ENABLE_TYPE
 #define TARGET_FLOAT128_ENABLE_TYPE 1
+
+/* Enable using prefixed PC-relative addressing on the 'future' machine if the
+   ABI supports it.  The ELF v2 ABI only supports PC-relative relocations for
+   the medium code model.  */
+#undef  PCREL_SUPPORTED_BY_ABI
+#define PCREL_SUPPORTED_BY_ABI	(TARGET_FUTURE && TARGET_PREFIXED	\
+				 && ELFv2_ABI_CHECK			\
+				 && (TARGET_CMODEL == CMODEL_MEDIUM))
--- /tmp/EHqpAk_rs6000-cpus.def	2020-04-02 15:23:19.993064282 -0500
+++ gcc/config/rs6000/rs6000-cpus.def	2020-04-02 15:23:01.016474023 -0500
@@ -75,11 +75,11 @@
 				 | OPTION_MASK_P8_VECTOR		\
 				 | OPTION_MASK_P9_VECTOR)
 
-/* Support for a future processor's features.  Do not enable -mpcrel until it
-   is fully functional.  */
+/* Support for a future processor's features.  We do not set the addressing
+   options OPTION_MASK_PREFIXED or OPTION_MASK_PCREL here.  Those options are
+   enabled in the function rs6000_option_override if the ABI supports them.  */
 #define ISA_FUTURE_MASKS_SERVER	(ISA_3_0_MASKS_SERVER			\
-				 | OPTION_MASK_FUTURE			\
-				 | OPTION_MASK_PREFIXED)
+				 | OPTION_MASK_FUTURE)
 
 /* Flags that need to be turned off if -mno-future.  */
 #define OTHER_FUTURE_MASKS	(OPTION_MASK_PCREL			\
--- /tmp/Zayhhc_rs6000.c	2020-04-02 15:23:20.009068153 -0500
+++ gcc/config/rs6000/rs6000.c	2020-04-02 15:23:01.020474991 -0500
@@ -4020,6 +4020,11 @@ rs6000_option_override_internal (bool gl
       rs6000_isa_flags &= ~OPTION_MASK_FLOAT128_HW;
     }
 
+  /* Enable -mprefixed by default on 64-bit 'future' systems.  */
+  if (TARGET_FUTURE && TARGET_POWERPC64
+      && (rs6000_isa_flags_explicit & OPTION_MASK_PREFIXED) == 0)
+    rs6000_isa_flags |= OPTION_MASK_PREFIXED;
+
   /* -mprefixed (and hence -mpcrel) requires -mcpu=future.  */
   if (TARGET_PREFIXED && !TARGET_FUTURE)
     {
@@ -4181,6 +4186,14 @@ rs6000_option_override_internal (bool gl
       rs6000_isa_flags &= ~OPTION_MASK_PCREL;
     }
 
+#ifdef PCREL_SUPPORTED_BY_ABI
+  /* If the ABI has support for PC-relative relocations, enable it by
+     default.  */
+  if (PCREL_SUPPORTED_BY_ABI
+      && (rs6000_isa_flags_explicit & OPTION_MASK_PCREL) == 0)
+    rs6000_isa_flags |= OPTION_MASK_PCREL;
+#endif
+
   if (TARGET_DEBUG_REG || TARGET_DEBUG_TARGET)
     rs6000_print_isa_options (stderr, 0, "after subtarget", rs6000_isa_flags);
 

-- 
Michael Meissner, IBM
IBM, M/S 2506R, 550 King Street, Littleton, MA 01460-6245, USA
email: meissner@linux.ibm.com, phone: +1 (978) 899-4797


More information about the Gcc-patches mailing list