diff mbox series

Fallout from -static-pie to GCC driver to create static PIE

Message ID 20170913201950.GC1701@tucnak
State New
Headers show
Series Fallout from -static-pie to GCC driver to create static PIE | expand

Commit Message

Jakub Jelinek Sept. 13, 2017, 8:19 p.m. UTC
On Wed, Sep 13, 2017 at 05:18:00AM -0700, H.J. Lu wrote:
> > In LINK_EH_SPEC you use %{!static|static-pie:--eh-frame-hdr}, what
> > exactly do you mean by that?  The way that works is if -static
> > isn't present on the command line OR if -static -static-pie OR
> > -static-pie -static is present, you get --eh-frame-hdr.  Didn't you
> > mean %{!static:%{!static-pie:--eh-frame-hdr}}, i.e. don't emit
> > --eh-frame-hdr for either -static or -static-pie?
> 
> It means "pass --eh-frame-hdr to ld if -static isn't used or -static-pie
> is used since -static-pie needs PT_GNU_EH_FRAME segment.

Ok.

So here is an updated patch (also fixed whitespace in i386/gnu-user.h
because the indentation there didn't match the nesting).

Bootstrapped/regtested on {x86_64,i686,powerpc64,powerpc64le}-linux,
ok for trunk?
At least the rs6000 part is really important, as bootstrap
is broken on powerpc*.

2017-09-13  Jakub Jelinek  <jakub@redhat.com>

	* config/alpha/elf.h (LINK_EH_SPEC): Add -static-pie support.
	* config/alpha/linux.h (LINK_GCC_C_SEQUENCE_SPEC): Likewise.
	* config/netbsd.h (LINK_EH_SPEC): Likewise.
	* config/sol2.h (LINK_EH_SPEC): Likewise.
	* config/arm/uclinux-elf.h (LINK_GCC_C_SEQUENCE_SPEC): Likewise.
	* config/s390/linux.h (LINK_SPEC): Likewise.
	* config/freebsd.h (LINK_EH_SPEC): Likewise.
	* config/openbsd.h (LINK_EH_SPEC): Likewise.
	* config/lm32/uclinux-elf.h (LINK_GCC_C_SEQUENCE_SPEC): Likewise.
	* config/aarch64/aarch64-linux.h (LINUX_TARGET_LINK_SPEC): Likewise.
	* config/powerpcspe/sysv4.h (LINK_EH_SPEC): Likewise.
	* config/bfin/linux.h (LINK_GCC_C_SEQUENCE_SPEC): Likewise.
	* config/rs6000/sysv4.h (STARTFILE_LINUX_SPEC): Likewise.
	(ENDFILE_LINUX_SPEC): Likewise.
	(LINK_EH_SPEC): Likewise.
	* config/rs6000/linux64.h (LINK_SHLIB_SPEC): Likewise.
	(LINK_OS_LINUX_SPEC32): Likewise.
	(LINK_OS_LINUX_SPEC64): Likewise.
	* config/rs6000/linux.h (LINK_SHLIB_SPEC): Likewise.
	(LINK_OS_LINUX_SPEC): Likewise.
	* config/i386/gnu-user64.h (GNU_USER_TARGET_LINK_SPEC): Fix a typo.
	* config/i386/gnu-user.h (GNU_USER_TARGET_LINK_SPEC): Formatting fix.



	Jakub

Comments

Segher Boessenkool Sept. 13, 2017, 8:36 p.m. UTC | #1
On Wed, Sep 13, 2017 at 10:19:50PM +0200, Jakub Jelinek wrote:
> On Wed, Sep 13, 2017 at 05:18:00AM -0700, H.J. Lu wrote:
> > > In LINK_EH_SPEC you use %{!static|static-pie:--eh-frame-hdr}, what
> > > exactly do you mean by that?  The way that works is if -static
> > > isn't present on the command line OR if -static -static-pie OR
> > > -static-pie -static is present, you get --eh-frame-hdr.  Didn't you
> > > mean %{!static:%{!static-pie:--eh-frame-hdr}}, i.e. don't emit
> > > --eh-frame-hdr for either -static or -static-pie?
> > 
> > It means "pass --eh-frame-hdr to ld if -static isn't used or -static-pie
> > is used since -static-pie needs PT_GNU_EH_FRAME segment.
> 
> Ok.
> 
> So here is an updated patch (also fixed whitespace in i386/gnu-user.h
> because the indentation there didn't match the nesting).
> 
> Bootstrapped/regtested on {x86_64,i686,powerpc64,powerpc64le}-linux,
> ok for trunk?
> At least the rs6000 part is really important, as bootstrap
> is broken on powerpc*.

The rs6000 part looks fine, thanks!


Segher
Joseph Myers Sept. 13, 2017, 10:36 p.m. UTC | #2
On Wed, 13 Sep 2017, Jakub Jelinek wrote:

> Ok.
> 
> So here is an updated patch (also fixed whitespace in i386/gnu-user.h
> because the indentation there didn't match the nesting).
> 
> Bootstrapped/regtested on {x86_64,i686,powerpc64,powerpc64le}-linux,
> ok for trunk?
> At least the rs6000 part is really important, as bootstrap
> is broken on powerpc*.

OK.
diff mbox series

Patch

--- gcc/config/alpha/elf.h.jj	2017-01-01 12:45:40.000000000 +0100
+++ gcc/config/alpha/elf.h	2017-09-13 11:34:37.889721802 +0200
@@ -168,5 +168,5 @@  extern int alpha_this_gpdisp_sequence_nu
    I imagine that other systems will catch up.  In the meantime, it
    doesn't harm to make sure that the data exists to be used later.  */
 #if defined(HAVE_LD_EH_FRAME_HDR)
-#define LINK_EH_SPEC "%{!static:--eh-frame-hdr} "
+#define LINK_EH_SPEC "%{!static|static-pie:--eh-frame-hdr} "
 #endif
--- gcc/config/alpha/linux.h.jj	2017-01-01 12:45:40.063647860 +0100
+++ gcc/config/alpha/linux.h	2017-09-13 11:42:01.187281636 +0200
@@ -79,7 +79,8 @@  along with GCC; see the file COPYING3.
 #define TARGET_POSIX_IO
 
 #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
--- gcc/config/netbsd.h.jj	2017-07-13 15:37:54.000000000 +0200
+++ gcc/config/netbsd.h	2017-09-13 11:33:39.105443205 +0200
@@ -125,7 +125,7 @@  along with GCC; see the file COPYING3.
 #define LIBGCC_SPEC NETBSD_LIBGCC_SPEC
 
 #if defined(HAVE_LD_EH_FRAME_HDR)
-#define LINK_EH_SPEC "%{!static:--eh-frame-hdr} "
+#define LINK_EH_SPEC "%{!static|static-pie:--eh-frame-hdr} "
 #endif
 
 #undef TARGET_LIBC_HAS_FUNCTION
--- gcc/config/sol2.h.jj	2017-09-01 09:26:51.000000000 +0200
+++ gcc/config/sol2.h	2017-09-13 11:34:04.628129989 +0200
@@ -372,7 +372,7 @@  along with GCC; see the file COPYING3.
 /* Solaris 11 build 135+ implements dl_iterate_phdr.  GNU ld needs
    --eh-frame-hdr to create the required .eh_frame_hdr sections.  */
 #if defined(HAVE_LD_EH_FRAME_HDR) && defined(TARGET_DL_ITERATE_PHDR)
-#define LINK_EH_SPEC "%{!static:--eh-frame-hdr} "
+#define LINK_EH_SPEC "%{!static|static-pie:--eh-frame-hdr} "
 #endif /* HAVE_LD_EH_FRAME && TARGET_DL_ITERATE_PHDR */
 #endif
 
--- gcc/config/arm/uclinux-elf.h.jj	2017-01-01 12:45:41.382630422 +0100
+++ gcc/config/arm/uclinux-elf.h	2017-09-13 11:42:51.438664949 +0200
@@ -70,7 +70,8 @@ 
 
 #undef LINK_GCC_C_SEQUENCE_SPEC
 #define LINK_GCC_C_SEQUENCE_SPEC \
-  "%{static:--start-group} %G %L %{static:--end-group}%{!static:%G %L}"
+  "%{static|static-pie:--start-group} %G %L \
+   %{static|static-pie:--end-group}%{!static:%{!static-pie:%G %L}}"
 
 /* Use --as-needed -lgcc_s for eh support.  */
 #ifdef HAVE_LD_AS_NEEDED
--- gcc/config/s390/linux.h.jj	2017-02-06 13:32:14.000000000 +0100
+++ gcc/config/s390/linux.h	2017-09-13 13:21:09.209266231 +0200
@@ -82,10 +82,11 @@  along with GCC; see the file COPYING3.
    %{shared:-shared} \
    %{!shared: \
       %{static:-static} \
-      %{!static: \
+      %{!static:%{!static-pie: \
 	%{rdynamic:-export-dynamic} \
 	%{m31:-dynamic-linker " GNU_USER_DYNAMIC_LINKER32 "} \
-	%{m64:-dynamic-linker " GNU_USER_DYNAMIC_LINKER64 "}}}"
+	%{m64:-dynamic-linker " GNU_USER_DYNAMIC_LINKER64 "}}}} \
+   %{static-pie:-static -pie --no-dynamic-linker -z text}"
 
 #define CPP_SPEC "%{posix:-D_POSIX_SOURCE} %{pthread:-D_REENTRANT}"
 
--- gcc/config/i386/gnu-user64.h.jj	2017-09-12 21:58:08.000000000 +0200
+++ gcc/config/i386/gnu-user64.h	2017-09-13 11:53:27.531835467 +0200
@@ -59,7 +59,7 @@  see the files COPYING3 and COPYING.RUNTI
   %{shared:-shared} \
   %{!shared: \
     %{!static: \
-      %{!static-static: \
+      %{!static-pie: \
 	%{rdynamic:-export-dynamic} \
 	%{" SPEC_32 ":-dynamic-linker " GNU_USER_DYNAMIC_LINKER32 "} \
 	%{" SPEC_64 ":-dynamic-linker " GNU_USER_DYNAMIC_LINKER64 "} \
--- gcc/config/i386/gnu-user.h.jj	2017-09-12 21:58:08.000000000 +0200
+++ gcc/config/i386/gnu-user.h	2017-09-13 15:37:39.993512827 +0200
@@ -80,7 +80,7 @@  along with GCC; see the file COPYING3.
       %{!static-pie: \
 	%{rdynamic:-export-dynamic} \
 	-dynamic-linker %(dynamic_linker)}} \
-      %{static:-static} %{static-pie:-static -pie --no-dynamic-linker -z text}}"
+    %{static:-static} %{static-pie:-static -pie --no-dynamic-linker -z text}}"
 
 #undef	LINK_SPEC
 #define LINK_SPEC GNU_USER_TARGET_LINK_SPEC
--- gcc/config/freebsd.h.jj	2017-01-01 12:45:40.000000000 +0100
+++ gcc/config/freebsd.h	2017-09-13 11:33:13.095762396 +0200
@@ -45,7 +45,7 @@  along with GCC; see the file COPYING3.
 #define LIB_SPEC FBSD_LIB_SPEC
 
 #if defined(HAVE_LD_EH_FRAME_HDR)
-#define LINK_EH_SPEC "%{!static:--eh-frame-hdr} "
+#define LINK_EH_SPEC "%{!static|static-pie:--eh-frame-hdr} "
 #endif
 
 #ifdef TARGET_LIBC_PROVIDES_SSP
--- gcc/config/openbsd.h.jj	2017-01-01 12:45:40.000000000 +0100
+++ gcc/config/openbsd.h	2017-09-13 11:33:26.439598640 +0200
@@ -136,7 +136,7 @@  while (0)
 #define LIB_SPEC OBSD_LIB_SPEC
 
 #if defined(HAVE_LD_EH_FRAME_HDR)
-#define LINK_EH_SPEC "%{!static:--eh-frame-hdr} "
+#define LINK_EH_SPEC "%{!static|static-pie:--eh-frame-hdr} "
 #endif
 
 #undef LIB_SPEC
--- gcc/config/lm32/uclinux-elf.h.jj	2017-01-01 12:45:42.000000000 +0100
+++ gcc/config/lm32/uclinux-elf.h	2017-09-13 11:44:50.788200287 +0200
@@ -72,7 +72,8 @@ 
 #define TARGET_OS_CPP_BUILTINS() GNU_USER_TARGET_OS_CPP_BUILTINS()
 
 #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}}"
 
 #undef  CC1_SPEC
 #define CC1_SPEC "%{G*} %{!fno-PIC:-fPIC}"
--- gcc/config/aarch64/aarch64-linux.h.jj	2017-01-01 12:45:43.000000000 +0100
+++ gcc/config/aarch64/aarch64-linux.h	2017-09-13 15:49:22.378859547 +0200
@@ -38,9 +38,10 @@ 
    %{static:-Bstatic}				\
    %{shared:-shared}				\
    %{symbolic:-Bsymbolic}			\
-   %{!static:					\
+   %{!static:%{!static-pie:			\
      %{rdynamic:-export-dynamic}		\
-     %{!shared:-dynamic-linker " GNU_USER_DYNAMIC_LINKER "}} \
+     %{!shared:-dynamic-linker " GNU_USER_DYNAMIC_LINKER "}}} \
+   %{static-pie:-Bstatic -pie --no-dynamic-linker -z text} \
    -X						\
    %{mbig-endian:-EB} %{mlittle-endian:-EL}     \
    -maarch64linux%{mabi=ilp32:32}%{mbig-endian:b}"
--- gcc/config/powerpcspe/sysv4.h.jj	2017-05-25 10:37:06.000000000 +0200
+++ gcc/config/powerpcspe/sysv4.h	2017-09-13 11:32:38.484187151 +0200
@@ -805,7 +805,7 @@  ENDIAN_SELECT(" -mbig", " -mlittle", DEF
   -dynamic-linker " GNU_USER_DYNAMIC_LINKER "}}"
 
 #if defined(HAVE_LD_EH_FRAME_HDR)
-# define LINK_EH_SPEC "%{!static:--eh-frame-hdr} "
+# define LINK_EH_SPEC "%{!static|static-pie:--eh-frame-hdr} "
 #endif
 
 #define CPP_OS_LINUX_SPEC "-D__unix__ -D__gnu_linux__ -D__linux__ \
--- gcc/config/bfin/linux.h.jj	2017-01-01 12:45:43.000000000 +0100
+++ gcc/config/bfin/linux.h	2017-09-13 11:44:10.858690304 +0200
@@ -35,8 +35,9 @@  see the files COPYING3 and COPYING.RUNTI
 
 #undef LINK_GCC_C_SEQUENCE_SPEC
 #define LINK_GCC_C_SEQUENCE_SPEC \
-  "%{static:--start-group} %{mfast-fp:-lbffastfp} %G %L %{static:--end-group} \
-   %{!static:%{mfast-fp:-lbffastfp} %G}"
+  "%{static|static-pie:--start-group} %{mfast-fp:-lbffastfp} %G %L \
+   %{static|static-pie:--end-group} \
+   %{!static:%{!static-pie:%{mfast-fp:-lbffastfp} %G}}"
 
 #undef CPP_SPEC
 #define CPP_SPEC "%{posix:-D_POSIX_SOURCE} %{pthread:-D_REENTRANT}"
--- gcc/config/rs6000/sysv4.h.jj	2017-09-01 09:26:55.000000000 +0200
+++ gcc/config/rs6000/sysv4.h	2017-09-13 11:38:01.493223171 +0200
@@ -764,11 +764,11 @@  ENDIAN_SELECT(" -mbig", " -mlittle", DEF
   "%{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} \
    %{mnewlib:ecrti.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; \
@@ -782,7 +782,7 @@  ENDIAN_SELECT(" -mbig", " -mlittle", DEF
      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} \
    %{mnewlib:ecrtn.o%s;:crtn.o%s} \
    " CRTOFFLOADEND
@@ -816,7 +816,7 @@  ENDIAN_SELECT(" -mbig", " -mlittle", DEF
   -dynamic-linker " GNU_USER_DYNAMIC_LINKER "}}"
 
 #if defined(HAVE_LD_EH_FRAME_HDR)
-# define LINK_EH_SPEC "%{!static:--eh-frame-hdr} "
+# define LINK_EH_SPEC "%{!static|static-pie:--eh-frame-hdr} "
 #endif
 
 #define CPP_OS_LINUX_SPEC "-D__unix__ -D__gnu_linux__ -D__linux__ \
--- gcc/config/rs6000/linux64.h.jj	2017-09-05 23:28:22.000000000 +0200
+++ gcc/config/rs6000/linux64.h	2017-09-13 11:57:54.641531551 +0200
@@ -395,7 +395,8 @@  extern int dot_symbols;
 #define CPP_OS_DEFAULT_SPEC "%(cpp_os_linux) %(include_extra)"
 
 #undef  LINK_SHLIB_SPEC
-#define LINK_SHLIB_SPEC "%{shared:-shared} %{!shared: %{static:-static}}"
+#define LINK_SHLIB_SPEC "%{shared:-shared} %{!shared: %{static:-static}} \
+  %{static-pie:-static -pie --no-dynamic-linker -z text}"
 
 #undef  LIB_DEFAULT_SPEC
 #define LIB_DEFAULT_SPEC "%(lib_linux)"
@@ -470,13 +471,15 @@  extern int dot_symbols;
 #endif
 
 #define LINK_OS_LINUX_SPEC32 LINK_OS_LINUX_EMUL32 " %{!shared: %{!static: \
-  %{rdynamic:-export-dynamic} \
-  -dynamic-linker " GNU_USER_DYNAMIC_LINKER32 "}} \
+  %{!static-pie: \
+    %{rdynamic:-export-dynamic} \
+    -dynamic-linker " GNU_USER_DYNAMIC_LINKER32 "}}} \
   %(link_os_extra_spec32)"
 
 #define LINK_OS_LINUX_SPEC64 LINK_OS_LINUX_EMUL64 " %{!shared: %{!static: \
-  %{rdynamic:-export-dynamic} \
-  -dynamic-linker " GNU_USER_DYNAMIC_LINKER64 "}} \
+  %{!static-pie: \
+    %{rdynamic:-export-dynamic} \
+    -dynamic-linker " GNU_USER_DYNAMIC_LINKER64 "}}} \
   %(link_os_extra_spec64)"
 
 #undef  TOC_SECTION_ASM_OP
--- gcc/config/rs6000/linux.h.jj	2017-01-01 12:45:43.000000000 +0100
+++ gcc/config/rs6000/linux.h	2017-09-13 11:56:33.092540242 +0200
@@ -61,7 +61,8 @@ 
 #define CPP_OS_DEFAULT_SPEC "%(cpp_os_linux)"
 
 #undef  LINK_SHLIB_SPEC
-#define LINK_SHLIB_SPEC "%{shared:-shared} %{!shared: %{static:-static}}"
+#define LINK_SHLIB_SPEC "%{shared:-shared} %{!shared: %{static:-static}} \
+  %{static-pie:-static -pie --no-dynamic-linker -z text}"
 
 #undef	LIB_DEFAULT_SPEC
 #define LIB_DEFAULT_SPEC "%(lib_linux)"
@@ -93,8 +94,9 @@ 
 
 #undef LINK_OS_LINUX_SPEC
 #define LINK_OS_LINUX_SPEC LINK_OS_LINUX_EMUL " %{!shared: %{!static: \
-  %{rdynamic:-export-dynamic} \
-  -dynamic-linker " GNU_USER_DYNAMIC_LINKER "}}"
+  %{!static-pie: \
+    %{rdynamic:-export-dynamic} \
+    -dynamic-linker " GNU_USER_DYNAMIC_LINKER "}}}"
 
 /* For backward compatibility, we must continue to use the AIX
    structure return convention.  */