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/gcc.c | |
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/gcc.c')
-rw-r--r-- | gcc/gcc.c | 20 |
1 files changed, 12 insertions, 8 deletions
@@ -1015,9 +1015,10 @@ proper position among the other output files. */ #endif /* -u* was put back because both BSD and SysV seem to support it. */ -/* %{static|no-pie:} simply prevents an error message: +/* %{static|no-pie|static-pie:} simply prevents an error message: 1. If the target machine doesn't handle -static. 2. If PIE isn't enabled by default. + 3. If the target machine doesn't handle -static-pie. */ /* We want %{T*} after %{L*} and %D so that it can be used to specify linker scripts which exist in user specified directories, or in standard @@ -1035,7 +1036,7 @@ proper position among the other output files. */ "%{fuse-ld=*:-fuse-ld=%*} " LINK_COMPRESS_DEBUG_SPEC \ "%X %{o*} %{e*} %{N} %{n} %{r}\ %{s} %{t} %{u*} %{z} %{Z} %{!nostdlib:%{!nostartfiles:%S}} \ - %{static|no-pie:} %{L*} %(mfwrap) %(link_libgcc) " \ + %{static|no-pie|static-pie:} %{L*} %(mfwrap) %(link_libgcc) " \ VTABLE_VERIFICATION_SPEC " " SANITIZER_EARLY_SPEC " %o " CHKP_SPEC " \ %{fopenacc|fopenmp|%:gt(%{ftree-parallelize-loops=*:%*} 1):\ %:include(libgomp.spec)%(link_gomp)}\ @@ -1670,17 +1671,19 @@ init_gcc_specs (struct obstack *obstack, const char *shared_name, { char *buf; - buf = concat ("%{static|static-libgcc:", static_name, " ", eh_name, "}" - "%{!static:%{!static-libgcc:" #if USE_LD_AS_NEEDED + buf = concat ("%{static|static-libgcc|static-pie:", static_name, " ", eh_name, "}" + "%{!static:%{!static-libgcc:%{!static-pie:" "%{!shared-libgcc:", static_name, " " LD_AS_NEEDED_OPTION " ", shared_name, " " LD_NO_AS_NEEDED_OPTION "}" "%{shared-libgcc:", shared_name, "%{!shared: ", static_name, "}" - "}" + "}}" #else + buf = concat ("%{static|static-libgcc:", static_name, " ", eh_name, "}" + "%{!static:%{!static-libgcc:" "%{!shared:" "%{!shared-libgcc:", static_name, " ", eh_name, "}" "%{shared-libgcc:", shared_name, " ", static_name, "}" @@ -1788,8 +1791,8 @@ init_spec (void) "-lgcc_eh" #ifdef USE_LIBUNWIND_EXCEPTIONS # ifdef HAVE_LD_STATIC_DYNAMIC - " %{!static:" LD_STATIC_OPTION "} -lunwind" - " %{!static:" LD_DYNAMIC_OPTION "}" + " %{!static:%{!static-pie:" LD_STATIC_OPTION "}} -lunwind" + " %{!static:%{!static-pie:" LD_DYNAMIC_OPTION "}}" # else " -lunwind" # endif @@ -3478,7 +3481,8 @@ display_help (void) fputs (_(" -S Compile only; do not assemble or link.\n"), stdout); fputs (_(" -c Compile and assemble, but do not link.\n"), stdout); fputs (_(" -o <file> Place the output into <file>.\n"), stdout); - fputs (_(" -pie Create a position independent executable.\n"), stdout); + fputs (_(" -pie Create a dynamically linked position independent\n\ + executable.\n"), stdout); fputs (_(" -shared Create a shared library.\n"), stdout); fputs (_("\ -x <language> Specify the language of the following input files.\n\ |