From: Jakub Jelinek Date: Tue, 3 Jun 2003 09:06:55 +0000 (+0200) Subject: configure.in (HAVE_LD_PIE): Check for ld -pie. X-Git-Tag: releases/gcc-3.4.0~6226 X-Git-Url: https://gcc.gnu.org/git/?a=commitdiff_plain;h=24a4dd31f80136aadf69774545916675b50836d6;p=gcc.git configure.in (HAVE_LD_PIE): Check for ld -pie. * configure.in (HAVE_LD_PIE): Check for ld -pie. * config.in: Rebuilt. * configure: Rebuilt. * toplev.c (flag_pie, flag_shlib): New variables. (f_options): Add -fpie and -fPIE. (parse_options_and_default_flags): Set flag_pic if -fpie/-fPIE. Set flag_shlib if flag_pic and not -fpie/-fPIE. * flags.h (flag_pic, flag_shlib): Add. * varasm.c (default_binds_local_p): Use flag_shlib instead of flag_pic. * gcc.c (LINK_PIE_SPEC): Define. (LINK_COMMAND_SPEC): Use LINK_PIE_SPEC. (option_map): Add --pie -> -pie mapping. * config/sol2.h (ASM_SPEC): Handle -fpie the same way as -fpic and -fPIE the same way as -fPIC. * config/openbsd.h (ASM_SPEC): Likewise. * config/frv/frv.h (ASM_SPEC): Likewise. * config/arm/linux-gas.h (SUBTARGET_CPP_SPEC): Likewise. * config/arm/semi.h (ASM_SPEC): Likewise. * config/arm/netbsd-elf.h (SUBTARGET_EXTRA_ASM_SPEC): Likewise. * config/freebsd-spec.h (FBSD_CPP_SPEC): Likewise. * config/i386/beos-elf.h (CC1_SPEC): Likewise. * config/i386/freebsd-aout.h (ASM_SPEC): Likewise. * config/m68k/linux.h (CPP_SPEC): Likewise. * config/m68k/netbsd.h (ASM_SPEC): Likewise. * config/m68k/openbsd.h (ASM_SPEC): Likewise. * config/m68k/netbsd-elf.h (ASM_SPEC): Likewise. * config/mips/linux.h (SUBTARGET_CPP_SPEC): Likewise. * config/mips/openbsd.h (SUBTARGET_ASM_SPEC): Likewise. * config/pa/pa-linux.h (CPP_SPEC): Likewise. * config/netbsd-aout.h (ASM_SPEC): Likewise. * config/rs6000/sysv4.h (ASM_SPEC, CPP_SYSV_SPEC): Likewise. * config/rs6000/vxworks.h (CPP_SPEC): Likewise. * config/sparc/linux.h (CPP_SUBTARGET_SPEC, ASM_SPEC): Likewise. * config/sparc/linux64.h (CPP_SUBTARGET_SPEC, ASM_SPEC): Likewise. * config/sparc/sparc.h (ASM_SPEC): Likewise. * config/sparc/sp64-elf.h (ASM_SPEC): Likewise. * config/sparc/sysv4.h (ASM_SPEC): Likewise. * config/sparc/netbsd-elf.h (ASM_SPEC): Likewise. * config/sparc/openbsd64.h (ASM_SPEC): Likewise. * config/cris/linux.h (CRIS_ASM_SUBTARGET_SPEC): Likewise. * config/linux.h (STARTFILE_SPEC, ENDFILE_SPEC): Handle -pie. Simplify. * config/alpha/elf.h (STARTFILE_SPEC, ENDFILE_SPEC): Likewise. * config/i386/linux64.h (STARTFILE_SPEC, ENDFILE_SPEC): Likewise. * config/ia64/linux.h (STARTFILE_SPEC, ENDFILE_SPEC): Likewise. * config/rs6000/sysv4.h (STARTFILE_SPEC, ENDFILE_SPEC): Likewise. * config/rs6000/linux64.h (STARTFILE_SPEC, ENDFILE_SPEC): Likewise. * config/sparc/linux.h (STARTFILE_SPEC, ENDFILE_SPEC): Likewise. * config/sparc/linux64.h (STARTFILE_SPEC, ENDFILE_SPEC): Likewise. * doc/invoke.texi: Document -pie, -fpie and -fPIE options. From-SVN: r67359 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index b628ed0649fd..30b502ddb3a3 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,57 @@ +2003-06-03 Jakub Jelinek + + * configure.in (HAVE_LD_PIE): Check for ld -pie. + * config.in: Rebuilt. + * configure: Rebuilt. + * toplev.c (flag_pie, flag_shlib): New variables. + (f_options): Add -fpie and -fPIE. + (parse_options_and_default_flags): Set flag_pic if -fpie/-fPIE. + Set flag_shlib if flag_pic and not -fpie/-fPIE. + * flags.h (flag_pic, flag_shlib): Add. + * varasm.c (default_binds_local_p): Use flag_shlib instead of + flag_pic. + * gcc.c (LINK_PIE_SPEC): Define. + (LINK_COMMAND_SPEC): Use LINK_PIE_SPEC. + (option_map): Add --pie -> -pie mapping. + * config/sol2.h (ASM_SPEC): Handle -fpie the same way as -fpic + and -fPIE the same way as -fPIC. + * config/openbsd.h (ASM_SPEC): Likewise. + * config/frv/frv.h (ASM_SPEC): Likewise. + * config/arm/linux-gas.h (SUBTARGET_CPP_SPEC): Likewise. + * config/arm/semi.h (ASM_SPEC): Likewise. + * config/arm/netbsd-elf.h (SUBTARGET_EXTRA_ASM_SPEC): Likewise. + * config/freebsd-spec.h (FBSD_CPP_SPEC): Likewise. + * config/i386/beos-elf.h (CC1_SPEC): Likewise. + * config/i386/freebsd-aout.h (ASM_SPEC): Likewise. + * config/m68k/linux.h (CPP_SPEC): Likewise. + * config/m68k/netbsd.h (ASM_SPEC): Likewise. + * config/m68k/openbsd.h (ASM_SPEC): Likewise. + * config/m68k/netbsd-elf.h (ASM_SPEC): Likewise. + * config/mips/linux.h (SUBTARGET_CPP_SPEC): Likewise. + * config/mips/openbsd.h (SUBTARGET_ASM_SPEC): Likewise. + * config/pa/pa-linux.h (CPP_SPEC): Likewise. + * config/netbsd-aout.h (ASM_SPEC): Likewise. + * config/rs6000/sysv4.h (ASM_SPEC, CPP_SYSV_SPEC): Likewise. + * config/rs6000/vxworks.h (CPP_SPEC): Likewise. + * config/sparc/linux.h (CPP_SUBTARGET_SPEC, ASM_SPEC): Likewise. + * config/sparc/linux64.h (CPP_SUBTARGET_SPEC, ASM_SPEC): Likewise. + * config/sparc/sparc.h (ASM_SPEC): Likewise. + * config/sparc/sp64-elf.h (ASM_SPEC): Likewise. + * config/sparc/sysv4.h (ASM_SPEC): Likewise. + * config/sparc/netbsd-elf.h (ASM_SPEC): Likewise. + * config/sparc/openbsd64.h (ASM_SPEC): Likewise. + * config/cris/linux.h (CRIS_ASM_SUBTARGET_SPEC): Likewise. + * config/linux.h (STARTFILE_SPEC, ENDFILE_SPEC): Handle -pie. + Simplify. + * config/alpha/elf.h (STARTFILE_SPEC, ENDFILE_SPEC): Likewise. + * config/i386/linux64.h (STARTFILE_SPEC, ENDFILE_SPEC): Likewise. + * config/ia64/linux.h (STARTFILE_SPEC, ENDFILE_SPEC): Likewise. + * config/rs6000/sysv4.h (STARTFILE_SPEC, ENDFILE_SPEC): Likewise. + * config/rs6000/linux64.h (STARTFILE_SPEC, ENDFILE_SPEC): Likewise. + * config/sparc/linux.h (STARTFILE_SPEC, ENDFILE_SPEC): Likewise. + * config/sparc/linux64.h (STARTFILE_SPEC, ENDFILE_SPEC): Likewise. + * doc/invoke.texi: Document -pie, -fpie and -fPIE options. + 2003-06-03 Jakub Jelinek * builtins.c (expand_builtin_memcpy): Remove endp argument and endp diff --git a/gcc/config.in b/gcc/config.in index ccaad9ee7b09..dca4a1bd6563 100644 --- a/gcc/config.in +++ b/gcc/config.in @@ -631,6 +631,9 @@ /* Define if your linker supports --eh-frame-hdr option. */ #undef HAVE_LD_EH_FRAME_HDR +/* Define if your linker supports -pie option. */ +#undef HAVE_LD_PIE + /* Define if your MIPS libgloss linker scripts consistently include STARTUP directives. */ #undef HAVE_MIPS_LIBGLOSS_STARTUP_DIRECTIVES diff --git a/gcc/config/alpha/elf.h b/gcc/config/alpha/elf.h index 3ca8d6c7478d..abdb92af5014 100644 --- a/gcc/config/alpha/elf.h +++ b/gcc/config/alpha/elf.h @@ -413,11 +413,15 @@ void FN () \ before entering `main'. */ #undef STARTFILE_SPEC +#ifdef HAVE_LD_PIE #define STARTFILE_SPEC \ - "%{!shared: \ - %{pg:gcrt1.o%s} %{!pg:%{p:gcrt1.o%s} %{!p:crt1.o%s}}}\ - crti.o%s %{static:crtbeginT.o%s}\ - %{!static:%{shared:crtbeginS.o%s}%{!shared:crtbegin.o%s}}" + "%{!shared: %{pg|p: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}" +#else +#define STARTFILE_SPEC \ + "%{!shared: %{pg|p:gcrt1.o%s;:crt1.o%s}}\ + crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s}" +#endif /* Provide a ENDFILE_SPEC appropriate for ELF. Here we tack on the magical crtend.o file which provides part of the support for @@ -427,7 +431,7 @@ void FN () \ #undef ENDFILE_SPEC #define ENDFILE_SPEC \ "%{ffast-math|funsafe-math-optimizations:crtfastmath.o%s} \ - %{shared:crtendS.o%s}%{!shared:crtend.o%s} crtn.o%s" + %{shared|pie:crtendS.o%s;:crtend.o%s} crtn.o%s" /* We support #pragma. */ #define HANDLE_SYSV_PRAGMA 1 diff --git a/gcc/config/arm/linux-gas.h b/gcc/config/arm/linux-gas.h index 37d788aeb9a6..f3ed5f886700 100644 --- a/gcc/config/arm/linux-gas.h +++ b/gcc/config/arm/linux-gas.h @@ -31,7 +31,7 @@ #define DEFAULT_SIGNED_CHAR 0 #undef SUBTARGET_CPP_SPEC -#define SUBTARGET_CPP_SPEC "%{posix:-D_POSIX_SOURCE} %{fPIC:-D__PIC__ -D__pic__} %{fpic:-D__PIC__ -D__pic__}" +#define SUBTARGET_CPP_SPEC "%{posix:-D_POSIX_SOURCE} %{fPIC|fPIE:-D__PIC__ -D__pic__} %{fpic|fpie:-D__PIC__ -D__pic__}" #undef SIZE_TYPE #define SIZE_TYPE "unsigned int" diff --git a/gcc/config/arm/netbsd-elf.h b/gcc/config/arm/netbsd-elf.h index 1e4c9301fca1..91ba9cd445c1 100644 --- a/gcc/config/arm/netbsd-elf.h +++ b/gcc/config/arm/netbsd-elf.h @@ -59,7 +59,7 @@ #undef SUBTARGET_EXTRA_ASM_SPEC #define SUBTARGET_EXTRA_ASM_SPEC \ - "-matpcs %{fpic:-k} %{fPIC:-k}" + "-matpcs %{fpic|fpie:-k} %{fPIC|fPIE:-k}" /* Default floating point model is soft-VFP. FIXME: -mhard-float currently implies FPA. */ diff --git a/gcc/config/arm/semi.h b/gcc/config/arm/semi.h index a7addee574ee..8847f8c2369d 100644 --- a/gcc/config/arm/semi.h +++ b/gcc/config/arm/semi.h @@ -59,7 +59,7 @@ binutils can't. */ #ifndef ASM_SPEC #define ASM_SPEC "\ -%{fpic: -k} %{fPIC: -k} \ +%{fpic|fpie: -k} %{fPIC|fPIE: -k} \ %{mbig-endian:-EB} \ %{mcpu=*:-mcpu=%*} \ %{march=*:-march=%*} \ diff --git a/gcc/config/cris/linux.h b/gcc/config/cris/linux.h index 6893d7f39b16..288c2856ee63 100644 --- a/gcc/config/cris/linux.h +++ b/gcc/config/cris/linux.h @@ -60,7 +60,7 @@ Boston, MA 02111-1307, USA. */ #define CRIS_ASM_SUBTARGET_SPEC \ "--em=criself\ %{!fleading-underscore:--no-underscore}\ - %{fPIC|fpic: --pic}" + %{fPIC|fpic|fPIE|fpie: --pic}" /* Provide a legacy -mlinux option. */ #undef CRIS_SUBTARGET_SWITCHES diff --git a/gcc/config/freebsd-spec.h b/gcc/config/freebsd-spec.h index b71a2024d338..2f4261b6abad 100644 --- a/gcc/config/freebsd-spec.h +++ b/gcc/config/freebsd-spec.h @@ -78,7 +78,7 @@ Boston, MA 02111-1307, USA. */ #define FBSD_CPP_SPEC " \ %(cpp_cpu) \ - %{fPIC:-D__PIC__ -D__pic__} %{fpic:-D__PIC__ -D__pic__} \ + %{fPIC|fpic|fPIE|fpie:-D__PIC__ -D__pic__} \ %{posix:-D_POSIX_SOURCE}" /* Provide a STARTFILE_SPEC appropriate for FreeBSD. Here we add diff --git a/gcc/config/frv/frv.h b/gcc/config/frv/frv.h index f7d46c0ab80e..4adcabae8284 100644 --- a/gcc/config/frv/frv.h +++ b/gcc/config/frv/frv.h @@ -86,7 +86,7 @@ %{mmedia} %{mno-media} \ %{mmuladd} %{mno-muladd} \ %{mpack} %{mno-pack} \ - %{fpic: -mpic} %{fPIC: -mPIC} %{mlibrary-pic}}" + %{fpic|fpie: -mpic} %{fPIC|fPIE: -mPIC} %{mlibrary-pic}}" /* Another C string constant used much like `LINK_SPEC'. The difference between the two is that `STARTFILE_SPEC' is used at the very beginning of diff --git a/gcc/config/i386/beos-elf.h b/gcc/config/i386/beos-elf.h index d36975606c67..075e16aefd5e 100644 --- a/gcc/config/i386/beos-elf.h +++ b/gcc/config/i386/beos-elf.h @@ -78,7 +78,7 @@ Boston, MA 02111-1307, USA. */ CC1_SPEC is used for both cc1 and cc1plus. */ #undef CC1_SPEC -#define CC1_SPEC "%{!no-fpic:%{!fPIC:-fpic}} %{!Wmultichar: -Wno-multichar} %(cc1_cpu) %{profile:-p}" +#define CC1_SPEC "%{!no-fpic:%{!fno-pic:%{!fno-pie:%{!fpie:%{!fPIC:%{!fPIE:-fpic}}}}}} %{!Wmultichar: -Wno-multichar} %(cc1_cpu) %{profile:-p}" #undef CC1PLUS_SPEC #define CC1PLUS_SPEC "%{!Wctor-dtor-privacy:-Wno-ctor-dtor-privacy}" diff --git a/gcc/config/i386/freebsd-aout.h b/gcc/config/i386/freebsd-aout.h index 48fea7fb64c1..da3202da451a 100644 --- a/gcc/config/i386/freebsd-aout.h +++ b/gcc/config/i386/freebsd-aout.h @@ -210,7 +210,7 @@ do { \ } while (0) #define AS_NEEDS_DASH_FOR_PIPED_INPUT -#define ASM_SPEC "%{fpic:-k} %{fPIC:-k}" +#define ASM_SPEC "%{fpic|fpie|fPIC|fPIE:-k}" #define LINK_SPEC \ "%{p:%e`-p' not supported; use `-pg' and gprof(1)} \ %{shared:-Bshareable} \ diff --git a/gcc/config/i386/linux64.h b/gcc/config/i386/linux64.h index 591e10df34b4..575cbee10cce 100644 --- a/gcc/config/i386/linux64.h +++ b/gcc/config/i386/linux64.h @@ -65,17 +65,6 @@ Boston, MA 02111-1307, USA. */ %{!m32:%{!dynamic-linker:-dynamic-linker /lib64/ld-linux-x86-64.so.2}}} \ %{static:-static}}" -#undef STARTFILE_SPEC -#define STARTFILE_SPEC \ - "%{!shared: \ - %{pg:gcrt1.o%s} %{!pg:%{p:gcrt1.o%s} \ - %{!p:%{profile:gcrt1.o%s} %{!profile:crt1.o%s}}}} \ - crti.o%s %{static:crtbeginT.o%s} \ - %{!static:%{!shared:crtbegin.o%s} %{shared:crtbeginS.o%s}}" - -#undef ENDFILE_SPEC -#define ENDFILE_SPEC "%{!shared:crtend.o%s} %{shared:crtendS.o%s} crtn.o%s" - #define MULTILIB_DEFAULTS { "m64" } /* Do code reading to identify a signal frame, and set the frame diff --git a/gcc/config/ia64/linux.h b/gcc/config/ia64/linux.h index e1d60f7d8c48..c24c70c8d5a4 100644 --- a/gcc/config/ia64/linux.h +++ b/gcc/config/ia64/linux.h @@ -21,18 +21,21 @@ do { \ /* Need to override linux.h STARTFILE_SPEC, since it has crtbeginT.o in. */ #undef STARTFILE_SPEC +#ifdef HAVE_LD_PIE #define STARTFILE_SPEC \ - "%{!shared: \ - %{pg:gcrt1.o%s} %{!pg:%{p:gcrt1.o%s} \ - %{!p:%{profile:gcrt1.o%s} \ - %{!profile:crt1.o%s}}}} \ - crti.o%s %{!shared:crtbegin.o%s} %{shared:crtbeginS.o%s}" + "%{!shared: %{pg|p|profile:gcrt1.o%s;pie:Scrt1.o%s;:crt1.o%s}}\ + crti.o%s %{shared|pie:crtbeginS.o%s;:crtbegin.o%s}" +#else +#define STARTFILE_SPEC \ + "%{!shared: %{pg|p|profile:gcrt1.o%s;:crt1.o%s}}\ + crti.o%s %{shared|pie:crtbeginS.o%s;:crtbegin.o%s}" +#endif /* Similar to standard Linux, but adding -ffast-math support. */ #undef ENDFILE_SPEC #define ENDFILE_SPEC \ "%{ffast-math|funsafe-math-optimizations:crtfastmath.o%s} \ - %{!shared:crtend.o%s} %{shared:crtendS.o%s} crtn.o%s" + %{shared|pie:crtendS.o%s;:crtend.o%s} crtn.o%s" /* Define this for shared library support because it isn't in the main linux.h file. */ diff --git a/gcc/config/linux.h b/gcc/config/linux.h index 13f5b627dcac..ea322b36d855 100644 --- a/gcc/config/linux.h +++ b/gcc/config/linux.h @@ -53,14 +53,14 @@ Boston, MA 02111-1307, USA. */ %{!p:%{profile:gcrt1.o%s} \ %{!profile:crt1.o%s}}}} \ crti.o%s %{!shared:crtbegin.o%s} %{shared:crtbeginS.o%s}" +#elif defined HAVE_LD_PIE +#define 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}" #else #define STARTFILE_SPEC \ - "%{!shared: \ - %{pg:gcrt1.o%s} %{!pg:%{p:gcrt1.o%s} \ - %{!p:%{profile:gcrt1.o%s} \ - %{!profile:crt1.o%s}}}} \ - crti.o%s %{static:crtbeginT.o%s}\ - %{!static:%{!shared:crtbegin.o%s} %{shared:crtbeginS.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}" #endif /* Provide a ENDFILE_SPEC appropriate for GNU/Linux. Here we tack on @@ -71,7 +71,7 @@ Boston, MA 02111-1307, USA. */ #undef ENDFILE_SPEC #define ENDFILE_SPEC \ - "%{!shared:crtend.o%s} %{shared:crtendS.o%s} crtn.o%s" + "%{shared|pie:crtendS.o%s;:crtend.o%s} crtn.o%s" /* This is for -profile to use -lc_p instead of -lc. */ #ifndef CC1_SPEC diff --git a/gcc/config/m68k/linux.h b/gcc/config/m68k/linux.h index 5b8bbd248862..9e81a0a81096 100644 --- a/gcc/config/m68k/linux.h +++ b/gcc/config/m68k/linux.h @@ -121,10 +121,10 @@ Boston, MA 02111-1307, USA. */ #undef CPP_SPEC #if TARGET_DEFAULT & MASK_68881 #define CPP_SPEC \ - "%{fPIC:-D__PIC__ -D__pic__} %{fpic:-D__PIC__ -D__pic__} %{!msoft-float:-D__HAVE_68881__} %{posix:-D_POSIX_SOURCE} %{pthread:-D_REENTRANT}" + "%{fPIC|fpic|fPIE|fpie:-D__PIC__ -D__pic__} %{!msoft-float:-D__HAVE_68881__} %{posix:-D_POSIX_SOURCE} %{pthread:-D_REENTRANT}" #else #define CPP_SPEC \ - "%{fPIC:-D__PIC__ -D__pic__} %{fpic:-D__PIC__ -D__pic__} %{m68881:-D__HAVE_68881__} %{posix:-D_POSIX_SOURCE} %{pthread:-D_REENTRANT}" + "%{fPIC|fpic|fPIE|fpie:-D__PIC__ -D__pic__} %{m68881:-D__HAVE_68881__} %{posix:-D_POSIX_SOURCE} %{pthread:-D_REENTRANT}" #endif /* We override the ASM_SPEC from svr4.h because we must pass -m68040 down diff --git a/gcc/config/m68k/netbsd-elf.h b/gcc/config/m68k/netbsd-elf.h index 2d24d4a602eb..0787c6accd64 100644 --- a/gcc/config/m68k/netbsd-elf.h +++ b/gcc/config/m68k/netbsd-elf.h @@ -105,7 +105,7 @@ Boston, MA 02111-1307, USA. */ #define ASM_SPEC \ "%(asm_default_spec) \ %{m68010} %{m68020} %{m68030} %{m68040} %{m68060} \ - %{fpic:-k} %{fPIC:-k -K}" + %{fpic|fpie:-k} %{fPIC|fPIE:-k -K}" #define AS_NEEDS_DASH_FOR_PIPED_INPUT diff --git a/gcc/config/m68k/netbsd.h b/gcc/config/m68k/netbsd.h index 69a88afe0d59..382adc0fa17d 100644 --- a/gcc/config/m68k/netbsd.h +++ b/gcc/config/m68k/netbsd.h @@ -31,7 +31,7 @@ "%{!msoft-float:-D__HAVE_68881__ -D__HAVE_FPU__} %(netbsd_cpp_spec)" #undef ASM_SPEC -#define ASM_SPEC "%{m68030} %{m68040} %{m68060} %{fpic:-k} %{fPIC:-k -K}" +#define ASM_SPEC "%{m68030} %{m68040} %{m68060} %{fpic|fpie:-k} %{fPIC|fPIE:-k -K}" #define AS_NEEDS_DASH_FOR_PIPED_INPUT diff --git a/gcc/config/m68k/openbsd.h b/gcc/config/m68k/openbsd.h index be185dbdc865..48e9eb91e1d1 100644 --- a/gcc/config/m68k/openbsd.h +++ b/gcc/config/m68k/openbsd.h @@ -46,7 +46,7 @@ Boston, MA 02111-1307, USA. */ /* m68k as needs to know about the processor subtype. */ #undef ASM_SPEC -#define ASM_SPEC "%{m68030} %{m68040} %{m68060} %{fpic:-k} %{fPIC:-k -K}" +#define ASM_SPEC "%{m68030} %{m68040} %{m68060} %{fpic|fpie:-k} %{fPIC|fPIE:-k -K}" #define AS_NEEDS_DASH_FOR_PIPED_INPUT diff --git a/gcc/config/mips/linux.h b/gcc/config/mips/linux.h index 8f81bc4497a6..9986fa312f89 100644 --- a/gcc/config/mips/linux.h +++ b/gcc/config/mips/linux.h @@ -163,7 +163,7 @@ void FN () \ #undef SUBTARGET_CPP_SPEC #define SUBTARGET_CPP_SPEC "\ %{fno-PIC:-U__PIC__ -U__pic__} %{fno-pic:-U__PIC__ -U__pic__} \ -%{fPIC:-D__PIC__ -D__pic__} %{fpic:-D__PIC__ -D__pic__} \ +%{fPIC|fPIE|fpic|fpie:-D__PIC__ -D__pic__} \ %{pthread:-D_REENTRANT}" /* From iris5.h */ diff --git a/gcc/config/mips/openbsd.h b/gcc/config/mips/openbsd.h index 73a81926be48..8b1c124cf8e5 100644 --- a/gcc/config/mips/openbsd.h +++ b/gcc/config/mips/openbsd.h @@ -21,7 +21,7 @@ Boston, MA 02111-1307, USA. */ /* Definitions needed for OpenBSD, to avoid picking mips 'defaults'. */ /* GAS must know this. */ -#define SUBTARGET_ASM_SPEC "%{fPIC:-KPIC}" +#define SUBTARGET_ASM_SPEC "%{fPIC|fPIE:-KPIC}" #define AS_NEEDS_DASH_FOR_PIPED_INPUT diff --git a/gcc/config/netbsd-aout.h b/gcc/config/netbsd-aout.h index f7eb1bf14495..f77fc2e2d9b9 100644 --- a/gcc/config/netbsd-aout.h +++ b/gcc/config/netbsd-aout.h @@ -39,7 +39,7 @@ Boston, MA 02111-1307, USA. */ with the options for generating PIC code. */ #undef ASM_SPEC -#define ASM_SPEC "%{fpic:-k} %{fPIC:-k -K}" +#define ASM_SPEC "%{fpic|fpie:-k} %{fPIC|fPIE:-k -K}" #define AS_NEEDS_DASH_FOR_PIPED_INPUT diff --git a/gcc/config/openbsd.h b/gcc/config/openbsd.h index 7eeb8fef06f1..00f645dd9800 100644 --- a/gcc/config/openbsd.h +++ b/gcc/config/openbsd.h @@ -106,7 +106,7 @@ Boston, MA 02111-1307, USA. */ still uses a special flavor of gas that needs to be told when generating pic code. */ #undef ASM_SPEC -#define ASM_SPEC "%{fpic:-k} %{fPIC:-k -K}" +#define ASM_SPEC "%{fpic|fpie:-k} %{fPIC|fPIE:-k -K}" #endif /* Since we use gas, stdin -> - is a good idea. */ diff --git a/gcc/config/pa/pa-linux.h b/gcc/config/pa/pa-linux.h index 1c8266af57ae..fa20da08ed52 100644 --- a/gcc/config/pa/pa-linux.h +++ b/gcc/config/pa/pa-linux.h @@ -66,7 +66,7 @@ Boston, MA 02111-1307, USA. */ while (0) #undef CPP_SPEC -#define CPP_SPEC "%{fPIC:-D__PIC__ -D__pic__} %{fpic:-D__PIC__ -D__pic__} %{posix:-D_POSIX_SOURCE}" +#define CPP_SPEC "%{fPIC|fpic|fPIE|fpie:-D__PIC__ -D__pic__} %{posix:-D_POSIX_SOURCE}" #undef LIB_SPEC #define LIB_SPEC \ diff --git a/gcc/config/rs6000/linux64.h b/gcc/config/rs6000/linux64.h index bd3a6a85b180..5a31366dbf2b 100644 --- a/gcc/config/rs6000/linux64.h +++ b/gcc/config/rs6000/linux64.h @@ -215,14 +215,19 @@ #endif #undef STARTFILE_LINUX_SPEC +#ifdef HAVE_LD_PIE #define STARTFILE_LINUX_SPEC "\ -%{!shared: %{pg:gcrt1.o%s} %{!pg:%{p:gcrt1.o%s} %{!p:crt1.o%s}}} crti.o%s \ -%{static:crtbeginT.o%s} \ -%{!static:%{!shared:crtbegin.o%s} %{shared:crtbeginS.o%s}}" +%{!shared: %{pg|p: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}" +#else +#define STARTFILE_LINUX_SPEC "\ +%{!shared: %{pg|p:gcrt1.o%s;:crt1.o%s}} crti.o%s \ +%{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s}" +#endif #undef ENDFILE_LINUX_SPEC #define ENDFILE_LINUX_SPEC "\ -%{!shared:crtend.o%s} %{shared:crtendS.o%s} crtn.o%s" +%{shared|pie:crtendS.o%s;:crtend.o%s} crtn.o%s" #undef TOC_SECTION_ASM_OP #define TOC_SECTION_ASM_OP "\t.section\t\".toc\",\"aw\"" diff --git a/gcc/config/rs6000/sysv4.h b/gcc/config/rs6000/sysv4.h index d266c283ccad..d91dd3d89154 100644 --- a/gcc/config/rs6000/sysv4.h +++ b/gcc/config/rs6000/sysv4.h @@ -810,7 +810,7 @@ extern int fixuplabelno; #define ASM_SPEC "%(asm_cpu) \ %{.s: %{mregnames} %{mno-regnames}} %{.S: %{mregnames} %{mno-regnames}} \ %{v:-V} %{Qy:} %{!Qn:-Qy} %{n} %{T} %{Ym,*} %{Yd,*} %{Wa,*:%*} \ -%{mrelocatable} %{mrelocatable-lib} %{fpic:-K PIC} %{fPIC:-K PIC} \ +%{mrelocatable} %{mrelocatable-lib} %{fpic|fpie|fPIC|fPIE:-K PIC} \ %{memb|msdata|msdata=eabi: -memb} \ %{mlittle|mlittle-endian:-mlittle; \ mbig|mbig-endian :-mbig; \ @@ -947,8 +947,8 @@ extern int fixuplabelno; #define CPP_SYSV_SPEC \ "%{mrelocatable*: -D_RELOCATABLE} \ -%{fpic: -D__PIC__=1 -D__pic__=1} \ -%{!fpic: %{fPIC: -D__PIC__=2 -D__pic__=2}}" +%{fpic|fpie: -D__PIC__=1 -D__pic__=1} \ +%{!fpic: %{fPIC|fPIE: -D__PIC__=2 -D__pic__=2}}" /* Override rs6000.h definition. */ #undef CPP_SPEC @@ -1107,12 +1107,16 @@ extern int fixuplabelno; %{!shared: %{pg:gcrt1.o%s} %{!pg:%{p:gcrt1.o%s} %{!p:crt1.o%s}}} \ %{mnewlib: ecrti.o%s} %{!mnewlib: crti.o%s} \ %{!shared:crtbegin.o%s} %{shared:crtbeginS.o%s}" +#elif defined HAVE_LD_PIE +#define STARTFILE_LINUX_SPEC "\ +%{!shared: %{pg|p: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}" #else #define STARTFILE_LINUX_SPEC "\ -%{!shared: %{pg:gcrt1.o%s} %{!pg:%{p:gcrt1.o%s} %{!p:crt1.o%s}}} \ -%{mnewlib: ecrti.o%s} %{!mnewlib: crti.o%s} \ -%{static:crtbeginT.o%s} \ -%{!static:%{!shared:crtbegin.o%s} %{shared:crtbeginS.o%s}}" +%{!shared: %{pg|p: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}" #endif #define ENDFILE_LINUX_SPEC "%{!shared:crtend.o%s} %{shared:crtendS.o%s} \ diff --git a/gcc/config/rs6000/vxworks.h b/gcc/config/rs6000/vxworks.h index 6a5c7e98e985..e7a70922e7ac 100644 --- a/gcc/config/rs6000/vxworks.h +++ b/gcc/config/rs6000/vxworks.h @@ -48,8 +48,8 @@ t860: -DCPU=PPC860 -D_SOFT_FLOAT ; \ : -DCPU=PPC604} \ %{!msoft-float:-D__hardfp} \ - %{fpic: -D__PIC__=1 -D__pic__=1 ; \ - fPIC: -D__PIC__=2 -D__pic__=2 } \ + %{fpic|fpie: -D__PIC__=1 -D__pic__=1 ; \ + fPIC|fPIE: -D__PIC__=2 -D__pic__=2 } \ %(cpp_cpu)" #define CC1_SPEC \ diff --git a/gcc/config/sol2.h b/gcc/config/sol2.h index 8dfe8e73a670..92353cff87e1 100644 --- a/gcc/config/sol2.h +++ b/gcc/config/sol2.h @@ -81,7 +81,7 @@ Boston, MA 02111-1307, USA. */ #undef ASM_SPEC #define ASM_SPEC "\ %{v:-V} %{Qy:} %{!Qn:-Qy} %{n} %{T} %{Ym,*} %{Wa,*:%*} -s \ -%{fpic:-K PIC} %{fPIC:-K PIC} \ +%{fpic|fpie|fPIC|fPIE:-K PIC} \ %(asm_cpu) \ " diff --git a/gcc/config/sparc/linux.h b/gcc/config/sparc/linux.h index 23f5892dd19e..63ce3b95e68f 100644 --- a/gcc/config/sparc/linux.h +++ b/gcc/config/sparc/linux.h @@ -57,12 +57,14 @@ Boston, MA 02111-1307, USA. */ "%{!shared: \ %{pg:gcrt1.o%s} %{!pg:%{p:gcrt1.o%s} %{!p:crt1.o%s}}}\ crti.o%s %{!shared:crtbegin.o%s} %{shared:crtbeginS.o%s}" +#elif defined HAVE_LD_PIE +#define STARTFILE_SPEC \ + "%{!shared: %{pg|p: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}" #else #define STARTFILE_SPEC \ - "%{!shared: \ - %{pg:gcrt1.o%s} %{!pg:%{p:gcrt1.o%s} %{!p:crt1.o%s}}}\ - crti.o%s %{static:crtbeginT.o%s}\ - %{!static:%{!shared:crtbegin.o%s} %{shared:crtbeginS.o%s}}" + "%{!shared: %{pg|p:gcrt1.o%s;:crt1.o%s}}\ + crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s}" #endif /* Provide a ENDFILE_SPEC appropriate for GNU/Linux. Here we tack on @@ -74,7 +76,7 @@ Boston, MA 02111-1307, USA. */ #undef ENDFILE_SPEC #define ENDFILE_SPEC \ "%{ffast-math|funsafe-math-optimizations:crtfastmath.o%s} \ - %{!shared:crtend.o%s} %{shared:crtendS.o%s} crtn.o%s" + %{shared|pie:crtendS.o%s;:crtend.o%s} crtn.o%s" /* This is for -profile to use -lc_p instead of -lc. */ #undef CC1_SPEC @@ -112,11 +114,11 @@ Boston, MA 02111-1307, USA. */ #undef CPP_SUBTARGET_SPEC #ifdef USE_GNULIBC_1 #define CPP_SUBTARGET_SPEC \ -"%{fPIC:-D__PIC__ -D__pic__} %{fpic:-D__PIC__ -D__pic__} %{posix:-D_POSIX_SOURCE} \ +"%{fPIC|fPIE|fpic|fpie:-D__PIC__ -D__pic__} %{posix:-D_POSIX_SOURCE} \ %{mlong-double-128:-D__LONG_DOUBLE_128__}" #else #define CPP_SUBTARGET_SPEC \ -"%{fPIC:-D__PIC__ -D__pic__} %{fpic:-D__PIC__ -D__pic__} %{posix:-D_POSIX_SOURCE} \ +"%{fPIC|fPIE|fpic|fpie:-D__PIC__ -D__pic__} %{posix:-D_POSIX_SOURCE} \ %{pthread:-D_REENTRANT} %{mlong-double-128:-D__LONG_DOUBLE_128__}" #endif @@ -192,8 +194,8 @@ Boston, MA 02111-1307, USA. */ It's safe to pass -s always, even if -g is not used. */ #undef ASM_SPEC #define ASM_SPEC \ - "%{V} %{v:%{!V:-V}} %{!Qn:-Qy} %{n} %{T} %{Ym,*} %{Wa,*:%*} -s %{fpic:-K PIC} \ - %{fPIC:-K PIC} %(asm_cpu) %(asm_relax)" + "%{V} %{v:%{!V:-V}} %{!Qn:-Qy} %{n} %{T} %{Ym,*} %{Wa,*:%*} -s \ + %{fpic|fPIC|fpie|fPIE:-K PIC} %(asm_cpu) %(asm_relax)" /* Same as sparc.h */ #undef DBX_REGISTER_NUMBER diff --git a/gcc/config/sparc/linux64.h b/gcc/config/sparc/linux64.h index aed067d9eacd..ecdd5204ee6a 100644 --- a/gcc/config/sparc/linux64.h +++ b/gcc/config/sparc/linux64.h @@ -66,10 +66,15 @@ Boston, MA 02111-1307, USA. */ #undef STARTFILE_SPEC +#ifdef HAVE_LD_PIE #define STARTFILE_SPEC \ - "%{!shared:%{pg:gcrt1.o%s} %{!pg:%{p:gcrt1.o%s} %{!p:crt1.o%s}}}\ - crti.o%s %{static:crtbeginT.o%s}\ - %{!static:%{!shared:crtbegin.o%s} %{shared:crtbeginS.o%s}}" + "%{!shared:%{pg|p:gcrt1.o%s;pie:Scrt1.o%s;:crt1.o%s}}\ + crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbeginS.o%s}" +#else +#define STARTFILE_SPEC \ + "%{!shared:%{pg|p:gcrt1.o%s;:crt1.o%s}}\ + crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbeginS.o%s}" +#endif /* Provide a ENDFILE_SPEC appropriate for GNU/Linux. Here we tack on the GNU/Linux magical crtend.o file (see crtstuff.c) which @@ -80,7 +85,7 @@ Boston, MA 02111-1307, USA. */ #undef ENDFILE_SPEC #define ENDFILE_SPEC \ - "%{!shared:crtend.o%s} %{shared:crtendS.o%s} crtn.o%s\ + "%{shared|pie:crtendS.o%s;:crtend.o%s} crtn.o%s\ %{ffast-math|funsafe-math-optimizations:crtfastmath.o%s}" /* The GNU C++ standard library requires that these macros be defined. */ @@ -124,8 +129,7 @@ Boston, MA 02111-1307, USA. */ #undef CPP_SUBTARGET_SPEC #define CPP_SUBTARGET_SPEC "\ -%{fPIC:-D__PIC__ -D__pic__} \ -%{fpic:-D__PIC__ -D__pic__} \ +%{fPIC|fpic|fPIE|fpie:-D__PIC__ -D__pic__} \ %{posix:-D_POSIX_SOURCE} \ %{pthread:-D_REENTRANT} \ " @@ -254,7 +258,7 @@ Boston, MA 02111-1307, USA. */ %{T} \ %{Ym,*} \ %{Wa,*:%*} \ --s %{fpic:-K PIC} %{fPIC:-K PIC} \ +-s %{fpic|fPIC|fpie|fPIE:-K PIC} \ %{mlittle-endian:-EL} \ %(asm_cpu) %(asm_arch) %(asm_relax)" diff --git a/gcc/config/sparc/netbsd-elf.h b/gcc/config/sparc/netbsd-elf.h index a20fce4edc84..06783f3bf5ce 100644 --- a/gcc/config/sparc/netbsd-elf.h +++ b/gcc/config/sparc/netbsd-elf.h @@ -86,7 +86,7 @@ Boston, MA 02111-1307, USA. */ #define USER_LABEL_PREFIX "" #undef ASM_SPEC -#define ASM_SPEC "%{fpic:-K PIC} %{fPIC:-K PIC} %{V} %{v:%{!V:-V}} \ +#define ASM_SPEC "%{fpic|fPIC|fpie|fPIE:-K PIC} %{V} %{v:%{!V:-V}} \ %{mlittle-endian:-EL} \ %(asm_cpu) %(asm_arch) %(asm_relax)" diff --git a/gcc/config/sparc/openbsd64.h b/gcc/config/sparc/openbsd64.h index 96ddf7949af3..e13c8862554b 100644 --- a/gcc/config/sparc/openbsd64.h +++ b/gcc/config/sparc/openbsd64.h @@ -53,7 +53,7 @@ Boston, MA 02111-1307, USA. */ #undef ASM_SPEC #define ASM_SPEC "\ -%{v:-V} -s %{fpic:-K PIC} %{fPIC:-K PIC} \ +%{v:-V} -s %{fpic|fPIC|fpie|fPIE:-K PIC} \ %{mlittle-endian:-EL} \ %(asm_cpu) %(asm_arch) \ " diff --git a/gcc/config/sparc/sp64-elf.h b/gcc/config/sparc/sp64-elf.h index f442fd86fc66..2782d688c514 100644 --- a/gcc/config/sparc/sp64-elf.h +++ b/gcc/config/sparc/sp64-elf.h @@ -56,7 +56,7 @@ Boston, MA 02111-1307, USA. */ #undef ASM_SPEC #define ASM_SPEC "\ -%{v:-V} -s %{fpic:-K PIC} %{fPIC:-K PIC} \ +%{v:-V} -s %{fpic|fPIC|fpie|fPIE:-K PIC} \ %{mlittle-endian:-EL} \ %(asm_cpu) %(asm_arch) \ " diff --git a/gcc/config/sparc/sparc.h b/gcc/config/sparc/sparc.h index 3ec9cded6e84..e08e4030ec7d 100644 --- a/gcc/config/sparc/sparc.h +++ b/gcc/config/sparc/sparc.h @@ -336,7 +336,7 @@ extern enum cmodel sparc_cmodel; /* Special flags to the Sun-4 assembler when using pipe for input. */ #define ASM_SPEC "\ -%{R} %{!pg:%{!p:%{fpic:-k} %{fPIC:-k}}} %{keep-local-as-symbols:-L} \ +%{R} %{!pg:%{!p:%{fpic|fPIC|fpie|fPIE:-k}}} %{keep-local-as-symbols:-L} \ %(asm_cpu) %(asm_relax)" #define AS_NEEDS_DASH_FOR_PIPED_INPUT diff --git a/gcc/config/sparc/sysv4.h b/gcc/config/sparc/sysv4.h index 1d153c03e663..80defea56fc1 100644 --- a/gcc/config/sparc/sysv4.h +++ b/gcc/config/sparc/sysv4.h @@ -59,7 +59,7 @@ Boston, MA 02111-1307, USA. */ #undef ASM_SPEC #define ASM_SPEC \ "%{v:-V} %{Qy:} %{!Qn:-Qy} %{n} %{T} %{Ym,*} %{Yd,*} %{Wa,*:%*} \ - %{fpic:-K PIC} %{fPIC:-K PIC} %(asm_cpu)" + %{fpic|fPIC|fpie|fPIE:-K PIC} %(asm_cpu)" /* Define the names of various pseudo-op used by the SPARC/svr4 assembler. Note that many of these are different from the typical pseudo-ops used diff --git a/gcc/configure b/gcc/configure index fe5e6b39f7a0..c03bd4d179a1 100755 --- a/gcc/configure +++ b/gcc/configure @@ -8838,11 +8838,32 @@ EOF fi echo "$ac_t""$gcc_cv_ld_eh_frame_hdr" 1>&6 +echo $ac_n "checking linker position independent executable support""... $ac_c" 1>&6 +echo "configure:8843: checking linker position independent executable support" >&5 +gcc_cv_ld_pie=no +if test $in_tree_ld = yes ; then + if test "$gcc_cv_gld_major_version" -eq 2 -a "$gcc_cv_gld_minor_version" -ge 15 -o "$gcc_cv_gld_major_version" -gt 2 && grep 'EMUL = elf' ../ld/Makefile > /dev/null; then + gcc_cv_ld_pie=yes + fi +elif test x$gcc_cv_ld != x; then + # Check if linker supports -pie option + if $gcc_cv_ld --help 2>/dev/null | grep -- -pie > /dev/null; then + gcc_cv_ld_pie=yes + fi +fi +if test x"$gcc_cv_ld_pie" = xyes; then + cat >> confdefs.h <<\EOF +#define HAVE_LD_PIE 1 +EOF + +fi +echo "$ac_t""$gcc_cv_ld_pie" 1>&6 + # Miscellaneous target-specific checks. case "$target" in mips*-*-*) echo $ac_n "checking whether libgloss uses STARTUP directives consistently""... $ac_c" 1>&6 -echo "configure:8846: checking whether libgloss uses STARTUP directives consistently" >&5 +echo "configure:8867: checking whether libgloss uses STARTUP directives consistently" >&5 gcc_cv_mips_libgloss_startup=no gcc_cv_libgloss_srcdir=`echo $srcdir | sed -e 's,/gcc$,,'`/libgloss if test "x$exec_prefix" = xNONE; then @@ -8870,7 +8891,7 @@ EOF echo "$ac_t""$gcc_cv_mips_libgloss_startup" 1>&6 echo $ac_n "checking whether the assembler has explicit relocation support""... $ac_c" 1>&6 -echo "configure:8874: checking whether the assembler has explicit relocation support" >&5 +echo "configure:8895: checking whether the assembler has explicit relocation support" >&5 if test x$gcc_cv_mips_explicit_relocs = x; then gcc_cv_mips_explicit_relocs=no if test x$gcc_cv_as != x; then @@ -9065,7 +9086,7 @@ fi echo $ac_n "checking whether to enable maintainer-specific portions of Makefiles""... $ac_c" 1>&6 -echo "configure:9069: checking whether to enable maintainer-specific portions of Makefiles" >&5 +echo "configure:9090: checking whether to enable maintainer-specific portions of Makefiles" >&5 # Check whether --enable-maintainer-mode or --disable-maintainer-mode was given. if test "${enable_maintainer_mode+set}" = set; then enableval="$enable_maintainer_mode" diff --git a/gcc/configure.in b/gcc/configure.in index f0e5d7524745..a37f1ccfba3b 100644 --- a/gcc/configure.in +++ b/gcc/configure.in @@ -2631,6 +2631,24 @@ if test x"$gcc_cv_ld_eh_frame_hdr" = xyes; then fi AC_MSG_RESULT($gcc_cv_ld_eh_frame_hdr) +AC_MSG_CHECKING(linker position independent executable support) +gcc_cv_ld_pie=no +if test $in_tree_ld = yes ; then + if test "$gcc_cv_gld_major_version" -eq 2 -a "$gcc_cv_gld_minor_version" -ge 15 -o "$gcc_cv_gld_major_version" -gt 2 && grep 'EMUL = elf' ../ld/Makefile > /dev/null; then + gcc_cv_ld_pie=yes + fi +elif test x$gcc_cv_ld != x; then + # Check if linker supports -pie option + if $gcc_cv_ld --help 2>/dev/null | grep -- -pie > /dev/null; then + gcc_cv_ld_pie=yes + fi +fi +if test x"$gcc_cv_ld_pie" = xyes; then + AC_DEFINE(HAVE_LD_PIE, 1, +[Define if your linker supports -pie option.]) +fi +AC_MSG_RESULT($gcc_cv_ld_pie) + # Miscellaneous target-specific checks. case "$target" in mips*-*-*) diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index d7539d29ed78..17584dba87b1 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -310,7 +310,7 @@ in the following sections. @item Linker Options @xref{Link Options,,Options for Linking}. @gccoptlist{@var{object-file-name} -l@var{library} @gol --nostartfiles -nodefaultlibs -nostdlib @gol +-nostartfiles -nodefaultlibs -nostdlib -pie @gol -s -static -static-libgcc -shared -shared-libgcc -symbolic @gol -Wl,@var{option} -Xlinker @var{option} @gol -u @var{symbol}} @@ -672,7 +672,7 @@ in the following sections. -fasynchronous-unwind-tables @gol -finhibit-size-directive -finstrument-functions @gol -fno-common -fno-ident -fno-gnu-linker @gol --fpcc-struct-return -fpic -fPIC @gol +-fpcc-struct-return -fpic -fPIC -fpie -fPIE @gol -freg-struct-return -fshared-data -fshort-enums @gol -fshort-double -fshort-wchar @gol -fverbose-asm -fpack-struct -fstack-check @gol @@ -4815,6 +4815,13 @@ library subroutines. (For example, @samp{__main}, used to ensure C++ constructors will be called; @pxref{Collect2,,@code{collect2}, gccint, GNU Compiler Collection (GCC) Internals}.) +@item -pie +@opindex pie +Produce a position independent executable on targets which support it. +For predictable results, you must also specify the same set of options +that were used to generate code (@option{-fpie}, @option{-fPIE}, +or model suboptions) when you specify this option. + @item -s @opindex s Remove all symbol table and relocation information from the executable. @@ -11040,6 +11047,15 @@ and the SPARC. Position-independent code requires special support, and therefore works only on certain machines. +@item -fpie +@itemx -fPIE +@opindex fpie +@opindex fPIE +These options are similar to @option{-fpic} and @option{-fPIC}, but +generated position independent code can be only linked into executables. +Usually these options are used when @option{-pie} GCC option will be +used during linking. + @item -ffixed-@var{reg} @opindex ffixed Treat the register named @var{reg} as a fixed register; generated code diff --git a/gcc/flags.h b/gcc/flags.h index c90428816d76..766b24dc4d74 100644 --- a/gcc/flags.h +++ b/gcc/flags.h @@ -462,6 +462,16 @@ extern int flag_pedantic_errors; extern int flag_pic; +/* Nonzero if we are compiling position independent code for executable. + 1 vs 2 for a target-dependent "small" or "large" mode. */ + +extern int flag_pie; + +/* Nonzero if we are compiling code for a shared library, zero for + executable. */ + +extern int flag_shlib; + /* Nonzero means generate extra code for exception handling and enable exception handling. */ diff --git a/gcc/gcc.c b/gcc/gcc.c index 1b79f5486b7b..e71a0e85f2f8 100644 --- a/gcc/gcc.c +++ b/gcc/gcc.c @@ -664,6 +664,14 @@ proper position among the other output files. */ #define LINK_GCC_C_SEQUENCE_SPEC "%G %L %G" #endif +#ifndef LINK_PIE_SPEC +#ifdef HAVE_LD_PIE +#define LINK_PIE_SPEC "%{pie:-pie} " +#else +#define LINK_PIE_SPEC "%{pie:} " +#endif +#endif + /* -u* was put back because both BSD and SysV seem to support it. */ /* %{static:} simply prevents an error message if the target machine doesn't handle -static. */ @@ -673,8 +681,8 @@ proper position among the other output files. */ #ifndef LINK_COMMAND_SPEC #define LINK_COMMAND_SPEC "\ %{!fsyntax-only:%{!c:%{!M:%{!MM:%{!E:%{!S:\ - %(linker) %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} %{r} %{s} %{t}\ - %{u*} %{x} %{z} %{Z} %{!A:%{!nostdlib:%{!nostartfiles:%S}}}\ + %(linker) %l " LINK_PIE_SPEC "%X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} %{r}\ + %{s} %{t} %{u*} %{x} %{z} %{Z} %{!A:%{!nostdlib:%{!nostartfiles:%S}}}\ %{static:} %{L*} %(link_libgcc) %o %{fprofile-arcs:-lgcov}\ %{!nostdlib:%{!nodefaultlibs:%(link_gcc_c_sequence)}}\ %{!A:%{!nostdlib:%{!nostartfiles:%E}}} %{T*} }}}}}}" @@ -1021,6 +1029,7 @@ static const struct option_map option_map[] = {"--param", "--param", "a"}, {"--pedantic", "-pedantic", 0}, {"--pedantic-errors", "-pedantic-errors", 0}, + {"--pie", "-pie", 0}, {"--pipe", "-pipe", 0}, {"--prefix", "-B", "a"}, {"--preprocess", "-E", 0}, diff --git a/gcc/toplev.c b/gcc/toplev.c index 6a6e076cd54c..660b4e1efacc 100644 --- a/gcc/toplev.c +++ b/gcc/toplev.c @@ -759,6 +759,17 @@ int flag_delayed_branch; int flag_pic; +/* Nonzero if we are compiling position independent code for executable. + The value is 1 if we are doing "small" pic; value is 2 if we're doing + "large" pic. */ + +int flag_pie; + +/* Nonzero if we are compiling code for a shared library, zero for + executable. */ + +int flag_shlib; + /* Set to the default thread-local storage (tls) model to use. */ enum tls_model flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC; @@ -1156,6 +1167,9 @@ static const lang_independent_options f_options[] = {"pic", &flag_pic, 1, N_("Generate position independent code, if possible") }, {"PIC", &flag_pic, 2, ""}, + {"pie", &flag_pie, 1, + N_("Generate position independent code for executables, if possible") }, + {"PIE", &flag_pie, 2, ""}, {"exceptions", &flag_exceptions, 1, N_("Enable exception handling") }, {"unwind-tables", &flag_unwind_tables, 1, @@ -5338,6 +5352,11 @@ parse_options_and_default_flags (int argc, char **argv) } } + if (flag_pie) + flag_pic = flag_pie; + if (flag_pic && !flag_pie) + flag_shlib = 1; + if (flag_no_inline == 2) flag_no_inline = 0; else diff --git a/gcc/varasm.c b/gcc/varasm.c index 0e9014aaa2fe..cf2722cf2e8e 100644 --- a/gcc/varasm.c +++ b/gcc/varasm.c @@ -5280,7 +5280,7 @@ bool default_binds_local_p (exp) tree exp; { - return default_binds_local_p_1 (exp, flag_pic); + return default_binds_local_p_1 (exp, flag_shlib); } bool