From: Andreas Krebbel Date: Wed, 28 Jun 2017 07:03:35 +0000 (+0000) Subject: S/390: New option -mpic-data-is-text-relative X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=935b5226c385e34088c314374cbbe9e4995b9e44;p=gcc.git S/390: New option -mpic-data-is-text-relative For hotpatching it might be required to introduce new .text parts while keep using the existing .data/.bss sections. To make this work the backend needs to be prevented from using relative addressing between code and data. This only works when already building PIC since the addressing will then be handling via GOT. gcc/testsuite/ChangeLog: 2017-06-28 Andreas Krebbel * gcc.target/s390/nodatarel-1.c: New test. gcc/ChangeLog: 2017-06-28 Andreas Krebbel * config/s390/predicates.md: Use s390_rel_address_ok_p. * config/s390/s390-protos.h: Add prototype of s390_rel_address_ok_p. * config/s390/s390.c (s390_got_symbol): New function. (s390_rel_address_ok_p): New function. (legitimize_pic_address): Use s390_rel_address_ok_p. (s390_load_got): Use s390_got_symbol. (s390_option_override): Issue error if -mno-pic-data-is-text-relative is used without -fpic/-fPIC. * config/s390/s390.h (TARGET_DEFAULT_PIC_DATA_IS_TEXT_RELATIVE): New macro. * config/s390/s390.opt: New option mpic-data-is-text-relative. From-SVN: r249720 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index f52d1b92a23..48c81b3a9c2 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,18 @@ +2017-06-28 Andreas Krebbel + + * config/s390/predicates.md: Use s390_rel_address_ok_p. + * config/s390/s390-protos.h: Add prototype of + s390_rel_address_ok_p. + * config/s390/s390.c (s390_got_symbol): New function. + (s390_rel_address_ok_p): New function. + (legitimize_pic_address): Use s390_rel_address_ok_p. + (s390_load_got): Use s390_got_symbol. + (s390_option_override): Issue error if + -mno-pic-data-is-text-relative is used without -fpic/-fPIC. + * config/s390/s390.h (TARGET_DEFAULT_PIC_DATA_IS_TEXT_RELATIVE): + New macro. + * config/s390/s390.opt: New option mpic-data-is-text-relative. + 2017-06-27 Andrew Pinski * match.pd (X >/>=/= 3) flag_prefetch_loop_arrays = 1; + if (!s390_pic_data_is_text_relative && !flag_pic) + error ("-mno-pic-data-is-text-relative cannot be used without -fpic/-fPIC"); + if (TARGET_TPF) { /* Don't emit DWARF3/4 unless specifically selected. The TPF diff --git a/gcc/config/s390/s390.h b/gcc/config/s390/s390.h index a372981ff3a..7847047d160 100644 --- a/gcc/config/s390/s390.h +++ b/gcc/config/s390/s390.h @@ -946,6 +946,10 @@ CUMULATIVE_ARGS; #define LEGITIMATE_PIC_OPERAND_P(X) legitimate_pic_operand_p (X) +#ifndef TARGET_DEFAULT_PIC_DATA_IS_TEXT_RELATIVE +#define TARGET_DEFAULT_PIC_DATA_IS_TEXT_RELATIVE 1 +#endif + /* Assembler file format. */ diff --git a/gcc/config/s390/s390.opt b/gcc/config/s390/s390.opt index d0a0d46b0a7..f277ac55eff 100644 --- a/gcc/config/s390/s390.opt +++ b/gcc/config/s390/s390.opt @@ -226,3 +226,7 @@ values are small, non-negative integers. The default branch cost is mlra Target Report Var(s390_lra_flag) Init(1) Save Use LRA instead of reload. + +mpic-data-is-text-relative +Target Report Var(s390_pic_data_is_text_relative) Init(TARGET_DEFAULT_PIC_DATA_IS_TEXT_RELATIVE) +Assume data segments are relative to text segment. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 46879b7998d..4ed5542d495 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2017-06-28 Andreas Krebbel + + * gcc.target/s390/nodatarel-1.c: New test. + 2017-06-27 Jerry DeLisle PR fortran/80164 diff --git a/gcc/testsuite/gcc.target/s390/nodatarel-1.c b/gcc/testsuite/gcc.target/s390/nodatarel-1.c new file mode 100644 index 00000000000..1d589a10947 --- /dev/null +++ b/gcc/testsuite/gcc.target/s390/nodatarel-1.c @@ -0,0 +1,83 @@ +/* Test -mno-pic-data-is-text-relative option. No relative addressing + of elements in .data and .bss are allowed with that option. */ + +/* { dg-do compile } */ +/* { dg-options "-O3 -fno-optimize-sibling-calls -fpic -mno-pic-data-is-text-relative -march=z10 -mtune=z9-109 -mzarch" } */ + +static int a = 3; + +/* With -mno-pic-data-is-text-relative these must be addressed via + GOT. */ + +int __attribute__((noinline,noclone)) +foo () +{ + return a; +} + +static int __attribute__((noinline,noclone)) +foostatic (void) +{ + return a; +} + +/* Just to make a potentially modified. */ + +void +bar (int b) +{ + a = b; +} + +/* { dg-final { scan-assembler-times "a@GOTENT" 3 } } */ + +/* The exrl target is a label_ref which should not be affected at + all. */ + +void +mymemcpy (char *dst, char *src, long size) +{ + __builtin_memcpy (dst, src, size); +} + +/* { dg-final { scan-assembler "exrl" } } */ + + +/* PLT slots can still be addressed relatively. */ + +int +callfoo () +{ + return foo (); +} + +/* { dg-final { scan-assembler-times "foo@PLT" 1 } } */ + + +/* GOT entries can still be addressed relatively. */ + +void * +fooptr () +{ + return &foo; +} + +/* { dg-final { scan-assembler-times "foo@GOTENT" 1 } } */ + + +/* A static function can be addressed relatively. */ + +int +callfoostatic () +{ + return foostatic (); +} + +void * +foostaticptr () +{ + return &foostatic; +} + + +/* { dg-final { scan-assembler-not "foostatic@" } } */