* [PATCH] Fix pr80044, -static and -pie insanity, and pr81170 @ 2017-06-22 15:29 Alan Modra 2017-06-29 13:34 ` Alan Modra ` (3 more replies) 0 siblings, 4 replies; 16+ messages in thread From: Alan Modra @ 2017-06-22 15:29 UTC (permalink / raw) To: gcc-patches 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 ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH] Fix pr80044, -static and -pie insanity, and pr81170 2017-06-22 15:29 [PATCH] Fix pr80044, -static and -pie insanity, and pr81170 Alan Modra @ 2017-06-29 13:34 ` Alan Modra 2017-07-15 12:45 ` Alan Modra 2017-07-06 13:34 ` Matthias Klose ` (2 subsequent siblings) 3 siblings, 1 reply; 16+ messages in thread From: Alan Modra @ 2017-06-29 13:34 UTC (permalink / raw) To: gcc-patches Ping? Linux startfile and endfile specs. https://gcc.gnu.org/ml/gcc-patches/2017-06/msg01678.html -- Alan Modra Australia Development Lab, IBM ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH] Fix pr80044, -static and -pie insanity, and pr81170 2017-06-29 13:34 ` Alan Modra @ 2017-07-15 12:45 ` Alan Modra 0 siblings, 0 replies; 16+ messages in thread From: Alan Modra @ 2017-07-15 12:45 UTC (permalink / raw) To: gcc-patches On Thu, Jun 29, 2017 at 11:03:56PM +0930, Alan Modra wrote: > Ping? Linux startfile and endfile specs. > https://gcc.gnu.org/ml/gcc-patches/2017-06/msg01678.html 3 week ping. Also fixes PR81295. -- Alan Modra Australia Development Lab, IBM ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH] Fix pr80044, -static and -pie insanity, and pr81170 2017-06-22 15:29 [PATCH] Fix pr80044, -static and -pie insanity, and pr81170 Alan Modra 2017-06-29 13:34 ` Alan Modra @ 2017-07-06 13:34 ` Matthias Klose 2017-07-15 13:32 ` H.J. Lu 2017-08-28 15:44 ` Jeff Law 3 siblings, 0 replies; 16+ messages in thread From: Matthias Klose @ 2017-07-06 13:34 UTC (permalink / raw) To: Alan Modra, gcc-patches, Segher Boessenkool 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 "" > > ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH] Fix pr80044, -static and -pie insanity, and pr81170 2017-06-22 15:29 [PATCH] Fix pr80044, -static and -pie insanity, and pr81170 Alan Modra 2017-06-29 13:34 ` Alan Modra 2017-07-06 13:34 ` Matthias Klose @ 2017-07-15 13:32 ` H.J. Lu 2017-07-17 12:33 ` Alan Modra 2017-08-28 15:44 ` Jeff Law 3 siblings, 1 reply; 16+ messages in thread From: H.J. Lu @ 2017-07-15 13:32 UTC (permalink / raw) To: Alan Modra; +Cc: GCC Patches On Thu, Jun 22, 2017 at 8:28 AM, Alan Modra <amodra@gmail.com> 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. > On x86-64, without --enable-default-pie, "-static -pie" and "-pie -static" never worked since both -static and -pie are passed to linker, which uses libc.a to build PIE. With --enable-default-pie, -static and -pie override each other. What does your patch do on x86-64? Make with and without --enable-default-pie behave the same? Does it mean that both fail to create executable? -- H.J. ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH] Fix pr80044, -static and -pie insanity, and pr81170 2017-07-15 13:32 ` H.J. Lu @ 2017-07-17 12:33 ` Alan Modra 2017-07-17 13:01 ` H.J. Lu 0 siblings, 1 reply; 16+ messages in thread From: Alan Modra @ 2017-07-17 12:33 UTC (permalink / raw) To: H.J. Lu; +Cc: GCC Patches On Sat, Jul 15, 2017 at 06:32:40AM -0700, H.J. Lu wrote: > On Thu, Jun 22, 2017 at 8:28 AM, Alan Modra <amodra@gmail.com> 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. > > > > On x86-64, without --enable-default-pie, "-static -pie" and "-pie -static" > never worked since both -static and -pie are passed to linker, which > uses libc.a to build PIE. Yes, it's broken. > With --enable-default-pie, -static and -pie > override each other. No they don't. -static overrides -pie. > What does your patch do on x86-64? Make > with and without --enable-default-pie behave the same? Yes, as I said in my original post first paragraph. > Does it > mean that both fail to create executable? I try to leave that sort of patch to those better qualified. Bootstrap and regression testing on x86_64-linux both --enable-default-pie and --disable-default-pie was complete June 23. -- Alan Modra Australia Development Lab, IBM ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH] Fix pr80044, -static and -pie insanity, and pr81170 2017-07-17 12:33 ` Alan Modra @ 2017-07-17 13:01 ` H.J. Lu 2017-07-18 4:02 ` Alan Modra 0 siblings, 1 reply; 16+ messages in thread From: H.J. Lu @ 2017-07-17 13:01 UTC (permalink / raw) To: Alan Modra; +Cc: GCC Patches On Mon, Jul 17, 2017 at 5:33 AM, Alan Modra <amodra@gmail.com> wrote: > On Sat, Jul 15, 2017 at 06:32:40AM -0700, H.J. Lu wrote: >> On Thu, Jun 22, 2017 at 8:28 AM, Alan Modra <amodra@gmail.com> 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. >> > >> >> On x86-64, without --enable-default-pie, "-static -pie" and "-pie -static" >> never worked since both -static and -pie are passed to linker, which >> uses libc.a to build PIE. > > Yes, it's broken. This behavior may be useful for static PIE when libc.a is compiled with -fPIE. >> With --enable-default-pie, -static and -pie >> override each other. > > No they don't. -static overrides -pie. > >> What does your patch do on x86-64? Make >> with and without --enable-default-pie behave the same? > > Yes, as I said in my original post first paragraph. > >> Does it >> mean that both fail to create executable? > > I try to leave that sort of patch to those better qualified. > Bootstrap and regression testing on x86_64-linux both > --enable-default-pie and --disable-default-pie was complete June 23. > What is the new behavior? The old --disable-default-pie or old --enable-default-pie? Will static PIE be supported if libc is compiled with -fPIE by default? -- H.J. ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH] Fix pr80044, -static and -pie insanity, and pr81170 2017-07-17 13:01 ` H.J. Lu @ 2017-07-18 4:02 ` Alan Modra 2017-07-18 12:36 ` H.J. Lu 0 siblings, 1 reply; 16+ messages in thread From: Alan Modra @ 2017-07-18 4:02 UTC (permalink / raw) To: H.J. Lu; +Cc: GCC Patches On Mon, Jul 17, 2017 at 06:01:47AM -0700, H.J. Lu wrote: > On Mon, Jul 17, 2017 at 5:33 AM, Alan Modra <amodra@gmail.com> wrote: > > On Sat, Jul 15, 2017 at 06:32:40AM -0700, H.J. Lu wrote: > >> On Thu, Jun 22, 2017 at 8:28 AM, Alan Modra <amodra@gmail.com> 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. > >> > > >> > >> On x86-64, without --enable-default-pie, "-static -pie" and "-pie -static" > >> never worked since both -static and -pie are passed to linker, which > >> uses libc.a to build PIE. > > > > Yes, it's broken. > > This behavior may be useful for static PIE when libc.a is compiled with > -fPIE. Building a PIE from static archives using -static -pie or -pie -static right now is broken, even if the archives are compiled -fpie/PIE. I've looked into fixing it, and decided it wasn't worth the effort. There are multiple problems. See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80044#c1 One reason why I believe it isn't worth fixing is that the meaning of -static has changed over the years, from "link using static archives" to "produce a static executable", and most certainly the meaning of -static and -pie together is not clear. I'll cite gold behaviour as evidence: -static with -pie results in an error from gold. See https://sourceware.org/ml/binutils/2012-02/msg00119.html and following discussion. > >> With --enable-default-pie, -static and -pie > >> override each other. > > > > No they don't. -static overrides -pie. > > > >> What does your patch do on x86-64? Make > >> with and without --enable-default-pie behave the same? > > > > Yes, as I said in my original post first paragraph. > > > >> Does it > >> mean that both fail to create executable? > > > > I try to leave that sort of patch to those better qualified. > > Bootstrap and regression testing on x86_64-linux both > > --enable-default-pie and --disable-default-pie was complete June 23. > > > > What is the new behavior? The old --disable-default-pie or old > --enable-default-pie? You are asking questions to which the answer is given in the very first paragraph posted in this thread, if you knew the current --enable-default-pie behaviour. -static overrides -pie. ie. current --enable-default-pie behaviour is unchanged. > Will static PIE be supported if libc is > compiled with -fPIE by default? I covered this above, if you're asking about -static and -pie together. Unsupported both before and after my patch. You *can* link a working PIE from -fPIE archives, if that is what you want, with "-pie -Wl,-Bstatic", both before and after my patch. I'll ask a question of you. Have you reviewed the patch and found anything wrong with it? -- Alan Modra Australia Development Lab, IBM ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH] Fix pr80044, -static and -pie insanity, and pr81170 2017-07-18 4:02 ` Alan Modra @ 2017-07-18 12:36 ` H.J. Lu 2017-07-18 14:10 ` Alan Modra 0 siblings, 1 reply; 16+ messages in thread From: H.J. Lu @ 2017-07-18 12:36 UTC (permalink / raw) To: Alan Modra; +Cc: GCC Patches On Mon, Jul 17, 2017 at 9:02 PM, Alan Modra <amodra@gmail.com> wrote: > On Mon, Jul 17, 2017 at 06:01:47AM -0700, H.J. Lu wrote: >> On Mon, Jul 17, 2017 at 5:33 AM, Alan Modra <amodra@gmail.com> wrote: >> > On Sat, Jul 15, 2017 at 06:32:40AM -0700, H.J. Lu wrote: >> >> On Thu, Jun 22, 2017 at 8:28 AM, Alan Modra <amodra@gmail.com> 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. >> >> > >> >> >> >> On x86-64, without --enable-default-pie, "-static -pie" and "-pie -static" >> >> never worked since both -static and -pie are passed to linker, which >> >> uses libc.a to build PIE. >> > >> > Yes, it's broken. >> >> This behavior may be useful for static PIE when libc.a is compiled with >> -fPIE. > > Building a PIE from static archives using -static -pie or -pie -static > right now is broken, even if the archives are compiled -fpie/PIE. > I've looked into fixing it, and decided it wasn't worth the effort. > There are multiple problems. See > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80044#c1 > > One reason why I believe it isn't worth fixing is that the meaning of > -static has changed over the years, from "link using static archives" > to "produce a static executable", and most certainly the meaning of > -static and -pie together is not clear. I'll cite gold behaviour as > evidence: -static with -pie results in an error from gold. See > https://sourceware.org/ml/binutils/2012-02/msg00119.html and following > discussion. > >> >> With --enable-default-pie, -static and -pie >> >> override each other. >> > >> > No they don't. -static overrides -pie. >> > >> >> What does your patch do on x86-64? Make >> >> with and without --enable-default-pie behave the same? >> > >> > Yes, as I said in my original post first paragraph. >> > >> >> Does it >> >> mean that both fail to create executable? >> > >> > I try to leave that sort of patch to those better qualified. >> > Bootstrap and regression testing on x86_64-linux both >> > --enable-default-pie and --disable-default-pie was complete June 23. >> > >> >> What is the new behavior? The old --disable-default-pie or old >> --enable-default-pie? > > You are asking questions to which the answer is given in the very > first paragraph posted in this thread, if you knew the current > --enable-default-pie behaviour. -static overrides -pie. ie. current > --enable-default-pie behaviour is unchanged. > >> Will static PIE be supported if libc is >> compiled with -fPIE by default? > > I covered this above, if you're asking about -static and -pie > together. Unsupported both before and after my patch. You *can* link > a working PIE from -fPIE archives, if that is what you want, with > "-pie -Wl,-Bstatic", both before and after my patch. I am working on compiling libc.a in glibc with -fPIE and building static PIE. This creates static executable with PIE: gcc -nostdlib -nostartfiles -static -o /export/build/gnu/glibc-static-pie/build-x86_64-linux/elf/sln -pie -Wl,--no-dynamic-linker /export/build/gnu/glibc-static-pie/build-x86_64-linux/csu/crt1.o /export/build/gnu/glibc-static-pie/build-x86_64-linux/csu/crti.o `gcc --print-file-name=crtbeginS.o` /export/build/gnu/glibc-static-pie/build-x86_64-linux/elf/sln.o /export/build/gnu/glibc-static-pie/build-x86_64-linux/elf/static-stubs.o -Wl,--start-group /export/build/gnu/glibc-static-pie/build-x86_64-linux/libc.a -lgcc -Wl,--end-group `gcc --print-file-name=crtendS.o` /export/build/gnu/glibc-static-pie/build-x86_64-linux/csu/crtn.o Currently, it only works with gcc configured with -disable-default-pie. With --enable-default-pie, I got [hjl@gnu-tools-1 build-x86_64-linux]$ /usr/gcc-7.1.1-x32-pie/bin/gcc -nostdlib -nostartfiles -static -o /tmp/sln -pie -Wl,--no-dynamic-linker /export/build/gnu/glibc-static-pie/build-x86_64-linux/csu/crt1.o /export/build/gnu/glibc-static-pie/build-x86_64-linux/csu/crti.o `gcc --print-file-name=crtbeginS.o` /export/build/gnu/glibc-static-pie/build-x86_64-linux/elf/sln.o /export/build/gnu/glibc-static-pie/build-x86_64-linux/elf/static-stubs.o -Wl,--start-group /export/build/gnu/glibc-static-pie/build-x86_64-linux/libc.a -lgcc -Wl,--end-group `gcc --print-file-name=crtendS.o` /export/build/gnu/glibc-static-pie/build-x86_64-linux/csu/crtn.o /export/build/gnu/glibc-static-pie/build-x86_64-linux/libc.a(dl-support.o): In function `elf_machine_load_address': /export/gnu/import/git/sources/glibc/elf/../sysdeps/x86_64/dl-machine.h:59: undefined reference to `_DYNAMIC' /export/build/gnu/glibc-static-pie/build-x86_64-linux/libc.a(dl-support.o): In function `elf_get_dynamic_info': /export/gnu/import/git/sources/glibc/elf/get-dynamic-info.h:48: undefined reference to `_DYNAMIC' collect2: error: ld returned 1 exit status [hjl@gnu-tools-1 build-x86_64-linux]$ Will your change fix it? -- H.J. ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH] Fix pr80044, -static and -pie insanity, and pr81170 2017-07-18 12:36 ` H.J. Lu @ 2017-07-18 14:10 ` Alan Modra 2017-07-18 14:49 ` H.J. Lu 0 siblings, 1 reply; 16+ messages in thread From: Alan Modra @ 2017-07-18 14:10 UTC (permalink / raw) To: H.J. Lu; +Cc: GCC Patches On Tue, Jul 18, 2017 at 05:36:49AM -0700, H.J. Lu wrote: > I am working on compiling libc.a in glibc with -fPIE and building static > PIE. This creates static executable with PIE: > > gcc -nostdlib -nostartfiles -static -o > /export/build/gnu/glibc-static-pie/build-x86_64-linux/elf/sln -pie > -Wl,--no-dynamic-linker > /export/build/gnu/glibc-static-pie/build-x86_64-linux/csu/crt1.o > /export/build/gnu/glibc-static-pie/build-x86_64-linux/csu/crti.o `gcc > --print-file-name=crtbeginS.o` > /export/build/gnu/glibc-static-pie/build-x86_64-linux/elf/sln.o > /export/build/gnu/glibc-static-pie/build-x86_64-linux/elf/static-stubs.o > -Wl,--start-group > /export/build/gnu/glibc-static-pie/build-x86_64-linux/libc.a -lgcc > -Wl,--end-group `gcc --print-file-name=crtendS.o` > /export/build/gnu/glibc-static-pie/build-x86_64-linux/csu/crtn.o > > Currently, it only works with gcc configured with -disable-default-pie. > With --enable-default-pie, I got > > [hjl@gnu-tools-1 build-x86_64-linux]$ /usr/gcc-7.1.1-x32-pie/bin/gcc > -nostdlib -nostartfiles -static -o /tmp/sln -pie > -Wl,--no-dynamic-linker > /export/build/gnu/glibc-static-pie/build-x86_64-linux/csu/crt1.o > /export/build/gnu/glibc-static-pie/build-x86_64-linux/csu/crti.o `gcc > --print-file-name=crtbeginS.o` > /export/build/gnu/glibc-static-pie/build-x86_64-linux/elf/sln.o > /export/build/gnu/glibc-static-pie/build-x86_64-linux/elf/static-stubs.o > -Wl,--start-group > /export/build/gnu/glibc-static-pie/build-x86_64-linux/libc.a -lgcc > -Wl,--end-group `gcc --print-file-name=crtendS.o` > /export/build/gnu/glibc-static-pie/build-x86_64-linux/csu/crtn.o > /export/build/gnu/glibc-static-pie/build-x86_64-linux/libc.a(dl-support.o): > In function `elf_machine_load_address': > /export/gnu/import/git/sources/glibc/elf/../sysdeps/x86_64/dl-machine.h:59: > undefined reference to `_DYNAMIC' > /export/build/gnu/glibc-static-pie/build-x86_64-linux/libc.a(dl-support.o): > In function `elf_get_dynamic_info': > /export/gnu/import/git/sources/glibc/elf/get-dynamic-info.h:48: > undefined reference to `_DYNAMIC' > collect2: error: ld returned 1 exit status > [hjl@gnu-tools-1 build-x86_64-linux]$ > > Will your change fix it? You have got to be joking! How should I know whether something will work with some hare-brained scheme of yours? One that seemingly requires you to specify startup files by hand! -- Alan Modra Australia Development Lab, IBM ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH] Fix pr80044, -static and -pie insanity, and pr81170 2017-07-18 14:10 ` Alan Modra @ 2017-07-18 14:49 ` H.J. Lu 2017-07-19 5:12 ` Alan Modra 0 siblings, 1 reply; 16+ messages in thread From: H.J. Lu @ 2017-07-18 14:49 UTC (permalink / raw) To: Alan Modra; +Cc: GCC Patches On Tue, Jul 18, 2017 at 7:09 AM, Alan Modra <amodra@gmail.com> wrote: > On Tue, Jul 18, 2017 at 05:36:49AM -0700, H.J. Lu wrote: >> I am working on compiling libc.a in glibc with -fPIE and building static >> PIE. This creates static executable with PIE: >> >> gcc -nostdlib -nostartfiles -static -o >> /export/build/gnu/glibc-static-pie/build-x86_64-linux/elf/sln -pie >> -Wl,--no-dynamic-linker >> /export/build/gnu/glibc-static-pie/build-x86_64-linux/csu/crt1.o >> /export/build/gnu/glibc-static-pie/build-x86_64-linux/csu/crti.o `gcc >> --print-file-name=crtbeginS.o` >> /export/build/gnu/glibc-static-pie/build-x86_64-linux/elf/sln.o >> /export/build/gnu/glibc-static-pie/build-x86_64-linux/elf/static-stubs.o >> -Wl,--start-group >> /export/build/gnu/glibc-static-pie/build-x86_64-linux/libc.a -lgcc >> -Wl,--end-group `gcc --print-file-name=crtendS.o` >> /export/build/gnu/glibc-static-pie/build-x86_64-linux/csu/crtn.o >> >> Currently, it only works with gcc configured with -disable-default-pie. >> With --enable-default-pie, I got >> >> [hjl@gnu-tools-1 build-x86_64-linux]$ /usr/gcc-7.1.1-x32-pie/bin/gcc >> -nostdlib -nostartfiles -static -o /tmp/sln -pie >> -Wl,--no-dynamic-linker >> /export/build/gnu/glibc-static-pie/build-x86_64-linux/csu/crt1.o >> /export/build/gnu/glibc-static-pie/build-x86_64-linux/csu/crti.o `gcc >> --print-file-name=crtbeginS.o` >> /export/build/gnu/glibc-static-pie/build-x86_64-linux/elf/sln.o >> /export/build/gnu/glibc-static-pie/build-x86_64-linux/elf/static-stubs.o >> -Wl,--start-group >> /export/build/gnu/glibc-static-pie/build-x86_64-linux/libc.a -lgcc >> -Wl,--end-group `gcc --print-file-name=crtendS.o` >> /export/build/gnu/glibc-static-pie/build-x86_64-linux/csu/crtn.o >> /export/build/gnu/glibc-static-pie/build-x86_64-linux/libc.a(dl-support.o): >> In function `elf_machine_load_address': >> /export/gnu/import/git/sources/glibc/elf/../sysdeps/x86_64/dl-machine.h:59: >> undefined reference to `_DYNAMIC' >> /export/build/gnu/glibc-static-pie/build-x86_64-linux/libc.a(dl-support.o): >> In function `elf_get_dynamic_info': >> /export/gnu/import/git/sources/glibc/elf/get-dynamic-info.h:48: >> undefined reference to `_DYNAMIC' >> collect2: error: ld returned 1 exit status >> [hjl@gnu-tools-1 build-x86_64-linux]$ >> >> Will your change fix it? > > You have got to be joking! How should I know whether something will > work with some hare-brained scheme of yours? One that seemingly > requires you to specify startup files by hand! > The difference is with --enable-default-pie, the gcc driver doesn't pass both -pie and -static ld when "-static -pie" is used. Does your change pass both -pie and -static ld when "-static -pie" is used? -- H.J. ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH] Fix pr80044, -static and -pie insanity, and pr81170 2017-07-18 14:49 ` H.J. Lu @ 2017-07-19 5:12 ` Alan Modra 2017-07-20 21:22 ` H.J. Lu 0 siblings, 1 reply; 16+ messages in thread From: Alan Modra @ 2017-07-19 5:12 UTC (permalink / raw) To: Joseph Myers, H.J. Lu; +Cc: GCC Patches On Tue, Jul 18, 2017 at 07:49:48AM -0700, H.J. Lu wrote: > The difference is with --enable-default-pie, the gcc driver doesn't pass > both -pie and -static ld when "-static -pie" is used. Does your change > pass both -pie and -static ld when "-static -pie" is used? Again, as I said in the original post: "In both cases you now will have -static completely overriding -pie". That means "gcc -pie -static" and "gcc -static -pie" just pass "-static" to ld, and select the appropriate startup files for a static executable, when configured with --disable-default-pie. Which is what happens currently for --enable-default-pie. None of this is rocket science. I know what I'm doing where the linker and startup files are concerned, and I'm comfortable with the gcc specs language. The patch is simple! It should be easy to review, except for trying to understand the "-" lines. Yet it has sat unreviewed for nearly four weeks. And it fixes a powerpc --enable-default-pie bootstrap failure (pr81295). Joseph, would you please take a look? https://gcc.gnu.org/ml/gcc-patches/2017-06/msg01678.html I know there is more to do in this area, for example, it seems to me that the HAVE_LD_PIE definition of GNU_USER_TARGET_STARTFILE_SPEC is good for !HAVE_LD_PIE, and similarly for GNU_USE_TARGET_ENDFILE_SPEC. And yes, I propagated that duplication into rs6000/sysv4.h, which needs some serious tidying. rs6000/sysv4.h linux support ought to be using the gnu-user.h defines rather than copying them, something I've told Segher I'll look at after this patch goes in. -- Alan Modra Australia Development Lab, IBM ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH] Fix pr80044, -static and -pie insanity, and pr81170 2017-07-19 5:12 ` Alan Modra @ 2017-07-20 21:22 ` H.J. Lu 0 siblings, 0 replies; 16+ messages in thread From: H.J. Lu @ 2017-07-20 21:22 UTC (permalink / raw) To: Alan Modra; +Cc: Joseph Myers, GCC Patches [-- Attachment #1: Type: text/plain, Size: 2124 bytes --] On Tue, Jul 18, 2017 at 10:11 PM, Alan Modra <amodra@gmail.com> wrote: > On Tue, Jul 18, 2017 at 07:49:48AM -0700, H.J. Lu wrote: >> The difference is with --enable-default-pie, the gcc driver doesn't pass >> both -pie and -static ld when "-static -pie" is used. Does your change >> pass both -pie and -static ld when "-static -pie" is used? > > Again, as I said in the original post: "In both cases you now will > have -static completely overriding -pie". > > That means "gcc -pie -static" and "gcc -static -pie" just pass > "-static" to ld, and select the appropriate startup files for a static > executable, when configured with --disable-default-pie. Which is what > happens currently for --enable-default-pie. > > None of this is rocket science. I know what I'm doing where the > linker and startup files are concerned, and I'm comfortable with the > gcc specs language. The patch is simple! It should be easy to > review, except for trying to understand the "-" lines. Yet it has sat > unreviewed for nearly four weeks. And it fixes a powerpc > --enable-default-pie bootstrap failure (pr81295). > > Joseph, would you please take a look? > https://gcc.gnu.org/ml/gcc-patches/2017-06/msg01678.html > > I know there is more to do in this area, for example, it seems to me > that the HAVE_LD_PIE definition of GNU_USER_TARGET_STARTFILE_SPEC is > good for !HAVE_LD_PIE, and similarly for GNU_USE_TARGET_ENDFILE_SPEC. > And yes, I propagated that duplication into rs6000/sysv4.h, which > needs some serious tidying. rs6000/sysv4.h linux support ought to be > using the gnu-user.h defines rather than copying them, something I've > told Segher I'll look at after this patch goes in. > Before your patch, I can creating static PIE when GCC is configured with --disable-default-pie. After your change, both --enable-default-pie and --disable-default-pie prevent creating static PIE. I opened a bug report for -static-pie: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81498 This patch, which should be applied on top of your patch, adds support for -static-pie. Can we merge 2 patches into 1? Thanks. -- H.J. [-- Attachment #2: 0001-Add-static-pie-to-GCC-driver-for-static-PIE.patch --] [-- Type: text/x-patch, Size: 7977 bytes --] From b65e6477a8c41c7c8b4602c22e92b7b8b10960ab Mon Sep 17 00:00:00 2001 From: "H.J. Lu" <hjl.tools@gmail.com> Date: Thu, 20 Jul 2017 14:08:18 -0700 Subject: [PATCH] Add -static-pie to GCC driver for static PIE A static position independent executable is similar to static executable, but can be loaded at any address without a dynamic linker. All linker input files must be compiled with -fpie or -fPIE and linker must support --no-dynamic-linker to avoid linking with dynamic linker. "-z text" is also passed to linker to prevent dynamic relocations in readonly segments. PR driver/81498 * common.opt (-static-pie): New alias. (shared): Negate static-pie. (static-pie): New option. * config/gnu-user.h (GNU_USER_TARGET_STARTFILE_SPEC): Add -static-pie support. (GNU_USER_TARGET_ENDFILE_SPEC): Likewise. (LINK_GCC_C_SEQUENCE_SPEC): Likewise. * config/i386/gnu-user.h (GNU_USER_TARGET_LINK_SPEC): Likewise. * config/i386/gnu-user64.h (GNU_USER_TARGET_LINK_SPEC): Likewise. * gcc.c (init_gcc_specs): Likewise. * doc/invoke.texi: Document -static-pie. --- gcc/common.opt | 9 ++++++++- gcc/config/gnu-user.h | 13 +++++++------ gcc/config/i386/gnu-user.h | 7 ++++--- gcc/config/i386/gnu-user64.h | 11 ++++++----- gcc/doc/invoke.texi | 9 ++++++++- gcc/gcc.c | 6 +++--- 6 files changed, 36 insertions(+), 19 deletions(-) diff --git a/gcc/common.opt b/gcc/common.opt index e81165c488b..4ada85a65a0 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -346,6 +346,9 @@ Common Alias(pedantic-errors) -pie Driver Alias(pie) +-static-pie +Driver Alias(static-pie) + -pipe Driver Alias(pipe) @@ -3050,7 +3053,7 @@ x Driver Joined Separate shared -Driver RejectNegative Negative(pie) +Driver RejectNegative Negative(static-pie) Create a shared library. shared-libgcc @@ -3102,6 +3105,10 @@ pie Driver RejectNegative Negative(no-pie) Create a position independent executable. +static-pie +Driver RejectNegative Negative(pie) +Create a static position independent executable. + z Driver Joined Separate diff --git a/gcc/config/gnu-user.h b/gcc/config/gnu-user.h index de605b0c466..f0cbde3343c 100644 --- a/gcc/config/gnu-user.h +++ b/gcc/config/gnu-user.h @@ -53,11 +53,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see "%{shared:; \ pg|p|profile:gcrt1.o%s; \ static:crt1.o%s; \ - " PIE_SPEC ":Scrt1.o%s; \ + static-pie|" PIE_SPEC ":Scrt1.o%s; \ :crt1.o%s} \ crti.o%s \ %{static:crtbeginT.o%s; \ - shared|" PIE_SPEC ":crtbeginS.o%s; \ + shared|static-pie|" PIE_SPEC ":crtbeginS.o%s; \ :crtbegin.o%s} \ %{fvtable-verify=none:%s; \ fvtable-verify=preinit:vtv_start_preinit.o%s; \ @@ -70,7 +70,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see :crt1.o%s} \ crti.o%s \ %{static:crtbeginT.o%s; \ - shared|pie:crtbeginS.o%s; \ + shared|pie|static-pie:crtbeginS.o%s; \ :crtbegin.o%s} \ %{fvtable-verify=none:%s; \ fvtable-verify=preinit:vtv_start_preinit.o%s; \ @@ -92,7 +92,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 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; \ + shared|static-pie|" PIE_SPEC ":crtendS.o%s; \ :crtend.o%s} \ crtn.o%s \ " CRTOFFLOADEND @@ -102,7 +102,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see fvtable-verify=preinit:vtv_end_preinit.o%s; \ fvtable-verify=std:vtv_end.o%s} \ %{static:crtend.o%s; \ - shared|pie:crtendS.o%s; \ + shared|pie|static-pie:crtendS.o%s; \ :crtend.o%s} \ crtn.o%s \ " CRTOFFLOADEND @@ -137,7 +137,8 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #undef LINK_GCC_C_SEQUENCE_SPEC #define LINK_GCC_C_SEQUENCE_SPEC \ - "%{static:--start-group} %G %L %{static:--end-group}%{!static:%G}" + "%{static|static-pie:--start-group} %G %L \ + %{static|static-pie:--end-group}%{!static:%{!static-pie:%G}}" /* Use --as-needed -lgcc_s for eh support. */ #ifdef HAVE_LD_AS_NEEDED diff --git a/gcc/config/i386/gnu-user.h b/gcc/config/i386/gnu-user.h index a4c88f1a848..8983dc9ecd7 100644 --- a/gcc/config/i386/gnu-user.h +++ b/gcc/config/i386/gnu-user.h @@ -77,9 +77,10 @@ along with GCC; see the file COPYING3. If not see #define GNU_USER_TARGET_LINK_SPEC "-m %(link_emulation) %{shared:-shared} \ %{!shared: \ %{!static: \ - %{rdynamic:-export-dynamic} \ - -dynamic-linker %(dynamic_linker)} \ - %{static:-static}}" + %{!static-pie: \ + %{rdynamic:-export-dynamic} \ + -dynamic-linker %(dynamic_linker)}} \ + %{static:-static} %{static-pie:-static -pie --no-dynamic-linker -z text}}" #undef LINK_SPEC #define LINK_SPEC GNU_USER_TARGET_LINK_SPEC diff --git a/gcc/config/i386/gnu-user64.h b/gcc/config/i386/gnu-user64.h index 39f5ef6a68b..6fc9eae6f6b 100644 --- a/gcc/config/i386/gnu-user64.h +++ b/gcc/config/i386/gnu-user64.h @@ -59,11 +59,12 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see %{shared:-shared} \ %{!shared: \ %{!static: \ - %{rdynamic:-export-dynamic} \ - %{" SPEC_32 ":-dynamic-linker " GNU_USER_DYNAMIC_LINKER32 "} \ - %{" SPEC_64 ":-dynamic-linker " GNU_USER_DYNAMIC_LINKER64 "} \ - %{" SPEC_X32 ":-dynamic-linker " GNU_USER_DYNAMIC_LINKERX32 "}} \ - %{static:-static}}" + %{!static-static: \ + %{rdynamic:-export-dynamic} \ + %{" SPEC_32 ":-dynamic-linker " GNU_USER_DYNAMIC_LINKER32 "} \ + %{" SPEC_64 ":-dynamic-linker " GNU_USER_DYNAMIC_LINKER64 "} \ + %{" SPEC_X32 ":-dynamic-linker " GNU_USER_DYNAMIC_LINKERX32 "}}} \ + %{static:-static} %{static-pie:-static -pie --no-dynamic-linker -z text}}" #undef LINK_SPEC #define LINK_SPEC GNU_USER_TARGET_LINK_SPEC diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index dfde403cbf2..027d9a97d6b 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -496,7 +496,7 @@ Objective-C and Objective-C++ Dialects}. @xref{Link Options,,Options for Linking}. @gccoptlist{@var{object-file-name} -fuse-ld=@var{linker} -l@var{library} @gol -nostartfiles -nodefaultlibs -nostdlib -pie -pthread -rdynamic @gol --s -static -static-libgcc -static-libstdc++ @gol +-s -static -static-pie -static-libgcc -static-libstdc++ @gol -static-libasan -static-libtsan -static-liblsan -static-libubsan @gol -static-libmpx -static-libmpxwrappers @gol -shared -shared-libgcc -symbolic @gol @@ -11746,6 +11746,13 @@ or model suboptions) when you specify this linker option. @opindex no-pie Don't produce a position independent executable. +@item -static-pie +@opindex static-pie +Produce a static position independent executable on targets that support +it. For predictable results, you must also specify the same set of +options used for compilation (@option{-fpie}, @option{-fPIE}, +or model suboptions) when you specify this linker option. + @item -pthread @opindex pthread Link with the POSIX threads library. This option is supported on diff --git a/gcc/gcc.c b/gcc/gcc.c index 80a8b8b2bee..ffd6e42114e 100644 --- a/gcc/gcc.c +++ b/gcc/gcc.c @@ -1668,8 +1668,8 @@ init_gcc_specs (struct obstack *obstack, const char *shared_name, { char *buf; - buf = concat ("%{static|static-libgcc:", static_name, " ", eh_name, "}" - "%{!static:%{!static-libgcc:" + buf = concat ("%{static|static-libgcc|static-pie:", static_name, " ", eh_name, "}" + "%{!static:%{!static-libgcc:%{!static-pie:" #if USE_LD_AS_NEEDED "%{!shared-libgcc:", static_name, " " LD_AS_NEEDED_OPTION " ", @@ -1677,7 +1677,7 @@ init_gcc_specs (struct obstack *obstack, const char *shared_name, "}" "%{shared-libgcc:", shared_name, "%{!shared: ", static_name, "}" - "}" + "}" "}" #else "%{!shared:" "%{!shared-libgcc:", static_name, " ", eh_name, "}" -- 2.13.3 ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH] Fix pr80044, -static and -pie insanity, and pr81170 2017-06-22 15:29 [PATCH] Fix pr80044, -static and -pie insanity, and pr81170 Alan Modra ` (2 preceding siblings ...) 2017-07-15 13:32 ` H.J. Lu @ 2017-08-28 15:44 ` Jeff Law 2017-08-29 2:35 ` Alan Modra 3 siblings, 1 reply; 16+ messages in thread From: Jeff Law @ 2017-08-28 15:44 UTC (permalink / raw) To: Alan Modra, gcc-patches On 06/22/2017 09:28 AM, 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. So sorry for the horrible delay. What was the final resolution here? I saw a lot of back and forth with HJ and yourself. 80044 is CLOSED/WONTFIX and 81170 has a patch attached to it, but is still in the ASSIGNED state. jeff ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH] Fix pr80044, -static and -pie insanity, and pr81170 2017-08-28 15:44 ` Jeff Law @ 2017-08-29 2:35 ` Alan Modra 2017-08-29 8:39 ` Jeff Law 0 siblings, 1 reply; 16+ messages in thread From: Alan Modra @ 2017-08-29 2:35 UTC (permalink / raw) To: Jeff Law; +Cc: gcc-patches On Mon, Aug 28, 2017 at 08:27:35AM -0600, Jeff Law wrote: > So sorry for the horrible delay. What was the final resolution here? I > saw a lot of back and forth with HJ and yourself. 80044 is > CLOSED/WONTFIX and 81170 has a patch attached to it, but is still in the > ASSIGNED state. The patch went in trunk as 5a402d649 (r250974) and a9b2df6cc (r251065). PR81170 and PR81295 are still open due to needing a fix for powerpc --enable-default-pie on the branches. Last I checked, both patches apply without any difficulty. https://gcc.gnu.org/ml/gcc-patches/2017-08/msg00831.html -- Alan Modra Australia Development Lab, IBM ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH] Fix pr80044, -static and -pie insanity, and pr81170 2017-08-29 2:35 ` Alan Modra @ 2017-08-29 8:39 ` Jeff Law 0 siblings, 0 replies; 16+ messages in thread From: Jeff Law @ 2017-08-29 8:39 UTC (permalink / raw) To: Alan Modra; +Cc: gcc-patches On 08/28/2017 04:33 PM, Alan Modra wrote: > On Mon, Aug 28, 2017 at 08:27:35AM -0600, Jeff Law wrote: >> So sorry for the horrible delay. What was the final resolution here? I >> saw a lot of back and forth with HJ and yourself. 80044 is >> CLOSED/WONTFIX and 81170 has a patch attached to it, but is still in the >> ASSIGNED state. > > The patch went in trunk as 5a402d649 (r250974) and a9b2df6cc > (r251065). PR81170 and PR81295 are still open due to needing a fix > for powerpc --enable-default-pie on the branches. Last I checked, > both patches apply without any difficulty. > > https://gcc.gnu.org/ml/gcc-patches/2017-08/msg00831.html I think if you want to backport, go ahead. jeff ^ permalink raw reply [flat|nested] 16+ messages in thread
end of thread, other threads:[~2017-08-29 5:21 UTC | newest] Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2017-06-22 15:29 [PATCH] Fix pr80044, -static and -pie insanity, and pr81170 Alan Modra 2017-06-29 13:34 ` Alan Modra 2017-07-15 12:45 ` Alan Modra 2017-07-06 13:34 ` Matthias Klose 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
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).