aboutsummaryrefslogtreecommitdiff
path: root/gcc/opts.c
diff options
context:
space:
mode:
authorH.J. Lu <hongjiu.lu@intel.com>2016-03-17 15:11:35 +0000
committerH.J. Lu <hjl@gcc.gnu.org>2016-03-17 08:11:35 -0700
commitb57e6e182cc596dd2e346b5799b57014ced47229 (patch)
tree17ba6d251c6be7998bf2b5fdac8d60ecdc3b210c /gcc/opts.c
parent91106e8435c68963f7f0a8e6bf45acb0b2a432ab (diff)
downloadgcc-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/opts.c')
-rw-r--r--gcc/opts.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/gcc/opts.c b/gcc/opts.c
index 2f45312..0f9431a 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -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;