diff options
author | H.J. Lu <hongjiu.lu@intel.com> | 2017-09-12 16:30:28 +0000 |
---|---|---|
committer | H.J. Lu <hjl@gcc.gnu.org> | 2017-09-12 09:30:28 -0700 |
commit | b4fed89078efeb11da212091421a9f4718f625cc (patch) | |
tree | 991254b7281354b7923b50ba07c1114a2364c58f /gcc/config | |
parent | ff76f0b5f6e6a4144fabb9ae984a9ee9dcaa2d08 (diff) | |
download | gcc-b4fed89078efeb11da212091421a9f4718f625cc.zip gcc-b4fed89078efeb11da212091421a9f4718f625cc.tar.gz gcc-b4fed89078efeb11da212091421a9f4718f625cc.tar.bz2 |
Add -static-pie to GCC driver to create static PIE
This patch adds -static-pie to GCC driver to create static PIE. A static
position independent executable (PIE) 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 needed to prevent dynamic relocations in read-only segments.
PR driver/81498
* common.opt (-static-pie): New alias.
(shared): Negate static-pie.
(-no-pie): Update help text.
(-pie): Likewise.
(static-pie): New option.
* config/gnu-user.h (GNU_USER_TARGET_STARTFILE_SPEC): Add
-static-pie support.
(GNU_USER_TARGET_ENDFILE_SPEC): Likewise.
(LINK_EH_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 (LINK_COMMAND_SPEC): Likewise.
(init_gcc_specs): Likewise.
(init_spec): Likewise.
(display_help): Update help message for -pie.
* doc/invoke.texi: Update -pie, -no-pie and -static. Document
-static-pie.
From-SVN: r252034
Diffstat (limited to 'gcc/config')
-rw-r--r-- | gcc/config/gnu-user.h | 15 | ||||
-rw-r--r-- | gcc/config/i386/gnu-user.h | 7 | ||||
-rw-r--r-- | gcc/config/i386/gnu-user64.h | 11 |
3 files changed, 18 insertions, 15 deletions
diff --git a/gcc/config/gnu-user.h b/gcc/config/gnu-user.h index de605b0..a967b69 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 @@ -132,12 +132,13 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #define LIB_SPEC GNU_USER_TARGET_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 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 a4c88f1..8983dc9 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 39f5ef6..6fc9eae 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 |