From: Matthias Klose <doko@ubuntu.com>
To: Alan Modra <amodra@gmail.com>,
gcc-patches@gcc.gnu.org,
Segher Boessenkool <segher@kernel.crashing.org>
Subject: Re: [PATCH] Fix pr80044, -static and -pie insanity, and pr81170
Date: Thu, 06 Jul 2017 13:34:00 -0000 [thread overview]
Message-ID: <b5bc0b2f-5d91-f4e2-ed58-c89d24cc9390@ubuntu.com> (raw)
In-Reply-To: <20170622152859.GG8406@bubble.grove.modra.org>
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 ""
>
>
next prev parent reply other threads:[~2017-07-06 13:34 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-22 15:29 Alan Modra
2017-06-29 13:34 ` Alan Modra
2017-07-15 12:45 ` Alan Modra
2017-07-06 13:34 ` Matthias Klose [this message]
2017-07-15 13:32 ` H.J. Lu
2017-07-17 12:33 ` Alan Modra
2017-07-17 13:01 ` H.J. Lu
2017-07-18 4:02 ` Alan Modra
2017-07-18 12:36 ` H.J. Lu
2017-07-18 14:10 ` Alan Modra
2017-07-18 14:49 ` H.J. Lu
2017-07-19 5:12 ` Alan Modra
2017-07-20 21:22 ` H.J. Lu
2017-08-28 15:44 ` Jeff Law
2017-08-29 2:35 ` Alan Modra
2017-08-29 8:39 ` Jeff Law
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b5bc0b2f-5d91-f4e2-ed58-c89d24cc9390@ubuntu.com \
--to=doko@ubuntu.com \
--cc=amodra@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=segher@kernel.crashing.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).