This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] add static-linked PIE support


This is the gcc side support of the static-linked PIE functionality
added to binutils in commit 9b8b325a1f4cdaf235e7d803849dde6ededec865:

https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=9b8b325a1f4cdaf235e7d803849dde6ededec865

I've moved the linking spec change from SUBTARGET_LINK_SPEC, where I
had it in earlier sh-only versions of this patch, to LINK_PIE_SPEC; I
believe the new location is more appropriate and avoids widespread
per-target changes.

A special start file named rcrt1.o must be provided by the C
runtime/standard library to perform relative relocation processing as
part of the program's entry point, since there is no dynamic linker to
do relocation processing.

No attempt is made to suppress passing --no-dynamic-linker to older
versions of ld that don't support it, because use of -static and -pie
together was already broken (it silently produced binaries with an
incorrect PT_INTERP header). If this is a problem I can work on adding
checking to configure, but I think making it conditional would
actually give worse user experience, since upgrading binutils to
support static PIE would then also require rebuilding gcc with the new
binutils available so that support gets detected.

2015-09-14  Rich Felker  <dalias@libc.org>

	* config/gnu-user.h (GNU_USER_TARGET_STARTFILE_SPEC): use
	rcrt1.o for static-linked PIE.
	* gcc.c (LINK_PIE_SPEC): pass --no-dynamic-linker to linker
	for static-linked PIE.

--- gcc-5.2.0.orig/gcc/config/gnu-user.h	2015-01-05 12:33:28.000000000 +0000
+++ gcc-5.2.0/gcc/config/gnu-user.h	2015-08-25 08:15:18.354957759 +0000
@@ -42,8 +42,8 @@
 
 #if defined HAVE_LD_PIE
 #define GNU_USER_TARGET_STARTFILE_SPEC \
-  "%{!shared: %{pg|p|profile:gcrt1.o%s;pie:Scrt1.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;pie:%{static:rcrt1.o%s;:Scrt1.o%s};:crt1.o%s}} \
+   crti.o%s %{shared|pie:crtbeginS.o%s;static:crtbeginT.o%s;:crtbegin.o%s} \
    %{fvtable-verify=none:%s; \
      fvtable-verify=preinit:vtv_start_preinit.o%s; \
      fvtable-verify=std:vtv_start.o%s}"
--- gcc-5.2.0.orig/gcc/gcc.c	2015-03-10 09:37:41.000000000 +0000
+++ gcc-5.2.0/gcc/gcc.c	2015-09-30 00:25:33.225927941 +0000
@@ -739,7 +739,7 @@
 
 #ifndef LINK_PIE_SPEC
 #ifdef HAVE_LD_PIE
-#define LINK_PIE_SPEC "%{pie:-pie} "
+#define LINK_PIE_SPEC "%{pie:-pie %{static:--no-dynamic-linker}} "
 #else
 #define LINK_PIE_SPEC "%{pie:} "
 #endif


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]