From patchwork Thu Mar 17 15:06:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 599101 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3qQsCJ6vJbz9sR9 for ; Fri, 18 Mar 2016 02:07:08 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=bkaLt7wy; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; q=dns; s=default; b=GVjrM8YFiImVKO0es1 /XLEEPkqs8uc8m+E7BdWaxqY3LNmB87ON53gyBaLOP83wmHMUaHb/2SR5GFfnBA4 1tJWttm8ksiP2M++iuc8KhRPk9yg5/QNFG8RRmnFtF3JM7fJlIU0YJhnmIjUhdUc xSX79q6WX8WJaKN9I+stmjzLU= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; s=default; bh=bFpjRRCLv9XvsofF+QvAi3yp MLQ=; b=bkaLt7wyP92u20sxZBxk7Lg1NB73DZw3W4akIW0rYT3xl+HpIlWaoU0b 1ni02cVKJB5nZUJ15trNFU+IhYZc5nR5WUNvkUcvoklh4fORfBvSJeZeWDoQvcFm 8seDbUmFhEzabzno/tGBbMwJQ54BA21StQmD82YJh7PnbutVlV0= Received: (qmail 20018 invoked by alias); 17 Mar 2016 15:06:59 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 20003 invoked by uid 89); 17 Mar 2016 15:06:58 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=hongjiuluintelcom, hongjiu.lu@intel.com X-HELO: mail-qg0-f42.google.com Received: from mail-qg0-f42.google.com (HELO mail-qg0-f42.google.com) (209.85.192.42) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Thu, 17 Mar 2016 15:06:48 +0000 Received: by mail-qg0-f42.google.com with SMTP id w104so74187825qge.1 for ; Thu, 17 Mar 2016 08:06:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc; bh=QQzIPHUl7b+pzcuhjh/gFm7RyiPxubNlknBh8FPJp6g=; b=lEk0JZr+CtqJFCKo7XnCw8dF5T9AhOQLWHdx8TujB0ppYq0rxvkbF+Vnr2NTihHZBR Wh37AWNA73Cd67zBQjuODPiO7BgyTq0KGHwk2VAr8T0jNz+V/DXAjx4e47/8Zuqp8TUb FG/oLosBSVaLBjqg94o4UCyM39O+oBga6f31iA3pNyZogad+XWh7lhW900lN/j3mRsqi 7foLZTXaOBwjLUqbpdcoBSF3M6+Upmf9RjlPxf4Zu9kuEFhB/9qEs23BVS/975vTn26g Nt6TDS2KLER6XZ1KIvlyuu61oo9ouWBWvb/AlPylHc60u22vacqXBbMzwDqJIZOqtKpE VpTw== X-Gm-Message-State: AD7BkJLyZO3F/w4b0C5CumR1kunaWR8/wIy92RByXiokZ0GAjeFO+wXcdjbcbQR6AHjftwFdiFduNomM7JgdKA== MIME-Version: 1.0 X-Received: by 10.140.19.52 with SMTP id 49mr14820705qgg.103.1458227206020; Thu, 17 Mar 2016 08:06:46 -0700 (PDT) Received: by 10.55.15.199 with HTTP; Thu, 17 Mar 2016 08:06:45 -0700 (PDT) In-Reply-To: References: <56EABCA9.80505@redhat.com> Date: Thu, 17 Mar 2016 08:06:45 -0700 Message-ID: Subject: Re: PING: [PATCH] PR driver/70192: Properly set flag_pie and flag_pic From: "H.J. Lu" To: Bernd Schmidt Cc: GCC Patches , Joseph Myers X-IsSubscribed: yes On Thu, Mar 17, 2016 at 7:55 AM, H.J. Lu wrote: > On Thu, Mar 17, 2016 at 7:18 AM, Bernd Schmidt wrote: >> On 03/17/2016 02:59 PM, H.J. Lu wrote: >>> >>> On Fri, Mar 11, 2016 at 9:09 AM, H.J. Lu 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. > This is the patch I am going to check in. Thanks. From a19696e2f4e6f9734baa29c7833cd029eafa93fe Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Fri, 11 Mar 2016 09:02:56 -0800 Subject: [PATCH] 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. --- gcc/common.opt | 4 ++-- gcc/opts.c | 7 ++++++- gcc/testsuite/gcc.dg/pic-1.c | 10 ++++++++++ gcc/testsuite/gcc.dg/pic-2.c | 10 ++++++++++ gcc/testsuite/gcc.dg/pic-3.c | 10 ++++++++++ gcc/testsuite/gcc.dg/pic-4.c | 10 ++++++++++ gcc/testsuite/gcc.dg/pie-1.c | 10 ++++++++++ gcc/testsuite/gcc.dg/pie-2.c | 10 ++++++++++ gcc/testsuite/gcc.dg/pie-3.c | 10 ++++++++++ gcc/testsuite/gcc.dg/pie-4.c | 10 ++++++++++ gcc/testsuite/gcc.dg/pie-5.c | 10 ++++++++++ gcc/testsuite/gcc.dg/pie-6.c | 6 ++++++ 12 files changed, 104 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pic-1.c create mode 100644 gcc/testsuite/gcc.dg/pic-2.c create mode 100644 gcc/testsuite/gcc.dg/pic-3.c create mode 100644 gcc/testsuite/gcc.dg/pic-4.c create mode 100644 gcc/testsuite/gcc.dg/pie-1.c create mode 100644 gcc/testsuite/gcc.dg/pie-2.c create mode 100644 gcc/testsuite/gcc.dg/pie-3.c create mode 100644 gcc/testsuite/gcc.dg/pie-4.c create mode 100644 gcc/testsuite/gcc.dg/pie-5.c create mode 100644 gcc/testsuite/gcc.dg/pie-6.c 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 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; 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 -- 2.5.0