This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Support PIE on Solaris 12
- From: Rainer Orth <ro at CeBiTec dot Uni-Bielefeld dot DE>
- To: binutils at sourceware dot org
- Date: Tue, 25 Aug 2015 13:52:25 +0200
- Subject: Support PIE on Solaris 12
- Authentication-results: sourceware.org; auth=none
As mentioned in
https://gcc.gnu.org/ml/gcc-patches/2015-08/msg01389.html
Solaris 12 will gain support for Position Independent Executables
(PIE). The following patch implements the changes to ld (and a minor
readelf addition) to handle this. Effectively it's only setting the new
DF_1_PIE flag.
The patch was tested with an early version of the new PIC CRTs, the PIE
patch from the message above, and mainline gcc configured both without
and with --enable-default-pie.
Ok for mainline?
Rainer
--
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University
2015-08-25 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
ld:
* emulparams/solaris2.sh (GENERATE_PIE_SCRIPT): Set to yes.
* emultempl/elf32.em (ld_${EMULATION_NAME}_emulation): Allow
overriding gld${EMULATION_NAME}_handle_option.
* emultempl/solaris2.em: Include ldlex.h.
(gld${EMULATION_NAME}_handle_option): Declare.
(elf_solaris2_handle_option): New function.
(LDEMUL_HANDLE_OPTION): Uset it.
include/elf:
* common.h (DF_1_PIE): Define.
binutils:
* readelf.c (process_dynamic_section): Handle DF_1_PIE.
diff --git a/binutils/readelf.c b/binutils/readelf.c
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -9234,6 +9234,11 @@ process_dynamic_section (FILE * file)
printf (" SINGLETON");
val ^= DF_1_SINGLETON;
}
+ if (val & DF_1_PIE)
+ {
+ printf (" PIE");
+ val ^= DF_1_PIE;
+ }
if (val != 0)
printf (" %lx", val);
puts ("");
diff --git a/include/elf/common.h b/include/elf/common.h
--- a/include/elf/common.h
+++ b/include/elf/common.h
@@ -868,6 +868,8 @@
#define DF_1_GLOBAUDIT 0x01000000
#define DF_1_SINGLETON 0x02000000
+#define DF_1_PIE 0x08000000
+
/* Flag values for the DT_FLAGS entry. */
#define DF_ORIGIN (1 << 0)
#define DF_SYMBOLIC (1 << 1)
diff --git a/ld/emulparams/solaris2.sh b/ld/emulparams/solaris2.sh
--- a/ld/emulparams/solaris2.sh
+++ b/ld/emulparams/solaris2.sh
@@ -8,3 +8,5 @@
# File, p.63.
TEXT_START_SYMBOLS='_START_ = .;'
OTHER_END_SYMBOLS='_END_ = .;'
+# Beginning with Solaris 12, there's PIE support.
+GENERATE_PIE_SCRIPT=yes
diff --git a/ld/emultempl/elf32.em b/ld/emultempl/elf32.em
--- a/ld/emultempl/elf32.em
+++ b/ld/emultempl/elf32.em
@@ -2463,7 +2463,7 @@ struct ld_emulation_xfer_struct ld_${EMU
${LDEMUL_SET_SYMBOLS-NULL},
${LDEMUL_PARSE_ARGS-NULL},
gld${EMULATION_NAME}_add_options,
- gld${EMULATION_NAME}_handle_option,
+ ${LDEMUL_HANDLE_OPTION-gld${EMULATION_NAME}_handle_option},
${LDEMUL_UNRECOGNIZED_FILE-NULL},
${LDEMUL_LIST_OPTIONS-${gld_list_options}},
${LDEMUL_RECOGNIZED_FILE-gld${EMULATION_NAME}_load_symbols},
diff --git a/ld/emultempl/solaris2.em b/ld/emultempl/solaris2.em
--- a/ld/emultempl/solaris2.em
+++ b/ld/emultempl/solaris2.em
@@ -29,6 +29,10 @@ fragment <<EOF
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
+#include "ldlex.h"
+
+static bfd_boolean gld${EMULATION_NAME}_handle_option (int);
+
#define TARGET_IS_${EMULATION_NAME}
/* The Solaris 2 ABI requires some global symbols to be present in the
@@ -149,7 +153,21 @@ elf_solaris2_after_allocation (void)
gld${EMULATION_NAME}_after_allocation ();
}
+static bfd_boolean
+elf_solaris2_handle_option (int optc)
+{
+ if (optc == OPTION_PIE)
+ {
+ link_info.flags_1 |= (bfd_vma) DF_1_PIE;
+ /* Necessary to have lexsup.c (parse_args) do its work. */
+ return FALSE;
+ }
+
+ return gld${EMULATION_NAME}_handle_option (optc);
+}
+
EOF
LDEMUL_BEFORE_ALLOCATION=elf_solaris2_before_allocation
LDEMUL_AFTER_ALLOCATION=elf_solaris2_after_allocation
+LDEMUL_HANDLE_OPTION=elf_solaris2_handle_option