PING: [PATCH] PR driver/70192: Properly set flag_pie and flag_pic

H.J. Lu hjl.tools@gmail.com
Thu Mar 17 15:00:00 GMT 2016


On Thu, Mar 17, 2016 at 7:18 AM, Bernd Schmidt <bschmidt@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.lu@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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Skip-some-PIC-PIE-tests-for-darwin-targets.patch
Type: text/x-patch
Size: 3153 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20160317/7bceb6ba/attachment.bin>


More information about the Gcc-patches mailing list