From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4894 invoked by alias); 6 Jul 2017 13:34:18 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 4878 invoked by uid 89); 6 Jul 2017 13:34:17 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.1 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy=Upgrade, H*Ad:D*ubuntu.com, fortunately, H*Ad:U*doko X-HELO: einhorn-mail.in-berlin.de Received: from einhorn-mail.in-berlin.de (HELO einhorn-mail.in-berlin.de) (217.197.80.20) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 06 Jul 2017 13:34:15 +0000 X-Envelope-From: doko@ubuntu.com Received: from [192.168.178.26] (ip5f5bd694.dynamic.kabel-deutschland.de [95.91.214.148]) (authenticated bits=0) by einhorn.in-berlin.de (8.14.4/8.14.4/Debian-8+deb8u2) with ESMTP id v66DYCXP031943 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 6 Jul 2017 15:34:13 +0200 Subject: Re: [PATCH] Fix pr80044, -static and -pie insanity, and pr81170 To: Alan Modra , gcc-patches@gcc.gnu.org, Segher Boessenkool References: <20170622152859.GG8406@bubble.grove.modra.org> From: Matthias Klose Message-ID: Date: Thu, 06 Jul 2017 13:34:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.1 MIME-Version: 1.0 In-Reply-To: <20170622152859.GG8406@bubble.grove.modra.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-SW-Source: 2017-07/txt/msg00327.txt.bz2 As seen in PR81295, the bootstrap is broken on powerpc-linux-gnu with --enable-default-pie. Using that patch the bootstrap succeeds. The bootstrap works fine on both powerpc64 be and le targets. Matthias On 22.06.2017 17:28, Alan Modra wrote: > PR80044 notes that -static and -pie together behave differently when > gcc is configured with --enable-default-pie as compared to configuring > without (or --disable-default-pie). This patch removes that > difference. In both cases you now will have -static completely > overriding -pie. > > Fixing this wasn't quite as simple as you'd expect, due to poor > separation of functionality. PIE_SPEC didn't just mean that -pie was > on explicitly or by default, but also -r and -shared were *not* on. > Fortunately the three files touched by this patch are the only places > PIE_SPEC and NO_PIE_SPEC are used, so it isn't too hard to see that > the reason PIE_SPEC and NO_PIE_SPEC are not inverses is the use of > PIE_SPEC in LINK_PIE_SPEC. So, move the inelegant symmetry breaking > addition, to LINK_PIE_SPEC where it belongs. Doing that showed > another problem in gnu-user.h, with PIE_SPEC and NO_PIE_SPEC selection > of crtbegin*.o not properly hooked into a chain of if .. elseif .. > conditions, which required both PIE_SPEC and NO_PIE_SPEC to exclude > -static and -shared. Fixing that particular problem finally allows > PIE_SPEC to serve just one purpose, and NO_PIE_SPEC to disappear. > > Bootstrapped and regression tested powerpc64le-linux c,c++. No > regressions and a bunch of --enable-default-pie failures squashed. > OK mainline and active branches? > > Incidentally, there is a fairly strong case to be made for adding > -static to the -shared, -pie, -no-pie chain of RejectNegative's in > common.opt. Since git 0d6378a9e (svn r48039) 2001-11-15, -static has > done more than just the traditional "prevent linking with dynamic > libraries", as -static selects crtbeginT.o rather than crtbegin.o > on GNU systems. Realizing this is what led me to close pr80044, which > I'd opened with the aim of making -pie -static work together (with the > traditional meaning of -static). I don't that is worth doing, but > mention pr80044 in the changelog due to fixing the insane output > produced by -pie -static with --disable-default-pie. > > PR driver/80044 > PR target/81170 > * 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. > * config/rs6000/sysv4.h (STARTFILE_LINUX_SPEC): Upgrade to > match gnu-user.h startfile. > (ENDFILE_LINUX_SPEC): Similarly. > > diff --git a/gcc/config/gnu-user.h b/gcc/config/gnu-user.h > index 2787a3d..de605b0 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 1ae7f9f..bc53a1c 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 6d724b2..625fae1 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 > diff --git a/gcc/config/rs6000/sysv4.h b/gcc/config/rs6000/sysv4.h > index de38629..c80fcea 100644 > --- a/gcc/config/rs6000/sysv4.h > +++ b/gcc/config/rs6000/sysv4.h > @@ -757,24 +757,61 @@ ENDIAN_SELECT(" -mbig", " -mlittle", DEFAULT_ASM_ENDIAN) > #define CRTOFFLOADEND "" > #endif > > +/* STARTFILE_LINUX_SPEC should be the same as GNU_USER_TARGET_STARTFILE_SPEC > + but with the mnewlib ecrti.o%s selection substituted for crti.o%s. */ > #ifdef HAVE_LD_PIE > -#define STARTFILE_LINUX_SPEC "\ > -%{!shared: %{pg|p|profile:gcrt1.o%s;pie:Scrt1.o%s;:crt1.o%s}} \ > -%{mnewlib:ecrti.o%s;:crti.o%s} \ > -%{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s} \ > -" CRTOFFLOADBEGIN > +#define STARTFILE_LINUX_SPEC \ > + "%{shared:; \ > + pg|p|profile:gcrt1.o%s; \ > + static:crt1.o%s; \ > + " PIE_SPEC ":Scrt1.o%s; \ > + :crt1.o%s} \ > + %{mnewlib:ecrti.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 STARTFILE_LINUX_SPEC "\ > -%{!shared: %{pg|p|profile:gcrt1.o%s;:crt1.o%s}} \ > -%{mnewlib:ecrti.o%s;:crti.o%s} \ > -%{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s} \ > -" CRTOFFLOADBEGIN > +#define STARTFILE_LINUX_SPEC \ > + "%{shared:; \ > + pg|p|profile:gcrt1.o%s; \ > + :crt1.o%s} \ > + %{mnewlib:ecrti.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} \ > + " CRTOFFLOADBEGIN > #endif > > -#define ENDFILE_LINUX_SPEC "\ > -%{shared|pie:crtendS.o%s;:crtend.o%s} \ > -%{mnewlib:ecrtn.o%s;:crtn.o%s} \ > -" CRTOFFLOADEND > +/* ENDFILE_LINUX_SPEC should be the same as GNU_USER_TARGET_ENDFILE_SPEC > + but with the mnewlib ecrtn.o%s selection substituted for crtn.o%s. */ > +#if defined HAVE_LD_PIE > +#define ENDFILE_LINUX_SPEC \ > + "%{fvtable-verify=none:%s; \ > + fvtable-verify=preinit:vtv_end_preinit.o%s; \ > + fvtable-verify=std:vtv_end.o%s} \ > + %{static:crtend.o%s; \ > + shared|" PIE_SPEC ":crtendS.o%s; \ > + :crtend.o%s} \ > + %{mnewlib:ecrtn.o%s;:crtn.o%s} \ > + " CRTOFFLOADEND > +#else > +#define ENDFILE_LINUX_SPEC \ > + "%{fvtable-verify=none:%s; \ > + fvtable-verify=preinit:vtv_end_preinit.o%s; \ > + fvtable-verify=std:vtv_end.o%s} \ > + %{static:crtend.o%s; \ > + shared|pie:crtendS.o%s; \ > + :crtend.o%s} \ > + %{mnewlib:ecrtn.o%s;:crtn.o%s} \ > + " CRTOFFLOADEND > +#endif > > #define LINK_START_LINUX_SPEC "" > >