From patchwork Tue Aug 1 02:04:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 796043 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-459448-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="YDeM6P00"; dkim-atps=neutral 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 3xM05T1vKDz9tWX for ; Tue, 1 Aug 2017 12:05:16 +1000 (AEST) 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:from:date:message-id :subject:to:cc:content-type; q=dns; s=default; b=NOA6gqthRPPaLMP UZJ7564YSt7z0XouiejRvRHa/u63uLrkN8L8vk3xUd9On7DCukl3K4q1kv99jSo+ hIVwBjXilVA0iow+SgBo4qjMzEeJEotBW6IalI6vOxML+wb39LAn4RTk/+iNImSS CVGgTUmUeSI3siAKX5Tw6R4rwAEQ= 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:from:date:message-id :subject:to:cc:content-type; s=default; bh=Xj+cjx1CnbyhEOwisD/HR IwAkZk=; b=YDeM6P00CAE7UZzhOctQVPnYOvHgduB34Gg6IK6TFGWBrStlbDIaB PiCFrCT2uTkj6kCxUGITXOKouQDikxUpsMqiI1LmqK8FUbVFvhwfKQIUd5oBcD2x cUHFeES6pXR5JIQJwstBqS/8gc2Sx3ykvWwKIu6dYw9LJWQ1f9HCGE= Received: (qmail 116436 invoked by alias); 1 Aug 2017 02:05:06 -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 110863 invoked by uid 89); 1 Aug 2017 02:05:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.9 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-oi0-f67.google.com Received: from mail-oi0-f67.google.com (HELO mail-oi0-f67.google.com) (209.85.218.67) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 01 Aug 2017 02:04:58 +0000 Received: by mail-oi0-f67.google.com with SMTP id s21so341595oie.5 for ; Mon, 31 Jul 2017 19:04:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=3eNn0ZUsMdsqzxm4D4L9FdGcybshAjQvR9E+yOX1iro=; b=ELEXWnN1cJDzaFX17vgMJ/SqGQk1IX4rHwOYMbl/ibQmYOclNSFVBKeQ9nMavOwtzR be/MnRf08BFPHo0Fxx1dj80srkx8+N/POzpbBmieja3HQziO5nNDq/D/NgpzPzxUTlef lfGsIdXDrDBm+wYxKEtU1nCfvEC61pT1p3CAtpb4hjqhgxyMw+rFEOBqgEnLZiCZFMhl 9HsJ5ugCz/jLzMTPyT2Y1W032m22mh7r1aIpbPmo3T0PFS3aLQ0I+5eDhexaVHkT4QI2 Ryw5/obFnhx9NDrykazG89EJ36MzfJRaMM8dXxqOXZXlODH08jenXaDjXi7XcQU88kDR 7EDw== X-Gm-Message-State: AIVw113ZUuiIcfZtfud9BwpNTGRMTVMpFDV1DlHa3i3ptYKIG5hekXEL xSYrO1PQd3ZUYxS5bnN+WY0PFmLkSA== X-Received: by 10.202.192.84 with SMTP id q81mr33833oif.88.1501553097151; Mon, 31 Jul 2017 19:04:57 -0700 (PDT) MIME-Version: 1.0 Received: by 10.74.169.200 with HTTP; Mon, 31 Jul 2017 19:04:56 -0700 (PDT) In-Reply-To: <20170801003717.GL1956@bubble.grove.modra.org> References: <20170801003717.GL1956@bubble.grove.modra.org> From: "H.J. Lu" Date: Mon, 31 Jul 2017 19:04:56 -0700 Message-ID: Subject: Re: PING: [PATCH] PR driver/81523: Make -static override -pie To: Alan Modra Cc: GCC Patches , "Joseph S. Myers" X-IsSubscribed: yes On Mon, Jul 31, 2017 at 5:37 PM, Alan Modra wrote: > On Mon, Jul 31, 2017 at 08:04:13AM -0700, H.J. Lu wrote: >> On Mon, Jul 24, 2017 at 10:24 AM, H.J. Lu wrote: >> > On Sun, Jul 23, 2017 at 8:14 AM, H.J. Lu wrote: >> >> -static and -pie together behave differently depending on whether GCC is >> >> configured with --enable-default-pie. On x86, "-static -pie" fails to >> >> create executable when --enable-default-pie isn't used, but creates a >> >> static executable when --enable-default-pie is used. This patch makes >> >> -static completely override -pie to create a static executable, regardless >> >> if --enable-default-pie is used to configure GCC. >> >> >> >> OK for master? >> >> >> >> H.J. >> >> -- >> >> 2017-07-23 Alan Modra >> >> H.J. Lu >> >> >> >> gcc/ >> >> >> >> PR driver/81523 >> >> * gcc.c (NO_PIE_SPEC): Delete. >> >> (PIE_SPEC): Define as !no-pie/pie. Move static|shared|r >> >> exclusion.. >> >> (LINK_PIE_SPEC): ..to here. >> >> * config/gnu-user.h (GNU_USER_TARGET_STARTFILE_SPEC): Correct >> >> chain of crtbegin*.o selection, update for PIE_SPEC changes and >> >> format. >> >> (GNU_USER_TARGET_ENDFILE_SPEC): Similarly. >> >> * config/sol2.h (STARTFILE_CRTBEGIN_SPEC): Similarly. >> >> (ENDFILE_CRTEND_SPEC): Similarly. >> >> >> > >> > We need to add %{no-pie:} to LINK_COMMAND_SPEC to prevent an error >> > message when PIE isn't enabled by default. Here is the updated patch with >> > a testcase. >> > >> >> PING. I am enclosing the patch here. > > For anyone looking at this, the patch enclosed here is mine from > https://gcc.gnu.org/ml/gcc-patches/2017-06/msg01678.html minus some PR > numbers and the powerpc specific part, plus testsuite (which looks to > me like HJ copied pie-static-1.c to pie-static-2.c then forgot to > change the order of -pie and -static), plus a tweak to > LINK_COMMAND_SPEC. The LINK_COMMAND_SPEC change looks good to me, > except for the comment which doesn't exactly match the code. That > change is necessary because I ignorantly removed %{no-pie:} from > LINK_PIE_SPEC without adding it back elsewhere. Here is the updated patch. From a2ed5b4c96978fba81423e562cdcb4b85c8cf9cc Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Thu, 20 Jul 2017 09:57:36 -0700 Subject: [PATCH] PR driver/81523: Make -static override -pie -static and -pie together behave differently depending on whether GCC is configured with --enable-default-pie. On x86, "-static -pie" fails to create executable when --enable-default-pie isn't used, but creates a static executable when --enable-default-pie is used. This patch makes -static completely override -pie to create a static executable, regardless if --enable-default-pie is used to configure GCC. 2017-07-24 Alan Modra H.J. Lu gcc/ PR driver/81523 * gcc.c (NO_PIE_SPEC): Delete. (PIE_SPEC): Define as !no-pie/pie. Move static|shared|r exclusion.. (LINK_PIE_SPEC): ..to here. (LINK_COMMAND_SPEC): Support -no-pie. * config/gnu-user.h (GNU_USER_TARGET_STARTFILE_SPEC): Correct chain of crtbegin*.o selection, update for PIE_SPEC changes and format. (GNU_USER_TARGET_ENDFILE_SPEC): Similarly. * config/sol2.h (STARTFILE_CRTBEGIN_SPEC): Similarly. (ENDFILE_CRTEND_SPEC): Similarly. gcc/testsuite/ PR driver/81523 * gcc.dg/pie-7.c: New test. * gcc.dg/pie-static-1.c: Likewise. * gcc.dg/pie-static-2.c: Likewise. --- gcc/config/gnu-user.h | 34 ++++++++++++++++++++++++---------- gcc/config/sol2.h | 12 ++++++------ gcc/gcc.c | 14 +++++++------- gcc/testsuite/gcc.dg/pie-7.c | 7 +++++++ gcc/testsuite/gcc.dg/pie-static-1.c | 7 +++++++ gcc/testsuite/gcc.dg/pie-static-2.c | 7 +++++++ 6 files changed, 58 insertions(+), 23 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pie-7.c create mode 100644 gcc/testsuite/gcc.dg/pie-static-1.c create mode 100644 gcc/testsuite/gcc.dg/pie-static-2.c diff --git a/gcc/config/gnu-user.h b/gcc/config/gnu-user.h index 2787a3d16be..de605b0c466 100644 --- a/gcc/config/gnu-user.h +++ b/gcc/config/gnu-user.h @@ -50,19 +50,28 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #if defined HAVE_LD_PIE #define GNU_USER_TARGET_STARTFILE_SPEC \ - "%{!shared: %{pg|p|profile:gcrt1.o%s;: \ - %{" PIE_SPEC ":Scrt1.o%s} %{" NO_PIE_SPEC ":crt1.o%s}}} \ - crti.o%s %{static:crtbeginT.o%s;: %{shared:crtbeginS.o%s} \ - %{" PIE_SPEC ":crtbeginS.o%s} \ - %{" NO_PIE_SPEC ":crtbegin.o%s}} \ + "%{shared:; \ + pg|p|profile:gcrt1.o%s; \ + static:crt1.o%s; \ + " PIE_SPEC ":Scrt1.o%s; \ + :crt1.o%s} \ + crti.o%s \ + %{static:crtbeginT.o%s; \ + shared|" PIE_SPEC ":crtbeginS.o%s; \ + :crtbegin.o%s} \ %{fvtable-verify=none:%s; \ fvtable-verify=preinit:vtv_start_preinit.o%s; \ fvtable-verify=std:vtv_start.o%s} \ " CRTOFFLOADBEGIN #else #define GNU_USER_TARGET_STARTFILE_SPEC \ - "%{!shared: %{pg|p|profile:gcrt1.o%s;:crt1.o%s}} \ - crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s} \ + "%{shared:; \ + pg|p|profile:gcrt1.o%s; \ + :crt1.o%s} \ + crti.o%s \ + %{static:crtbeginT.o%s; \ + shared|pie:crtbeginS.o%s; \ + :crtbegin.o%s} \ %{fvtable-verify=none:%s; \ fvtable-verify=preinit:vtv_start_preinit.o%s; \ fvtable-verify=std:vtv_start.o%s} \ @@ -82,15 +91,20 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see "%{fvtable-verify=none:%s; \ fvtable-verify=preinit:vtv_end_preinit.o%s; \ fvtable-verify=std:vtv_end.o%s} \ - %{shared:crtendS.o%s;: %{" PIE_SPEC ":crtendS.o%s} \ - %{" NO_PIE_SPEC ":crtend.o%s}} crtn.o%s \ + %{static:crtend.o%s; \ + shared|" PIE_SPEC ":crtendS.o%s; \ + :crtend.o%s} \ + crtn.o%s \ " CRTOFFLOADEND #else #define GNU_USER_TARGET_ENDFILE_SPEC \ "%{fvtable-verify=none:%s; \ fvtable-verify=preinit:vtv_end_preinit.o%s; \ fvtable-verify=std:vtv_end.o%s} \ - %{shared|pie:crtendS.o%s;:crtend.o%s} crtn.o%s \ + %{static:crtend.o%s; \ + shared|pie:crtendS.o%s; \ + :crtend.o%s} \ + crtn.o%s \ " CRTOFFLOADEND #endif #undef ENDFILE_SPEC diff --git a/gcc/config/sol2.h b/gcc/config/sol2.h index b8398d082a9..bf5203b8c16 100644 --- a/gcc/config/sol2.h +++ b/gcc/config/sol2.h @@ -174,9 +174,9 @@ along with GCC; see the file COPYING3. If not see %{!ansi:values-Xa.o%s}" #if defined(HAVE_LD_PIE) && defined(HAVE_SOLARIS_CRTS) -#define STARTFILE_CRTBEGIN_SPEC "%{shared:crtbeginS.o%s} \ - %{" PIE_SPEC ":crtbeginS.o%s} \ - %{" NO_PIE_SPEC ":crtbegin.o%s}" +#define STARTFILE_CRTBEGIN_SPEC "%{static:crtbegin.o%s; \ + shared|" PIE_SPEC ":crtbeginS.o%s; \ + :crtbegin.o%s}" #else #define STARTFILE_CRTBEGIN_SPEC "crtbegin.o%s" #endif @@ -224,9 +224,9 @@ along with GCC; see the file COPYING3. If not see #endif #if defined(HAVE_LD_PIE) && defined(HAVE_SOLARIS_CRTS) -#define ENDFILE_CRTEND_SPEC "%{shared:crtendS.o%s;: \ - %{" PIE_SPEC ":crtendS.o%s} \ - %{" NO_PIE_SPEC ":crtend.o%s}}" +#define ENDFILE_CRTEND_SPEC "%{static:crtend.o%s; \ + shared|" PIE_SPEC ":crtendS.o%s; \ + :crtend.o%s}" #else #define ENDFILE_CRTEND_SPEC "crtend.o%s" #endif diff --git a/gcc/gcc.c b/gcc/gcc.c index d8c5260e36b..987eff55aa6 100644 --- a/gcc/gcc.c +++ b/gcc/gcc.c @@ -878,8 +878,7 @@ proper position among the other output files. */ #endif #ifdef ENABLE_DEFAULT_PIE -#define NO_PIE_SPEC "no-pie|static" -#define PIE_SPEC NO_PIE_SPEC "|r|shared:;" +#define PIE_SPEC "!no-pie" #define NO_FPIE1_SPEC "fno-pie" #define FPIE1_SPEC NO_FPIE1_SPEC ":;" #define NO_FPIE2_SPEC "fno-PIE" @@ -900,7 +899,6 @@ proper position among the other output files. */ #define FPIE_OR_FPIC_SPEC NO_FPIE_AND_FPIC_SPEC ":;" #else #define PIE_SPEC "pie" -#define NO_PIE_SPEC PIE_SPEC "|r|shared:;" #define FPIE1_SPEC "fpie" #define NO_FPIE1_SPEC FPIE1_SPEC ":;" #define FPIE2_SPEC "fPIE" @@ -929,7 +927,7 @@ proper position among the other output files. */ #else #define LD_PIE_SPEC "" #endif -#define LINK_PIE_SPEC "%{no-pie:} " "%{" PIE_SPEC ":" LD_PIE_SPEC "} " +#define LINK_PIE_SPEC "%{static|shared|r:;" PIE_SPEC ":" LD_PIE_SPEC "} " #endif #ifndef LINK_BUILDID_SPEC @@ -1017,8 +1015,10 @@ proper position among the other output files. */ #endif /* -u* was put back because both BSD and SysV seem to support it. */ -/* %{static:} simply prevents an error message if the target machine - doesn't handle -static. */ +/* %{static|no-pie:} simply prevents an error message: + 1. If the target machine doesn't handle -static. + 2. If PIE isn't enabled by default. + */ /* We want %{T*} after %{L*} and %D so that it can be used to specify linker scripts which exist in user specified directories, or in standard directories. */ @@ -1035,7 +1035,7 @@ proper position among the other output files. */ "%{fuse-ld=*:-fuse-ld=%*} " LINK_COMPRESS_DEBUG_SPEC \ "%X %{o*} %{e*} %{N} %{n} %{r}\ %{s} %{t} %{u*} %{z} %{Z} %{!nostdlib:%{!nostartfiles:%S}} \ - %{static:} %{L*} %(mfwrap) %(link_libgcc) " \ + %{static|no-pie:} %{L*} %(mfwrap) %(link_libgcc) " \ VTABLE_VERIFICATION_SPEC " " SANITIZER_EARLY_SPEC " %o " CHKP_SPEC " \ %{fopenacc|fopenmp|%:gt(%{ftree-parallelize-loops=*:%*} 1):\ %:include(libgomp.spec)%(link_gomp)}\ diff --git a/gcc/testsuite/gcc.dg/pie-7.c b/gcc/testsuite/gcc.dg/pie-7.c new file mode 100644 index 00000000000..e118a98bafd --- /dev/null +++ b/gcc/testsuite/gcc.dg/pie-7.c @@ -0,0 +1,7 @@ +/* { dg-do run { target pie } } */ +/* { dg-options "-fno-pie -no-pie" } */ + +int main(void) +{ + return 0; +} diff --git a/gcc/testsuite/gcc.dg/pie-static-1.c b/gcc/testsuite/gcc.dg/pie-static-1.c new file mode 100644 index 00000000000..f3580efdfe6 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pie-static-1.c @@ -0,0 +1,7 @@ +/* { dg-do run { target pie } } */ +/* { dg-options "-static -fpie -pie" } */ + +int main(void) +{ + return 0; +} diff --git a/gcc/testsuite/gcc.dg/pie-static-2.c b/gcc/testsuite/gcc.dg/pie-static-2.c new file mode 100644 index 00000000000..49608c5fb2a --- /dev/null +++ b/gcc/testsuite/gcc.dg/pie-static-2.c @@ -0,0 +1,7 @@ +/* { dg-do run { target pie } } */ +/* { dg-options "-fpie -pie -static" } */ + +int main(void) +{ + return 0; +} -- 2.13.3