summaryrefslogtreecommitdiff
path: root/gnu/usr.bin
diff options
context:
space:
mode:
authorPascal Stumpf <pascal@cvs.openbsd.org>2012-08-28 18:59:29 +0000
committerPascal Stumpf <pascal@cvs.openbsd.org>2012-08-28 18:59:29 +0000
commitfcbf5c8c7ee754fbc5c55c8791761a8563c6e1fd (patch)
tree1c65ab49096d8f0f94034349938e0daccbe78542 /gnu/usr.bin
parentca3f64c0c488a8aed59da1cc7ab59b24dff6f283 (diff)
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@
Diffstat (limited to 'gnu/usr.bin')
-rw-r--r--gnu/usr.bin/binutils-2.17/Makefile.bsd-wrapper3
-rw-r--r--gnu/usr.bin/binutils-2.17/ld/ldmain.c12
-rw-r--r--gnu/usr.bin/binutils-2.17/ld/lexsup.c13
-rw-r--r--gnu/usr.bin/binutils/Makefile.bsd-wrapper3
-rw-r--r--gnu/usr.bin/binutils/ld/ldmain.c12
-rw-r--r--gnu/usr.bin/binutils/ld/lexsup.c13
-rw-r--r--gnu/usr.bin/cc/Makefile.inc3
7 files changed, 56 insertions, 3 deletions
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