This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Support PIE on Solaris 12


On Tue, Sep 22, 2015 at 2:30 AM, Rainer Orth
<ro@cebitec.uni-bielefeld.de> wrote:
> "H.J. Lu" <hjl.tools@gmail.com> writes:
>
>> On Mon, Sep 21, 2015 at 6:46 AM, Rainer Orth
>> <ro@cebitec.uni-bielefeld.de> wrote:
>>> "H.J. Lu" <hjl.tools@gmail.com> writes:
>>>
>>>> On Thu, Sep 10, 2015 at 4:40 AM, Rainer Orth
>>>> <ro@cebitec.uni-bielefeld.de> wrote:
>>>>> Alan Modra <amodra@gmail.com> writes:
>>>>>
>>>>>> On Wed, Sep 02, 2015 at 11:05:55AM +0200, Rainer Orth wrote:
>>>>>>> 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_STUB, DF_1_PIE): Define.
>>>>>>>
>>>>>>>      binutils:
>>>>>>>      * readelf.c (process_dynamic_section): Handle DF_1_STUB, DF_1_PIE.
>>>>>>
>>>>>> OK.
>>>>>
>>>>> How should we proceed with this patch?  Keep setting DF_1_PIE
>>>>> Solaris-specific as in the version above you've already approved or set
>>>>> it everywhere as HJ suggested, using the ld part from
>>>>>
>>>>>         https://sourceware.org/ml/binutils/2015-09/msg00035.html
>>>>>
>>>>> instead.
>>>>
>>>> We have set bits in DT_FLAGS_1 which ld supports.  I don't see
>>>> DF_1_PIE is special.
>>>
>>> It's been more than a week since this mail: can I have either approval
>>> or rejection for generically setting DF_1_PIE so I can install either
>>> version of the patch?
>>>
>>
>> Please just set DF_1_PIE unconditionally for PIE.
>
> Here's what I've installed.
>
> Thanks.
>         Rainer
>
>
> 2015-09-03  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>
>
>         ld:
>         * emulparams/solaris2.sh (GENERATE_PIE_SCRIPT): Set to yes.
>
>         * emultempl/elf32.em: Include ldlex.h.
>         (gld${EMULATION_NAME}_handle_option) [GENERATE_PIE_SCRIPT]
>         <OPTION_PIE>: Set DF_1_PIE.
>
>         include/elf:
>         * common.h (DF_1_STUB, DF_1_PIE): Define.
>
>         binutils:
>         * readelf.c (process_dynamic_section): Handle DF_1_STUB, DF_1_PIE.
>

It breaks the linker.  I checked in this patch to fix it.

-- 
H.J.
Subject: [PATCH] Set DF_1_PIE in gld${EMULATION_NAME}_after_parse

We can't add OPTION_PIE to gld${EMULATION_NAME}_handle_option since
it has been handled in parse_args in lexsup.c.  This patch moves
setting DF_1_PIE to gld${EMULATION_NAME}_after_parse.

ld/

* emultempl/alphaelf.em (alpha_after_parse): Call
gld${EMULATION_NAME}_after_parse instead of
after_parse_default.
* emultempl/cr16elf.em (cr16elf_after_parse): Likewise.
* emultempl/crxelf.em (crxelf_after_parse); Likewise.
* emultempl/hppaelf.em (hppaelf_after_parse): Likewise.
* emultempl/mipself.em (mips_after_parse): Likewise.
* emultempl/nds32elf.em (nds32_elf_after_parse): Likewise.
* emultempl/elf32.em: Don't include ldlex.h.
(gld${EMULATION_NAME}_after_parse): New function.
(gld${EMULATION_NAME}_handle_option) [GENERATE_PIE_SCRIPT]
<OPTION_PIE>: Removed.
(ld_${EMULATION_NAME}_emulation): Replace after_parse_default
with gld${EMULATION_NAME}_after_parse.
* emultempl/ia64elf.em (gld${EMULATION_NAME}_after_parse):
Renamed to ...
(ia64elf_after_parse): This.  Call
gld${EMULATION_NAME}_after_parse instead of after_parse_default.
(LDEMUL_AFTER_PARSE): Replace gld${EMULATION_NAME}_after_parse
with ia64elf_after_parse.

ld/testsuite/

* ld-elf/pie.d: New test.
---
 ld/ChangeLog              | 23 +++++++++++++++++++++++
 ld/emultempl/alphaelf.em  |  2 +-
 ld/emultempl/cr16elf.em   |  2 +-
 ld/emultempl/crxelf.em    |  2 +-
 ld/emultempl/elf32.em     | 26 +++++++++++++++++---------
 ld/emultempl/hppaelf.em   |  2 +-
 ld/emultempl/ia64elf.em   |  6 +++---
 ld/emultempl/mipself.em   |  2 +-
 ld/emultempl/nds32elf.em  |  2 +-
 ld/testsuite/ChangeLog    |  4 ++++
 ld/testsuite/ld-elf/pie.d |  8 ++++++++
 11 files changed, 61 insertions(+), 18 deletions(-)
 create mode 100644 ld/testsuite/ld-elf/pie.d

diff --git a/ld/ChangeLog b/ld/ChangeLog
index 88a46c5..93a852a 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,26 @@
+2015-09-22  H.J. Lu  <hongjiu.lu@intel.com>
+
+ * emultempl/alphaelf.em (alpha_after_parse): Call
+ gld${EMULATION_NAME}_after_parse instead of
+ after_parse_default.
+ * emultempl/cr16elf.em (cr16elf_after_parse): Likewise.
+ * emultempl/crxelf.em (crxelf_after_parse); Likewise.
+ * emultempl/hppaelf.em (hppaelf_after_parse): Likewise.
+ * emultempl/mipself.em (mips_after_parse): Likewise.
+ * emultempl/nds32elf.em (nds32_elf_after_parse): Likewise.
+ * emultempl/elf32.em: Don't include ldlex.h.
+ (gld${EMULATION_NAME}_after_parse): New function.
+ (gld${EMULATION_NAME}_handle_option) [GENERATE_PIE_SCRIPT]
+ <OPTION_PIE>: Removed.
+ (ld_${EMULATION_NAME}_emulation): Replace after_parse_default
+ with gld${EMULATION_NAME}_after_parse.
+ * emultempl/ia64elf.em (gld${EMULATION_NAME}_after_parse):
+ Renamed to ...
+ (ia64elf_after_parse): This.  Call
+ gld${EMULATION_NAME}_after_parse instead of after_parse_default.
+ (LDEMUL_AFTER_PARSE): Replace gld${EMULATION_NAME}_after_parse
+ with ia64elf_after_parse.
+
 2015-09-22  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

  * emulparams/solaris2.sh (GENERATE_PIE_SCRIPT): Set to yes.
diff --git a/ld/emultempl/alphaelf.em b/ld/emultempl/alphaelf.em
index 1301c6f..1db94c7 100644
--- a/ld/emultempl/alphaelf.em
+++ b/ld/emultempl/alphaelf.em
@@ -82,7 +82,7 @@ alpha_after_parse (void)
    exp_nameop (SIZEOF_HEADERS, NULL)),
  NULL);

-  after_parse_default ();
+  gld${EMULATION_NAME}_after_parse ();
 }

 static void
diff --git a/ld/emultempl/cr16elf.em b/ld/emultempl/cr16elf.em
index 276dce4..48dcf14 100644
--- a/ld/emultempl/cr16elf.em
+++ b/ld/emultempl/cr16elf.em
@@ -119,7 +119,7 @@ cr16elf_after_parse (void)
      is true the link sometimes fails.  */
   config.magic_demand_paged = FALSE;

-  after_parse_default ();
+  gld${EMULATION_NAME}_after_parse ();
 }

 /* This is called after the sections have been attached to output
diff --git a/ld/emultempl/crxelf.em b/ld/emultempl/crxelf.em
index 8fefb82..172aa9b 100644
--- a/ld/emultempl/crxelf.em
+++ b/ld/emultempl/crxelf.em
@@ -42,7 +42,7 @@ crxelf_after_parse (void)
      is true the link sometimes fails.  */
   config.magic_demand_paged = FALSE;

-  after_parse_default ();
+  gld${EMULATION_NAME}_after_parse ();
 }

 /* This is called after the sections have been attached to output
diff --git a/ld/emultempl/elf32.em b/ld/emultempl/elf32.em
index 5fe576e..b7ddca3 100644
--- a/ld/emultempl/elf32.em
+++ b/ld/emultempl/elf32.em
@@ -49,7 +49,6 @@ fragment <<EOF
 #include "ldmain.h"
 #include "ldmisc.h"
 #include "ldexp.h"
-#include "ldlex.h"
 #include "ldlang.h"
 #include "ldfile.h"
 #include "ldemul.h"
@@ -61,6 +60,7 @@ fragment <<EOF

 /* Declare functions used by various EXTRA_EM_FILEs.  */
 static void gld${EMULATION_NAME}_before_parse (void);
+static void gld${EMULATION_NAME}_after_parse (void);
 static void gld${EMULATION_NAME}_after_open (void);
 static void gld${EMULATION_NAME}_before_allocation (void);
 static void gld${EMULATION_NAME}_after_allocation (void);
@@ -108,6 +108,21 @@ gld${EMULATION_NAME}_before_parse (void)
 EOF
 fi

+if test x"$LDEMUL_AFTER_PARSE" != xgld"$EMULATION_NAME"_after_parse; then
+fragment <<EOF
+
+static void
+gld${EMULATION_NAME}_after_parse (void)
+{
+  if (bfd_link_pie (&link_info))
+    link_info.flags_1 |= (bfd_vma) DF_1_PIE;
+
+  after_parse_default ();
+}
+
+EOF
+fi
+
 if test x"$LDEMUL_RECOGNIZED_FILE" !=
xgld"${EMULATION_NAME}"_load_symbols; then
 fragment <<EOF
 /* Handle the generation of DT_NEEDED tags.  */
@@ -2290,13 +2305,6 @@ fragment <<EOF

 EOF
 fi
-if test x"$GENERATE_PIE_SCRIPT" = xyes; then
-fragment <<EOF
-    case OPTION_PIE:
-      link_info.flags_1 |= (bfd_vma) DF_1_PIE;
-      break;
-EOF
-fi
 fragment <<EOF
     case 'z':
       if (strcmp (optarg, "defs") == 0)
@@ -2459,7 +2467,7 @@ struct ld_emulation_xfer_struct
ld_${EMULATION_NAME}_emulation =
   ${LDEMUL_BEFORE_PARSE-gld${EMULATION_NAME}_before_parse},
   ${LDEMUL_SYSLIB-syslib_default},
   ${LDEMUL_HLL-hll_default},
-  ${LDEMUL_AFTER_PARSE-after_parse_default},
+  ${LDEMUL_AFTER_PARSE-gld${EMULATION_NAME}_after_parse},
   ${LDEMUL_AFTER_OPEN-gld${EMULATION_NAME}_after_open},
   ${LDEMUL_AFTER_ALLOCATION-gld${EMULATION_NAME}_after_allocation},
   ${LDEMUL_SET_OUTPUT_ARCH-set_output_arch_default},
diff --git a/ld/emultempl/hppaelf.em b/ld/emultempl/hppaelf.em
index 26ccc0f..0807149 100644
--- a/ld/emultempl/hppaelf.em
+++ b/ld/emultempl/hppaelf.em
@@ -59,7 +59,7 @@ hppaelf_after_parse (void)
   NULL);
   */

-  after_parse_default ();
+  gld${EMULATION_NAME}_after_parse ();
 }

 /* This is called before the input files are opened.  We create a new
diff --git a/ld/emultempl/ia64elf.em b/ld/emultempl/ia64elf.em
index 4de45e8..ddfa4b5 100644
--- a/ld/emultempl/ia64elf.em
+++ b/ld/emultempl/ia64elf.em
@@ -31,12 +31,12 @@ fragment <<EOF
 static int itanium = 0;

 static void
-gld${EMULATION_NAME}_after_parse (void)
+ia64elf_after_parse (void)
 {
   link_info.relax_pass = 2;
   bfd_elf${ELFSIZE}_ia64_after_parse (itanium);

-  after_parse_default ();
+  gld${EMULATION_NAME}_after_parse ();
 }

 EOF
@@ -61,5 +61,5 @@ PARSE_AND_LIST_ARGS_CASES='
       break;
 '

-LDEMUL_AFTER_PARSE=gld${EMULATION_NAME}_after_parse
+LDEMUL_AFTER_PARSE=ia64elf_after_parse
 source_em ${srcdir}/emultempl/needrelax.em
diff --git a/ld/emultempl/mipself.em b/ld/emultempl/mipself.em
index 0eb0813..1c60c66 100644
--- a/ld/emultempl/mipself.em
+++ b/ld/emultempl/mipself.em
@@ -47,7 +47,7 @@ mips_after_parse (void)
       link_info.emit_hash = TRUE;
       link_info.emit_gnu_hash = FALSE;
     }
-  after_parse_default ();
+  gld${EMULATION_NAME}_after_parse ();
 }

 struct hook_stub_info
diff --git a/ld/emultempl/nds32elf.em b/ld/emultempl/nds32elf.em
index e74652a..73a49f7 100644
--- a/ld/emultempl/nds32elf.em
+++ b/ld/emultempl/nds32elf.em
@@ -94,7 +94,7 @@ nds32_elf_after_parse (void)
       target_optimize = target_optimize & (!NDS32_RELAX_EX9_ON);
     }

-  after_parse_default ();
+  gld${EMULATION_NAME}_after_parse ();
 }

 static void
diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog
index 575d048..78de2b2 100644
--- a/ld/testsuite/ChangeLog
+++ b/ld/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2015-09-22  H.J. Lu  <hongjiu.lu@intel.com>
+
+ * ld-elf/pie.d: New test.
+
 2015-09-18  Alan Modra  <amodra@gmail.com>

  PR ld/18963
diff --git a/ld/testsuite/ld-elf/pie.d b/ld/testsuite/ld-elf/pie.d
new file mode 100644
index 0000000..d68b962
--- /dev/null
+++ b/ld/testsuite/ld-elf/pie.d
@@ -0,0 +1,8 @@
+#source: start.s
+#readelf: -d -W
+#ld: -pie
+#target: *-*-linux* *-*-gnu* *-*-solaris*
+
+#...
+ +0x[0-9a-f]+ +\(FLAGS_1\) +Flags: +PIE
+#pass
-- 
2.4.3


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]