summaryrefslogtreecommitdiff
path: root/gnu/usr.bin/binutils-2.17
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/binutils-2.17
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/binutils-2.17')
-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
3 files changed, 27 insertions, 1 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;