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