diff options
author | 2012-08-28 18:59:28 +0000 | |
---|---|---|
committer | 2012-08-28 18:59:28 +0000 | |
commit | 9622a78f2d82a6ba6ae69b32a8dc97de1d2b5596 (patch) | |
tree | 7247d81690d2730234595d0f383fe081b243206f | |
parent | Work around -Wbounded warning by using sizeof(x_fname), not FILNMLEN. The (diff) | |
download | wireguard-openbsd-9622a78f2d82a6ba6ae69b32a8dc97de1d2b5596.tar.xz wireguard-openbsd-9622a78f2d82a6ba6ae69b32a8dc97de1d2b5596.zip |
Add support for PIE-by-default in both ld and gcc. This is a completely
different approach than the one taken in kurt@'s original diff, but deemed
better after discussion and diff exchange with kettenis@ and matthew@.
Lots of feedback by kettenis@ and matthew@, prodding and encouragement by
deraadt@.
ok kettenis@ matthew@
-rw-r--r-- | gnu/gcc/gcc/common.opt | 2 | ||||
-rw-r--r-- | gnu/gcc/gcc/defaults.h | 4 | ||||
-rw-r--r-- | gnu/gcc/gcc/gcc.c | 2 | ||||
-rw-r--r-- | gnu/gcc/gcc/opts.c | 2 | ||||
-rw-r--r-- | gnu/usr.bin/binutils-2.17/Makefile.bsd-wrapper | 3 | ||||
-rw-r--r-- | gnu/usr.bin/binutils-2.17/ld/ldmain.c | 12 | ||||
-rw-r--r-- | gnu/usr.bin/binutils-2.17/ld/lexsup.c | 13 | ||||
-rw-r--r-- | gnu/usr.bin/binutils/Makefile.bsd-wrapper | 3 | ||||
-rw-r--r-- | gnu/usr.bin/binutils/ld/ldmain.c | 12 | ||||
-rw-r--r-- | gnu/usr.bin/binutils/ld/lexsup.c | 13 | ||||
-rw-r--r-- | gnu/usr.bin/cc/Makefile.inc | 3 |
11 files changed, 64 insertions, 5 deletions
diff --git a/gnu/gcc/gcc/common.opt b/gnu/gcc/gcc/common.opt index 8eb5883768e..66499639fc2 100644 --- a/gnu/gcc/gcc/common.opt +++ b/gnu/gcc/gcc/common.opt @@ -677,7 +677,7 @@ Common Report Var(flag_pic,2) Generate position-independent code if possible (large mode) fPIE -Common Report Var(flag_pie,2) +Common Report Var(flag_pie,2) Init(PIE_DEFAULT) Generate position-independent code for executables if possible (large mode) fpic diff --git a/gnu/gcc/gcc/defaults.h b/gnu/gcc/gcc/defaults.h index 6af5f17bd7d..d7d65e85b85 100644 --- a/gnu/gcc/gcc/defaults.h +++ b/gnu/gcc/gcc/defaults.h @@ -900,4 +900,8 @@ Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA #define HARD_REGNO_NREGS_WITH_PADDING(REGNO, MODE) -1 #endif +#ifndef PIE_DEFAULT +#define PIE_DEFAULT 0 +#endif + #endif /* ! GCC_DEFAULTS_H */ diff --git a/gnu/gcc/gcc/gcc.c b/gnu/gcc/gcc/gcc.c index 0b5ee4b15d8..07ed21ebae3 100644 --- a/gnu/gcc/gcc/gcc.c +++ b/gnu/gcc/gcc/gcc.c @@ -684,7 +684,7 @@ proper position among the other output files. */ #ifndef LINK_PIE_SPEC #ifdef HAVE_LD_PIE -#define LINK_PIE_SPEC "%{pie:-pie} " +#define LINK_PIE_SPEC "%{pie:-pie} %{p|pg|nopie:-nopie} " #else #define LINK_PIE_SPEC "%{pie:} " #endif diff --git a/gnu/gcc/gcc/opts.c b/gnu/gcc/gcc/opts.c index c8e32cfb4e1..f84546120f8 100644 --- a/gnu/gcc/gcc/opts.c +++ b/gnu/gcc/gcc/opts.c @@ -570,6 +570,8 @@ decode_options (unsigned int argc, const char **argv) handle_options (argc, argv, lang_mask); + if (flag_pic || profile_flag) + flag_pie = 0; if (flag_pie) flag_pic = flag_pie; if (flag_pic && !flag_pie) diff --git a/gnu/usr.bin/binutils-2.17/Makefile.bsd-wrapper b/gnu/usr.bin/binutils-2.17/Makefile.bsd-wrapper index e6847f456e8..9ae6c7105d5 100644 --- a/gnu/usr.bin/binutils-2.17/Makefile.bsd-wrapper +++ b/gnu/usr.bin/binutils-2.17/Makefile.bsd-wrapper @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.bsd-wrapper,v 1.3 2011/11/16 18:57:54 schwarze Exp $ +# $OpenBSD: Makefile.bsd-wrapper,v 1.4 2012/08/28 18:59:28 pascal Exp $ OLD_TOOLCHAIN=m68k m88k vax @@ -13,6 +13,7 @@ USING_OLD_TOOLCHAIN?=no SUBDIRS= opcodes bfd CONF_SUBDIRS= opcodes bfd +CFLAGS+= ${PIE_DEFAULT} # This allows moving the whole binutils installation around for # testing purposes PREFIX=/usr diff --git a/gnu/usr.bin/binutils-2.17/ld/ldmain.c b/gnu/usr.bin/binutils-2.17/ld/ldmain.c index e948d8b4560..246224072fc 100644 --- a/gnu/usr.bin/binutils-2.17/ld/ldmain.c +++ b/gnu/usr.bin/binutils-2.17/ld/ldmain.c @@ -271,7 +271,11 @@ main (int argc, char **argv) link_info.emitrelocations = FALSE; link_info.task_link = FALSE; link_info.shared = FALSE; +#ifdef PIE_DEFAULT + link_info.pie = TRUE; +#else link_info.pie = FALSE; +#endif link_info.executable = FALSE; link_info.symbolic = FALSE; link_info.export_dynamic = FALSE; @@ -338,6 +342,14 @@ main (int argc, char **argv) ldemul_set_symbols (); + if (! link_info.shared && link_info.pie) + { + if (link_info.relocatable) + link_info.pie = FALSE; + else + link_info.shared = TRUE; + } + if (link_info.relocatable) { if (link_info.gc_sections) diff --git a/gnu/usr.bin/binutils-2.17/ld/lexsup.c b/gnu/usr.bin/binutils-2.17/ld/lexsup.c index 77c68667ebb..654edb52f27 100644 --- a/gnu/usr.bin/binutils-2.17/ld/lexsup.c +++ b/gnu/usr.bin/binutils-2.17/ld/lexsup.c @@ -149,6 +149,7 @@ enum option_values OPTION_ACCEPT_UNKNOWN_INPUT_ARCH, OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH, OPTION_PIE, + OPTION_NOPIE, OPTION_UNRESOLVED_SYMBOLS, OPTION_WARN_UNRESOLVED_SYMBOLS, OPTION_ERROR_UNRESOLVED_SYMBOLS, @@ -448,6 +449,8 @@ static const struct ld_option ld_options[] = '\0', NULL, N_("Create a position independent executable"), ONE_DASH }, { {"pic-executable", no_argument, NULL, OPTION_PIE}, '\0', NULL, NULL, TWO_DASHES }, + { {"nopie", no_argument, NULL, OPTION_NOPIE}, + '\0', NULL, N_("Do not create a position independent executable"), ONE_DASH }, { {"sort-common", no_argument, NULL, OPTION_SORT_COMMON}, '\0', NULL, N_("Sort common symbols by size"), TWO_DASHES }, { {"sort_common", no_argument, NULL, OPTION_SORT_COMMON}, @@ -1073,6 +1076,7 @@ parse_args (unsigned argc, char **argv) if (config.has_shared) { link_info.shared = TRUE; + link_info.pie = FALSE; /* When creating a shared library, the default behaviour is to ignore any unresolved references. */ if (link_info.unresolved_syms_in_objects == RM_NOT_YET_SET) @@ -1092,6 +1096,15 @@ parse_args (unsigned argc, char **argv) else einfo (_("%P%F: -pie not supported\n")); break; + case OPTION_NOPIE: + if (config.has_shared) + { + link_info.shared = FALSE; + link_info.pie = FALSE; + } + else + einfo (_("%P%F: -nopie not supported\n")); + break; case 'h': /* Used on Solaris. */ case OPTION_SONAME: command_line.soname = optarg; diff --git a/gnu/usr.bin/binutils/Makefile.bsd-wrapper b/gnu/usr.bin/binutils/Makefile.bsd-wrapper index 047605b1128..4d469af3a94 100644 --- a/gnu/usr.bin/binutils/Makefile.bsd-wrapper +++ b/gnu/usr.bin/binutils/Makefile.bsd-wrapper @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.bsd-wrapper,v 1.76 2011/10/30 20:57:06 schwarze Exp $ +# $OpenBSD: Makefile.bsd-wrapper,v 1.77 2012/08/28 18:59:28 pascal Exp $ NEW_BINUTILS=alpha amd64 arm hppa hppa64 i386 mips64 powerpc sh sparc sparc64 @@ -13,6 +13,7 @@ USING_NEW_BINUTILS?=no SUBDIRS= opcodes bfd CONF_SUBDIRS= opcodes bfd +CFLAGS+= ${PIE_DEFAULT} # This allows moving the whole binutils installation around for # testing purposes PREFIX=/usr diff --git a/gnu/usr.bin/binutils/ld/ldmain.c b/gnu/usr.bin/binutils/ld/ldmain.c index a5387abf0d7..188422c7b5c 100644 --- a/gnu/usr.bin/binutils/ld/ldmain.c +++ b/gnu/usr.bin/binutils/ld/ldmain.c @@ -286,7 +286,11 @@ main (int argc, char **argv) link_info.emitrelocations = FALSE; link_info.task_link = FALSE; link_info.shared = FALSE; +#ifdef PIE_DEFAULT + link_info.pie = TRUE; +#else link_info.pie = FALSE; +#endif link_info.executable = FALSE; link_info.symbolic = FALSE; link_info.export_dynamic = FALSE; @@ -345,6 +349,14 @@ main (int argc, char **argv) ldemul_set_symbols (); + if (! link_info.shared && link_info.pie) + { + if (link_info.relocatable) + link_info.pie = FALSE; + else + link_info.shared = TRUE; + } + if (link_info.relocatable) { if (command_line.gc_sections) diff --git a/gnu/usr.bin/binutils/ld/lexsup.c b/gnu/usr.bin/binutils/ld/lexsup.c index a1a67be880d..dbcb19880cf 100644 --- a/gnu/usr.bin/binutils/ld/lexsup.c +++ b/gnu/usr.bin/binutils/ld/lexsup.c @@ -140,6 +140,7 @@ enum option_values OPTION_ACCEPT_UNKNOWN_INPUT_ARCH, OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH, OPTION_PIE, + OPTION_NOPIE, OPTION_UNRESOLVED_SYMBOLS, OPTION_WARN_UNRESOLVED_SYMBOLS, OPTION_ERROR_UNRESOLVED_SYMBOLS @@ -383,6 +384,8 @@ static const struct ld_option ld_options[] = '\0', NULL, N_("Create a position independent executable"), ONE_DASH }, { {"pic-executable", no_argument, NULL, OPTION_PIE}, '\0', NULL, NULL, TWO_DASHES }, + { {"nopie", no_argument, NULL, OPTION_NOPIE}, + '\0', NULL, N_("Do not create a position independent executable"), ONE_DASH }, { {"sort-common", no_argument, NULL, OPTION_SORT_COMMON}, '\0', NULL, N_("Sort common symbols by size"), TWO_DASHES }, { {"sort_common", no_argument, NULL, OPTION_SORT_COMMON}, @@ -985,6 +988,7 @@ parse_args (unsigned argc, char **argv) if (config.has_shared) { link_info.shared = TRUE; + link_info.pie = FALSE; /* When creating a shared library, the default behaviour is to ignore any unresolved references. */ if (link_info.unresolved_syms_in_objects == RM_NOT_YET_SET) @@ -1004,6 +1008,15 @@ parse_args (unsigned argc, char **argv) else einfo (_("%P%F: -pie not supported\n")); break; + case OPTION_NOPIE: + if (config.has_shared) + { + link_info.shared = FALSE; + link_info.pie = FALSE; + } + else + einfo (_("%P%F: -nopie not supported\n")); + break; case 'h': /* Used on Solaris. */ case OPTION_SONAME: command_line.soname = optarg; diff --git a/gnu/usr.bin/cc/Makefile.inc b/gnu/usr.bin/cc/Makefile.inc index 9ba8baae570..96a127c109c 100644 --- a/gnu/usr.bin/cc/Makefile.inc +++ b/gnu/usr.bin/cc/Makefile.inc @@ -1,5 +1,5 @@ # $FreeBSD: src/gnu/usr.bin/cc/Makefile.inc,v 1.66.8.1 2009/04/15 03:14:26 kensmith Exp $ -# $OpenBSD: Makefile.inc,v 1.4 2011/03/06 20:18:22 guenther Exp $ +# $OpenBSD: Makefile.inc,v 1.5 2012/08/28 18:59:28 pascal Exp $ .include "../Makefile.inc" @@ -23,6 +23,7 @@ GCC_TARGET= ${TARGET_ARCH}-unknown-openbsd${OSREV} CFLAGS+= -DIN_GCC -DHAVE_CONFIG_H CFLAGS+= -DPREFIX=\"${TOOLS_PREFIX}/usr\" #CFLAGS+= -DWANT_COMPILER_INVARIANTS +CFLAGS+= ${PIE_DEFAULT} # If building 64-bit longs for the i386, "_LARGE_LONG" should also be defined # to get the proper sizes in limits.h |