Blame SOURCES/gcc48-rh1555397.patch

b89248
2017-06-28  Andreas Krebbel  <krebbel@linux.vnet.ibm.com>
b89248
b89248
	* config/s390/predicates.md: Use s390_rel_address_ok_p.
b89248
	* config/s390/s390-protos.h: Add prototype of
b89248
	s390_rel_address_ok_p.
b89248
	* config/s390/s390.c (s390_got_symbol): New function.
b89248
	(s390_rel_address_ok_p): New function.
b89248
	(legitimize_pic_address): Use s390_rel_address_ok_p.
b89248
	(s390_load_got): Use s390_got_symbol.
b89248
	(s390_option_override): Issue error if
b89248
	-mno-pic-data-is-text-relative is used without -fpic/-fPIC.
b89248
	* config/s390/s390.h (TARGET_DEFAULT_PIC_DATA_IS_TEXT_RELATIVE):
b89248
	New macro.
b89248
	* config/s390/s390.opt: New option mpic-data-is-text-relative.
b89248
b89248
--- gcc/config/s390/predicates.md	2013-08-14 07:55:12.000000000 -0400
b89248
+++ gcc/config/s390/predicates.md	2018-04-09 21:36:49.428209951 -0400
b89248
@@ -116,7 +116,7 @@
b89248
   if (GET_CODE (op) == SYMBOL_REF)
b89248
     return (!SYMBOL_REF_ALIGN1_P (op)
b89248
 	    && SYMBOL_REF_TLS_MODEL (op) == 0
b89248
-	    && (!flag_pic || SYMBOL_REF_LOCAL_P (op)));
b89248
+	    && s390_rel_address_ok_p (op));
b89248
 
b89248
   /* Everything else must have a CONST, so strip it.  */
b89248
   if (GET_CODE (op) != CONST)
b89248
@@ -141,7 +141,7 @@
b89248
   if (GET_CODE (op) == SYMBOL_REF)
b89248
     return ((SYMBOL_REF_FLAGS (op) & SYMBOL_FLAG_ALIGN1) == 0
b89248
 	    && SYMBOL_REF_TLS_MODEL (op) == 0
b89248
-	    && (!flag_pic || SYMBOL_REF_LOCAL_P (op)));
b89248
+	    && s390_rel_address_ok_p (op));
b89248
 
b89248
   /* Now we must have a @GOTENT offset or @PLT stub
b89248
      or an @INDNTPOFF TLS offset.  */
b89248
--- gcc/config/s390/s390.c	2015-06-18 10:33:04.000000000 -0400
b89248
+++ gcc/config/s390/s390.c	2018-04-09 21:32:43.489851529 -0400
b89248
@@ -491,6 +491,23 @@ s390_label_align (rtx label)
b89248
   return align_labels_log;
b89248
 }
b89248
 
b89248
+static GTY(()) rtx got_symbol;
b89248
+
b89248
+/* Return the GOT table symbol.  The symbol will be created when the
b89248
+   function is invoked for the first time.  */
b89248
+
b89248
+static rtx
b89248
+s390_got_symbol (void)
b89248
+{
b89248
+  if (!got_symbol)
b89248
+    {
b89248
+      got_symbol = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_");
b89248
+      SYMBOL_REF_FLAGS (got_symbol) = SYMBOL_FLAG_LOCAL;
b89248
+    }
b89248
+
b89248
+  return got_symbol;
b89248
+}
b89248
+
b89248
 static enum machine_mode
b89248
 s390_libgcc_cmp_return_mode (void)
b89248
 {
b89248
@@ -1863,6 +1880,9 @@ s390_option_override (void)
b89248
   if (flag_prefetch_loop_arrays < 0 && HAVE_prefetch && optimize >= 3)
b89248
     flag_prefetch_loop_arrays = 1;
b89248
 
b89248
+  if (!s390_pic_data_is_text_relative && !flag_pic)
b89248
+    error ("-mno-pic-data-is-text-relative cannot be used without -fpic/-fPIC");
b89248
+
b89248
   /* Use the alternative scheduling-pressure algorithm by default.  */
b89248
   maybe_set_param_value (PARAM_SCHED_PRESSURE_ALGORITHM, 2,
b89248
                          global_options.x_param_values,
b89248
@@ -3557,6 +3577,26 @@ s390_load_address (rtx dst, rtx src)
b89248
     emit_insn (gen_force_la_31 (dst, src));
b89248
 }
b89248
 
b89248
+/* Return true if it ok to use SYMBOL_REF in a relative address.  */
b89248
+
b89248
+bool
b89248
+s390_rel_address_ok_p (rtx symbol_ref)
b89248
+{
b89248
+  tree decl;
b89248
+
b89248
+  if (symbol_ref == s390_got_symbol () || CONSTANT_POOL_ADDRESS_P (symbol_ref))
b89248
+    return true;
b89248
+
b89248
+  decl = SYMBOL_REF_DECL (symbol_ref);
b89248
+
b89248
+  if (!flag_pic || SYMBOL_REF_LOCAL_P (symbol_ref))
b89248
+    return (s390_pic_data_is_text_relative
b89248
+	    || (decl
b89248
+		&& TREE_CODE (decl) == FUNCTION_DECL));
b89248
+
b89248
+  return false;
b89248
+}
b89248
+
b89248
 /* Return a legitimate reference for ORIG (an address) using the
b89248
    register REG.  If REG is 0, a new pseudo is generated.
b89248
 
b89248
@@ -3594,7 +3634,7 @@ legitimize_pic_address (rtx orig, rtx re
b89248
     }
b89248
 
b89248
   if ((GET_CODE (addr) == LABEL_REF
b89248
-       || (GET_CODE (addr) == SYMBOL_REF && SYMBOL_REF_LOCAL_P (addr))
b89248
+       || (GET_CODE (addr) == SYMBOL_REF && s390_rel_address_ok_p (addr))
b89248
        || (GET_CODE (addr) == UNSPEC &&
b89248
 	   (XINT (addr, 1) == UNSPEC_GOTENT
b89248
 	    || (TARGET_CPU_ZARCH && XINT (addr, 1) == UNSPEC_PLT))))
b89248
@@ -8545,7 +8585,6 @@ restore_gprs (rtx base, int offset, int
b89248
 
b89248
 /* Return insn sequence to load the GOT register.  */
b89248
 
b89248
-static GTY(()) rtx got_symbol;
b89248
 rtx
b89248
 s390_load_got (void)
b89248
 {
b89248
@@ -8557,23 +8596,17 @@ s390_load_got (void)
b89248
      aren't usable.  */
b89248
   rtx got_rtx = gen_rtx_REG (Pmode, 12);
b89248
 
b89248
-  if (!got_symbol)
b89248
-    {
b89248
-      got_symbol = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_");
b89248
-      SYMBOL_REF_FLAGS (got_symbol) = SYMBOL_FLAG_LOCAL;
b89248
-    }
b89248
-
b89248
   start_sequence ();
b89248
 
b89248
   if (TARGET_CPU_ZARCH)
b89248
     {
b89248
-      emit_move_insn (got_rtx, got_symbol);
b89248
+      emit_move_insn (got_rtx, s390_got_symbol ());
b89248
     }
b89248
   else
b89248
     {
b89248
       rtx offset;
b89248
 
b89248
-      offset = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, got_symbol),
b89248
+      offset = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, s390_got_symbol ()),
b89248
 			       UNSPEC_LTREL_OFFSET);
b89248
       offset = gen_rtx_CONST (Pmode, offset);
b89248
       offset = force_const_mem (Pmode, offset);
b89248
--- gcc/config/s390/s390.h	2014-01-14 10:37:03.000000000 -0500
b89248
+++ gcc/config/s390/s390.h	2018-04-09 21:21:28.076858052 -0400
b89248
@@ -814,6 +814,10 @@ do {									\
b89248
 
b89248
 #define LEGITIMATE_PIC_OPERAND_P(X)  legitimate_pic_operand_p (X)
b89248
 
b89248
+#ifndef TARGET_DEFAULT_PIC_DATA_IS_TEXT_RELATIVE
b89248
+#define TARGET_DEFAULT_PIC_DATA_IS_TEXT_RELATIVE 1
b89248
+#endif
b89248
+
b89248
 
b89248
 /* Assembler file format.  */
b89248
 
b89248
--- gcc/config/s390/s390.opt	2015-06-18 10:33:05.000000000 -0400
b89248
+++ gcc/config/s390/s390.opt	2018-04-09 21:28:18.842465842 -0400
b89248
@@ -158,6 +158,10 @@ mzarch
b89248
 Target Report RejectNegative Negative(mesa) Mask(ZARCH)
b89248
 z/Architecture
b89248
 
b89248
+mpic-data-is-text-relative
b89248
+Target Report Var(s390_pic_data_is_text_relative) Init(TARGET_DEFAULT_PIC_DATA_IS_TEXT_RELATIVE)
b89248
+Assume data segments are relative to text segment.
b89248
+
b89248
 mbranch-cost=
b89248
 Target Report Joined RejectNegative UInteger Var(s390_branch_cost) Init(1)
b89248
 Set the branch costs for conditional branch instructions.  Reasonable
b89248
--- gcc/config/s390/s390-protos.h	2014-01-14 10:37:04.000000000 -0500
b89248
+++ gcc/config/s390/s390-protos.h	2018-04-09 21:21:28.072858046 -0400
b89248
@@ -52,6 +52,7 @@ extern bool s390_contiguous_bitmask_p (u
b89248
 extern bool s390_split_ok_p (rtx, rtx, enum machine_mode, int);
b89248
 extern bool s390_overlap_p (rtx, rtx, HOST_WIDE_INT);
b89248
 extern bool s390_offset_p (rtx, rtx, rtx);
b89248
+extern bool s390_rel_address_ok_p (rtx);
b89248
 extern int tls_symbolic_operand (rtx);
b89248
 
b89248
 extern bool s390_match_ccmode (rtx, enum machine_mode);
b89248
--- gcc/testsuite/gcc.target/s390/nodatarel-1.c	1969-12-31 19:00:00.000000000 -0500
b89248
+++ gcc/testsuite/gcc.target/s390/nodatarel-1.c	2018-04-09 21:21:28.077858053 -0400
b89248
@@ -0,0 +1,83 @@
b89248
+/* Test -mno-pic-data-is-text-relative option.  No relative addressing
b89248
+   of elements in .data and .bss are allowed with that option.  */
b89248
+
b89248
+/* { dg-do compile } */
b89248
+/* { dg-options "-O3 -fno-optimize-sibling-calls -fpic -mno-pic-data-is-text-relative -march=z10 -mtune=z9-109 -mzarch" } */
b89248
+
b89248
+static int a = 3;
b89248
+
b89248
+/* With -mno-pic-data-is-text-relative these must be addressed via
b89248
+   GOT.  */
b89248
+
b89248
+int __attribute__((noinline,noclone))
b89248
+foo ()
b89248
+{
b89248
+  return a;
b89248
+}
b89248
+
b89248
+static int __attribute__((noinline,noclone))
b89248
+foostatic (void)
b89248
+{
b89248
+  return a;
b89248
+}
b89248
+
b89248
+/* Just to make a potentially modified.  */
b89248
+
b89248
+void
b89248
+bar (int b)
b89248
+{
b89248
+  a = b;
b89248
+}
b89248
+
b89248
+/* { dg-final { scan-assembler-times "a@GOTENT" 3 } } */
b89248
+
b89248
+/* The exrl target is a label_ref which should not be affected at
b89248
+   all.  */
b89248
+
b89248
+void
b89248
+mymemcpy (char *dst, char *src, long size)
b89248
+{
b89248
+  __builtin_memcpy (dst, src, size);
b89248
+}
b89248
+
b89248
+/* { dg-final { scan-assembler "exrl" } } */
b89248
+
b89248
+
b89248
+/* PLT slots can still be addressed relatively.  */
b89248
+
b89248
+int
b89248
+callfoo ()
b89248
+{
b89248
+  return foo ();
b89248
+}
b89248
+
b89248
+/* { dg-final { scan-assembler-times "foo@PLT" 1 } } */
b89248
+
b89248
+
b89248
+/* GOT entries can still be addressed relatively.  */
b89248
+
b89248
+void *
b89248
+fooptr ()
b89248
+{
b89248
+  return &foo;
b89248
+}
b89248
+
b89248
+/* { dg-final { scan-assembler-times "foo@GOTENT" 1 } } */
b89248
+
b89248
+
b89248
+/* A static function can be addressed relatively.  */
b89248
+
b89248
+int
b89248
+callfoostatic ()
b89248
+{
b89248
+  return foostatic ();
b89248
+}
b89248
+
b89248
+void *
b89248
+foostaticptr ()
b89248
+{
b89248
+  return &foostatic;
b89248
+}
b89248
+
b89248
+
b89248
+/* { dg-final { scan-assembler-not "foostatic@" } } */