diff options
author | H.J. Lu <hongjiu.lu@intel.com> | 2016-03-17 15:11:35 +0000 |
---|---|---|
committer | H.J. Lu <hjl@gcc.gnu.org> | 2016-03-17 08:11:35 -0700 |
commit | b57e6e182cc596dd2e346b5799b57014ced47229 (patch) | |
tree | 17ba6d251c6be7998bf2b5fdac8d60ecdc3b210c /gcc | |
parent | 91106e8435c68963f7f0a8e6bf45acb0b2a432ab (diff) | |
download | gcc-b57e6e182cc596dd2e346b5799b57014ced47229.zip gcc-b57e6e182cc596dd2e346b5799b57014ced47229.tar.gz gcc-b57e6e182cc596dd2e346b5799b57014ced47229.tar.bz2 |
Properly set flag_pie and flag_pic
We can't set flag_pie to the default when flag_pic == 0, which may be
set by -fno-pic or -fno-PIC, since the default value of flag_pie is
non-zero when GCC is configured with --enable-default-pie. We need
to initialize flag_pic to -1 so that we can tell if -fpic, -fPIC,
-fno-pic or -fno-PIC is used.
Since Darwin defaults to PIC (__PIC__ == 2) and the PIC setting can't
be changed, skip tests of default __PIC__ and __PIE__ setting for
*-*-darwin* targets.
gcc/
PR driver/70192
* opts.c (finish_options): Don't set flag_pie to the default if
-fpic, -fPIC, -fno-pic or -fno-PIC is used. Set flag_pic to 0
if it is -1.
gcc/testsuite/
PR driver/70192
* gcc.dg/pic-1.c: New test.
* gcc.dg/pic-2.c: Likewise.
* gcc.dg/pic-3.c: Likewise.
* gcc.dg/pic-4.c: Likewise.
* gcc.dg/pie-1.c: Likewise.
* gcc.dg/pie-2.c: Likewise.
* gcc.dg/pie-3.c: Likewise.
* gcc.dg/pie-4.c: Likewise.
* gcc.dg/pie-5.c: Likewise.
* gcc.dg/pie-6.c: Likewise.
From-SVN: r234295
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/common.opt | 4 | ||||
-rw-r--r-- | gcc/opts.c | 7 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 14 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pic-1.c | 10 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pic-2.c | 10 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pic-3.c | 10 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pic-4.c | 10 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pie-1.c | 10 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pie-2.c | 10 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pie-3.c | 10 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pie-4.c | 10 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pie-5.c | 10 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pie-6.c | 6 |
14 files changed, 125 insertions, 3 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d05b0da..b7711b8 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2016-03-17 H.J. Lu <hongjiu.lu@intel.com> + + PR driver/70192 + * opts.c (finish_options): Don't set flag_pie to the default if + -fpic, -fPIC, -fno-pic or -fno-PIC is used. Set flag_pic to 0 + if it is -1. + 2016-03-17 Joern Rennecke <joern.rennecke@embecosm.com> * config/i386/i386.md (*movv4qicc_insn+1..36): Pass diff --git a/gcc/common.opt b/gcc/common.opt index 1c8cc8e..67048db 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -1840,7 +1840,7 @@ Common Report Var(flag_peephole2) Optimization Enable an RTL peephole pass before sched2. fPIC -Common Report Var(flag_pic,2) Negative(fPIE) +Common Report Var(flag_pic,2) Negative(fPIE) Init(-1) Generate position-independent code if possible (large mode). fPIE @@ -1848,7 +1848,7 @@ Common Report Var(flag_pie,2) Negative(fpic) Init(-1) Generate position-independent code for executables if possible (large mode). fpic -Common Report Var(flag_pic,1) Negative(fpie) +Common Report Var(flag_pic,1) Negative(fpie) Init(-1) Generate position-independent code if possible (small mode). fpie @@ -766,13 +766,18 @@ finish_options (struct gcc_options *opts, struct gcc_options *opts_set, default value. */ if (opts->x_flag_pie == -1) { - if (opts->x_flag_pic == 0) + /* We initialize opts->x_flag_pic to -1 so that we can tell if + -fpic, -fPIC, -fno-pic or -fno-PIC is used. */ + if (opts->x_flag_pic == -1) opts->x_flag_pie = DEFAULT_FLAG_PIE; else opts->x_flag_pie = 0; } + /* If -fPIE or -fpie is used, turn on PIC. */ if (opts->x_flag_pie) opts->x_flag_pic = opts->x_flag_pie; + else if (opts->x_flag_pic == -1) + opts->x_flag_pic = 0; if (opts->x_flag_pic && !opts->x_flag_pie) opts->x_flag_shlib = 1; opts->x_flag_opts_finished = true; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 0fb3762..c59417e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,17 @@ +2016-03-17 H.J. Lu <hongjiu.lu@intel.com> + + PR driver/70192 + * gcc.dg/pic-1.c: New test. + * gcc.dg/pic-2.c: Likewise. + * gcc.dg/pic-3.c: Likewise. + * gcc.dg/pic-4.c: Likewise. + * gcc.dg/pie-1.c: Likewise. + * gcc.dg/pie-2.c: Likewise. + * gcc.dg/pie-3.c: Likewise. + * gcc.dg/pie-4.c: Likewise. + * gcc.dg/pie-5.c: Likewise. + * gcc.dg/pie-6.c: Likewise. + 2016-03-17 Tom de Vries <tom@codesourcery.com> * gfortran.dg/goacc/kernels-alias-3.f95: New test. diff --git a/gcc/testsuite/gcc.dg/pic-1.c b/gcc/testsuite/gcc.dg/pic-1.c new file mode 100644 index 0000000..86360aa --- /dev/null +++ b/gcc/testsuite/gcc.dg/pic-1.c @@ -0,0 +1,10 @@ +/* { dg-do compile { target { ! *-*-darwin* } } } */ +/* { dg-options "-fpic" } */ + +#if __PIC__ != 1 +# error __PIC__ is not 1! +#endif + +#ifdef __PIE__ +# error __PIE__ is defined! +#endif diff --git a/gcc/testsuite/gcc.dg/pic-2.c b/gcc/testsuite/gcc.dg/pic-2.c new file mode 100644 index 0000000..2c742e9 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pic-2.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-options "-fPIC" } */ + +#if __PIC__ != 2 +# error __PIC__ is not 2! +#endif + +#ifdef __PIE__ +# error __PIE__ is defined! +#endif diff --git a/gcc/testsuite/gcc.dg/pic-3.c b/gcc/testsuite/gcc.dg/pic-3.c new file mode 100644 index 0000000..7c4bbce --- /dev/null +++ b/gcc/testsuite/gcc.dg/pic-3.c @@ -0,0 +1,10 @@ +/* { dg-do compile { target { ! *-*-darwin* } } } */ +/* { dg-options "-fno-pic" } */ + +#ifdef __PIC__ +# error __PIC__ is defined! +#endif + +#ifdef __PIE__ +# error __PIE__ is defined! +#endif diff --git a/gcc/testsuite/gcc.dg/pic-4.c b/gcc/testsuite/gcc.dg/pic-4.c new file mode 100644 index 0000000..727fe14 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pic-4.c @@ -0,0 +1,10 @@ +/* { dg-do compile { target { ! *-*-darwin* } } } */ +/* { dg-options "-fno-PIC" } */ + +#ifdef __PIC__ +# error __PIC__ is defined! +#endif + +#ifdef __PIE__ +# error __PIE__ is defined! +#endif diff --git a/gcc/testsuite/gcc.dg/pie-1.c b/gcc/testsuite/gcc.dg/pie-1.c new file mode 100644 index 0000000..ca43e8b --- /dev/null +++ b/gcc/testsuite/gcc.dg/pie-1.c @@ -0,0 +1,10 @@ +/* { dg-do compile { target { ! *-*-darwin* } } } */ +/* { dg-options "-fpie" } */ + +#if __PIC__ != 1 +# error __PIC__ is not 1! +#endif + +#if __PIE__ != 1 +# error __PIE__ is not 1! +#endif diff --git a/gcc/testsuite/gcc.dg/pie-2.c b/gcc/testsuite/gcc.dg/pie-2.c new file mode 100644 index 0000000..e185e51 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pie-2.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-options "-fPIE" } */ + +#if __PIC__ != 2 +# error __PIC__ is not 2! +#endif + +#if __PIE__ != 2 +# error __PIE__ is not 2! +#endif diff --git a/gcc/testsuite/gcc.dg/pie-3.c b/gcc/testsuite/gcc.dg/pie-3.c new file mode 100644 index 0000000..0ccc56b --- /dev/null +++ b/gcc/testsuite/gcc.dg/pie-3.c @@ -0,0 +1,10 @@ +/* { dg-do compile { target { ! *-*-darwin* } } } */ +/* { dg-options "-fno-pie" } */ + +#ifdef __PIC__ +# error __PIC__ is defined! +#endif + +#ifdef __PIE__ +# error __PIE__ is defined! +#endif diff --git a/gcc/testsuite/gcc.dg/pie-4.c b/gcc/testsuite/gcc.dg/pie-4.c new file mode 100644 index 0000000..f42bad3 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pie-4.c @@ -0,0 +1,10 @@ +/* { dg-do compile { target { ! *-*-darwin* } } } */ +/* { dg-options "-fno-PIE" } */ + +#ifdef __PIC__ +# error __PIC__ is defined! +#endif + +#ifdef __PIE__ +# error __PIE__ is defined! +#endif diff --git a/gcc/testsuite/gcc.dg/pie-5.c b/gcc/testsuite/gcc.dg/pie-5.c new file mode 100644 index 0000000..d49554f --- /dev/null +++ b/gcc/testsuite/gcc.dg/pie-5.c @@ -0,0 +1,10 @@ +/* { dg-do compile { target pie_enabled } } */ +/* { dg-options "" } */ + +#ifndef __PIC__ +# error __PIC__ is not defined! +#endif + +#ifndef __PIE__ +# error __PIE__ is not defined! +#endif diff --git a/gcc/testsuite/gcc.dg/pie-6.c b/gcc/testsuite/gcc.dg/pie-6.c new file mode 100644 index 0000000..fac1e94 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pie-6.c @@ -0,0 +1,6 @@ +/* { dg-do compile { target { ! pie_enabled } } } */ +/* { dg-options "" } */ + +#ifdef __PIE__ +# error __PIE__ is defined! +#endif |