From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 102913 invoked by alias); 22 Jun 2017 15:29:09 -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 102899 invoked by uid 89); 22 Jun 2017 15:29:09 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.0 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,SPF_PASS autolearn=ham version=3.3.2 spammy=fortunately, substituted, insane, hooked X-HELO: mail-pg0-f48.google.com Received: from mail-pg0-f48.google.com (HELO mail-pg0-f48.google.com) (74.125.83.48) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 22 Jun 2017 15:29:06 +0000 Received: by mail-pg0-f48.google.com with SMTP id e187so9200628pgc.1 for ; Thu, 22 Jun 2017 08:29:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-disposition:user-agent; bh=k2MvJEOzoG8VJe9esGN2ZWBxp3h2kBI2MBcvbHtCIYg=; b=eXibklj6f6eN6ZqnzoEGJpQsMsthSO8HJJEIEdkhqP65/rNrnKfPufNoFGO4zKZh2y KsghQVy/9i3Z+tF5RGSF1By7c2Z+u2T0Z2tENapecjazVg8dVjzhcUfg/OBqKbfqM0W9 GRC3N3SRKTQW3+MNzBq24Dd9LCSpnH2T/WvX62v2Hp2CFm/4c6OEdY+CvUCtSjYclNGB OPSFhgU+MhZtQBAWHpB7Gs7h/Yz3m3y0jnzxKuM0+I18l9YxnmhConJ9K+nB0Zk5Odj1 TtzLcQJgvLKcOLpNMK5P7gyjx4mCftF3pczycQeZCr/g80BPRjOvRUGmfgeNVckEhnF8 fMuA== X-Gm-Message-State: AKS2vOxHs+Hq84jupWdQvJd72xTCAGpo7/UqTD6JxeKAR29lFJbPaMmz vpZx6YFgzQMrEi9n X-Received: by 10.84.132.14 with SMTP id 14mr3470582ple.271.1498145344415; Thu, 22 Jun 2017 08:29:04 -0700 (PDT) Received: from bubble.grove.modra.org (CPE-58-160-71-80.tyqh2.lon.bigpond.net.au. [58.160.71.80]) by smtp.gmail.com with ESMTPSA id m73sm5140714pfi.12.2017.06.22.08.29.03 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Jun 2017 08:29:03 -0700 (PDT) Received: by bubble.grove.modra.org (Postfix, from userid 1000) id BBAD5C300C; Fri, 23 Jun 2017 00:58:59 +0930 (ACST) Date: Thu, 22 Jun 2017 15:29:00 -0000 From: Alan Modra To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix pr80044, -static and -pie insanity, and pr81170 Message-ID: <20170622152859.GG8406@bubble.grove.modra.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-IsSubscribed: yes X-SW-Source: 2017-06/txt/msg01678.txt.bz2 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 "" -- Alan Modra Australia Development Lab, IBM