On Thu, Mar 17, 2016 at 7:18 AM, Bernd Schmidt <bschm...@redhat.com> wrote: > On 03/17/2016 02:59 PM, H.J. Lu wrote: >> >> On Fri, Mar 11, 2016 at 9:09 AM, H.J. Lu <hongjiu...@intel.com> wrote: >>> >>> 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. > > >>> 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. > > > I think this part is ok. > >>> 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 > > > In normal code that should probably use the "__PIC__ - 0" trick to guard > against cases where the macro isn't defined, but I suppose we'd be getting > an error in that case as well. > > >>> diff --git a/gcc/testsuite/gcc.dg/pie-3.c b/gcc/testsuite/gcc.dg/pie-3.c >>> new file mode 100644 >>> index 0000000..fe46c98 >>> --- /dev/null >>> +++ b/gcc/testsuite/gcc.dg/pie-3.c >>> @@ -0,0 +1,10 @@ >>> +/* { dg-do compile } */ >>> +/* { 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..977baf0 >>> --- /dev/null >>> +++ b/gcc/testsuite/gcc.dg/pie-4.c >>> @@ -0,0 +1,10 @@ >>> +/* { dg-do compile } */ >>> +/* { 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-6.c b/gcc/testsuite/gcc.dg/pie-6.c >>> new file mode 100644 >>> index 0000000..85529a8 >>> --- /dev/null >>> +++ b/gcc/testsuite/gcc.dg/pie-6.c >>> @@ -0,0 +1,10 @@ >>> +/* { dg-do compile { target { ! pie_enabled } } } */ >>> +/* { dg-options "" } */ >>> + >>> +#ifdef __PIC__ >>> +# error __PIC__ is defined! >>> +#endif >>> + >>> +#ifdef __PIE__ >>> +# error __PIE__ is defined! >>> +#endif > > These I'm not so sure about. I could imagine there are targets where pic is > the default. I'd remove these tests or the test for __PIC__. So, ok with > that change.
Darwin is such a target. Here is a follow-up patch I was planning to submit. But I will remove __PIC__ instead. -- H.J.
From ff1ef6e4e969b244984d1ae4c93960e36edd1334 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" <hjl.to...@gmail.com> Date: Fri, 11 Mar 2016 09:24:41 -0800 Subject: [PATCH] Skip some PIC/PIE tests for *-*-darwin* targets Since Darwin defaults to PIC, not PIE, skip tests of default __PIC__ and __PIE__ setting for *-*-darwin* targets. * gcc.dg/pic-1.c: Skip for *-*-darwin* targets. * gcc.dg/pic-3.c: Likewise. * gcc.dg/pic-4.c: Likewise. * gcc.dg/pie-1.c: Likewise. * gcc.dg/pie-3.c: Likewise. * gcc.dg/pie-4.c: Likewise. * gcc.dg/pie-6.c: Likewise. --- gcc/testsuite/gcc.dg/pic-1.c | 2 +- gcc/testsuite/gcc.dg/pic-3.c | 2 +- gcc/testsuite/gcc.dg/pic-4.c | 2 +- gcc/testsuite/gcc.dg/pie-1.c | 2 +- gcc/testsuite/gcc.dg/pie-3.c | 2 +- gcc/testsuite/gcc.dg/pie-4.c | 2 +- gcc/testsuite/gcc.dg/pie-6.c | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/gcc/testsuite/gcc.dg/pic-1.c b/gcc/testsuite/gcc.dg/pic-1.c index 7eb0765..86360aa 100644 --- a/gcc/testsuite/gcc.dg/pic-1.c +++ b/gcc/testsuite/gcc.dg/pic-1.c @@ -1,4 +1,4 @@ -/* { dg-do compile } */ +/* { dg-do compile { target { ! *-*-darwin* } } } */ /* { dg-options "-fpic" } */ #if __PIC__ != 1 diff --git a/gcc/testsuite/gcc.dg/pic-3.c b/gcc/testsuite/gcc.dg/pic-3.c index d7d861b..7c4bbce 100644 --- a/gcc/testsuite/gcc.dg/pic-3.c +++ b/gcc/testsuite/gcc.dg/pic-3.c @@ -1,4 +1,4 @@ -/* { dg-do compile } */ +/* { dg-do compile { target { ! *-*-darwin* } } } */ /* { dg-options "-fno-pic" } */ #ifdef __PIC__ diff --git a/gcc/testsuite/gcc.dg/pic-4.c b/gcc/testsuite/gcc.dg/pic-4.c index 732f61f..727fe14 100644 --- a/gcc/testsuite/gcc.dg/pic-4.c +++ b/gcc/testsuite/gcc.dg/pic-4.c @@ -1,4 +1,4 @@ -/* { dg-do compile } */ +/* { dg-do compile { target { ! *-*-darwin* } } } */ /* { dg-options "-fno-PIC" } */ #ifdef __PIC__ diff --git a/gcc/testsuite/gcc.dg/pie-1.c b/gcc/testsuite/gcc.dg/pie-1.c index ff6281f..ca43e8b 100644 --- a/gcc/testsuite/gcc.dg/pie-1.c +++ b/gcc/testsuite/gcc.dg/pie-1.c @@ -1,4 +1,4 @@ -/* { dg-do compile } */ +/* { dg-do compile { target { ! *-*-darwin* } } } */ /* { dg-options "-fpie" } */ #if __PIC__ != 1 diff --git a/gcc/testsuite/gcc.dg/pie-3.c b/gcc/testsuite/gcc.dg/pie-3.c index fe46c98..0ccc56b 100644 --- a/gcc/testsuite/gcc.dg/pie-3.c +++ b/gcc/testsuite/gcc.dg/pie-3.c @@ -1,4 +1,4 @@ -/* { dg-do compile } */ +/* { dg-do compile { target { ! *-*-darwin* } } } */ /* { dg-options "-fno-pie" } */ #ifdef __PIC__ diff --git a/gcc/testsuite/gcc.dg/pie-4.c b/gcc/testsuite/gcc.dg/pie-4.c index 977baf0..f42bad3 100644 --- a/gcc/testsuite/gcc.dg/pie-4.c +++ b/gcc/testsuite/gcc.dg/pie-4.c @@ -1,4 +1,4 @@ -/* { dg-do compile } */ +/* { dg-do compile { target { ! *-*-darwin* } } } */ /* { dg-options "-fno-PIE" } */ #ifdef __PIC__ diff --git a/gcc/testsuite/gcc.dg/pie-6.c b/gcc/testsuite/gcc.dg/pie-6.c index 85529a8..99bf36c 100644 --- a/gcc/testsuite/gcc.dg/pie-6.c +++ b/gcc/testsuite/gcc.dg/pie-6.c @@ -1,4 +1,4 @@ -/* { dg-do compile { target { ! pie_enabled } } } */ +/* { dg-do compile { target { { ! *-*-darwin* } && { ! pie_enabled } } } } */ /* { dg-options "" } */ #ifdef __PIC__ -- 2.5.0