This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
PATCH: PR ld/15096: DT_RPATH != DT_RUNPATH
- From: "H.J. Lu" <hongjiu dot lu at intel dot com>
- To: binutils at sourceware dot org
- Date: Mon, 4 Feb 2013 15:20:00 -0800
- Subject: PATCH: PR ld/15096: DT_RPATH != DT_RUNPATH
- Reply-to: "H.J. Lu" <hjl dot tools at gmail dot com>
Hi,
We can't replace DT_RPATH with DT_RUNPATH by default since one object's
DT_RUNPATH entry does not affect the search for any other object's
dependencies. This patch enables new tdags on Linux only if -rpath
isn't used. OK to install?
Thanks.
H.J.
---
include/
2013-02-04 H.J. Lu <hongjiu.lu@intel.com>
PR ld/15096
* bfdlink.h (bfd_link_info): Change new_dtags to int.
ld/
2013-02-04 H.J. Lu <hongjiu.lu@intel.com>
PR ld/15096
* ldemul.c (after_parse_default): Set link_info.new_dtags to
FALSE by default.
* ldmain.c (main): Initialize link_info.new_dtags to -1.
* 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/ia64elf.em (gld${EMULATION_NAME}_after_parse): Renamed
to ...
(gld_${EMULATION_NAME}_after_parse): This. Call
gld${EMULATION_NAME}_after_parse instead of after_parse_default.
(LDEMUL_AFTER_PARSE): Set to gld_${EMULATION_NAME}_after_parse.
* emultempl/elf32.em (gld${EMULATION_NAME}_after_parse): New
function.
(ld_${EMULATION_NAME}_emulation): Replace after_parse_default'
with gld${EMULATION_NAME}_after_parse.
ld/testsuite/
2013-02-04 H.J. Lu <hongjiu.lu@intel.com>
PR ld/15096
* ld-elf/new-dtags-1.d: New test.
* ld-elf/new-dtags-2.d: Likewise.
* ld-elf/new-dtags-3.d: Likewise.
* ld-elf/new-dtags-4.d: Likewise.
* ld-elf/new-dtags-5.d: Likewise.
* ld-elf/new-dtags-6.d: Likewise.
* ld-elf/new-dtags-7.d: Likewise.
* ld-elf/new-dtags-8.d: Likewise.
diff --git a/include/bfdlink.h b/include/bfdlink.h
index bf44dee..58a6bc1 100644
--- a/include/bfdlink.h
+++ b/include/bfdlink.h
@@ -365,9 +365,6 @@ struct bfd_link_info
imported symbols. */
unsigned int default_imported_symver: 1;
- /* TRUE if the new ELF dynamic tags are enabled. */
- unsigned int new_dtags: 1;
-
/* FALSE if .eh_frame unwind info should be generated for PLT and other
linker created sections, TRUE if it should be omitted. */
unsigned int no_ld_generated_unwind_info: 1;
@@ -518,6 +515,11 @@ struct bfd_link_info
/* How many spare .dynamic DT_NULL entries should be added? */
unsigned int spare_dynamic_tags;
+ /* TRUE if the new ELF dynamic tags are enabled. Set to TRUE if
+ this feature is explicitly requested by the user, -1 if enabled
+ by default. */
+ int new_dtags;
+
/* May be used to set DT_FLAGS for ELF. */
bfd_vma flags;
diff --git a/ld/emultempl/alphaelf.em b/ld/emultempl/alphaelf.em
index 21064ad..d44de52 100644
--- a/ld/emultempl/alphaelf.em
+++ b/ld/emultempl/alphaelf.em
@@ -80,7 +80,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 f76b95e..0cf5e39 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 c6d5a8d..ae12f5e 100644
--- a/ld/emultempl/crxelf.em
+++ b/ld/emultempl/crxelf.em
@@ -43,7 +43,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 13a1a41..22674da 100644
--- a/ld/emultempl/elf32.em
+++ b/ld/emultempl/elf32.em
@@ -63,6 +63,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);
@@ -105,16 +106,35 @@ gld${EMULATION_NAME}_before_parse (void)
input_flags.dynamic = ${DYNAMIC_LINK-TRUE};
config.has_shared = `if test -n "$GENERATE_SHLIB_SCRIPT" ; then echo TRUE ; else echo FALSE ; fi`;
config.separate_code = `if test "x${SEPARATE_CODE}" = xyes ; then echo TRUE ; else echo FALSE ; fi`;
+}
+
EOF
+fi
+fragment <<EOF
+static void
+gld${EMULATION_NAME}_after_parse (void)
+{
+EOF
+
+if test x"$LDEMUL_AFTER_PARSE" != xgld"$EMULATION_NAME"_after_parse; then
+# Enable the "new" dtags by default only for Linux target emulation if
+# -rpath isn't used.
case ${target} in
*-*-linux-* | *-*-k*bsd*-* | *-*-gnu* | *-*-nacl*)
- fragment <<EOF
- link_info.new_dtags = TRUE;
+ case " ${EMULATION_LIBPATH} " in
+ *" ${EMULATION_NAME} "*)
+fragment <<EOF
+ if (link_info.new_dtags == -1 && command_line.rpath == NULL)
+ link_info.new_dtags = TRUE;
EOF
+ ;;
+ esac
;;
esac
+
fragment <<EOF
+ after_parse_default ();
}
EOF
@@ -2515,7 +2535,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 65c1ea5..b315e51 100644
--- a/ld/emultempl/hppaelf.em
+++ b/ld/emultempl/hppaelf.em
@@ -60,7 +60,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 88d5748..8eca763 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)
+gld_${EMULATION_NAME}_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=gld_${EMULATION_NAME}_after_parse
source_em ${srcdir}/emultempl/needrelax.em
diff --git a/ld/emultempl/mipself.em b/ld/emultempl/mipself.em
index 9ac61a2..d685b87 100644
--- a/ld/emultempl/mipself.em
+++ b/ld/emultempl/mipself.em
@@ -45,7 +45,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/ldemul.c b/ld/ldemul.c
index 85baeab..e97aa35 100644
--- a/ld/ldemul.c
+++ b/ld/ldemul.c
@@ -206,6 +206,9 @@ ldemul_default_target (int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)
void
after_parse_default (void)
{
+ if (link_info.new_dtags == -1)
+ link_info.new_dtags = FALSE;
+
if (entry_symbol.name != NULL
&& (link_info.executable || entry_from_cmdline))
{
diff --git a/ld/ldmain.c b/ld/ldmain.c
index c23c554..c508fc2 100644
--- a/ld/ldmain.c
+++ b/ld/ldmain.c
@@ -290,6 +290,7 @@ main (int argc, char **argv)
link_info.relax_pass = 1;
link_info.pei386_auto_import = -1;
link_info.spare_dynamic_tags = 5;
+ link_info.new_dtags = -1;
link_info.path_separator = ':';
ldfile_add_arch ("");
diff --git a/ld/testsuite/ld-elf/new-dtags-1.d b/ld/testsuite/ld-elf/new-dtags-1.d
new file mode 100644
index 0000000..918a326
--- /dev/null
+++ b/ld/testsuite/ld-elf/new-dtags-1.d
@@ -0,0 +1,9 @@
+#source: start.s
+#readelf: -d -W
+#ld: -shared -rpath .
+#target: *-*-linux* *-*-gnu*
+
+#failif
+#...
+ +0x[0-9a-f]+ +\(RUNPATH\) +Library runpath: +\[.\]
+#...
diff --git a/ld/testsuite/ld-elf/new-dtags-2.d b/ld/testsuite/ld-elf/new-dtags-2.d
new file mode 100644
index 0000000..17be86d
--- /dev/null
+++ b/ld/testsuite/ld-elf/new-dtags-2.d
@@ -0,0 +1,8 @@
+#source: start.s
+#readelf: -d -W
+#ld: -shared -rpath .
+#target: *-*-linux* *-*-gnu*
+
+#...
+ +0x[0-9a-f]+ +\(RPATH\) +Library rpath: +\[.\]
+#pass
diff --git a/ld/testsuite/ld-elf/new-dtags-3.d b/ld/testsuite/ld-elf/new-dtags-3.d
new file mode 100644
index 0000000..4d06639
--- /dev/null
+++ b/ld/testsuite/ld-elf/new-dtags-3.d
@@ -0,0 +1,9 @@
+#source: start.s
+#readelf: -d -W
+#ld: -shared -rpath . --enable-new-dtags
+#target: *-*-linux* *-*-gnu*
+
+#failif
+#...
+ +0x[0-9a-f]+ +\(RPATH\) +Library rpath: +\[.\]
+#...
diff --git a/ld/testsuite/ld-elf/new-dtags-4.d b/ld/testsuite/ld-elf/new-dtags-4.d
new file mode 100644
index 0000000..0df8af6
--- /dev/null
+++ b/ld/testsuite/ld-elf/new-dtags-4.d
@@ -0,0 +1,8 @@
+#source: start.s
+#readelf: -d -W
+#ld: -shared -rpath . --enable-new-dtags
+#target: *-*-linux* *-*-gnu*
+
+#...
+ +0x[0-9a-f]+ +\(RUNPATH\) +Library runpath: +\[.\]
+#pass
diff --git a/ld/testsuite/ld-elf/new-dtags-5.d b/ld/testsuite/ld-elf/new-dtags-5.d
new file mode 100644
index 0000000..eb1a587
--- /dev/null
+++ b/ld/testsuite/ld-elf/new-dtags-5.d
@@ -0,0 +1,9 @@
+#source: start.s
+#readelf: -d -W
+#ld: -shared -z now
+#target: *-*-linux* *-*-gnu*
+
+#failif
+#...
+ 0x[0-9a-f]+ +\(BIND_NOW\) +
+#...
diff --git a/ld/testsuite/ld-elf/new-dtags-6.d b/ld/testsuite/ld-elf/new-dtags-6.d
new file mode 100644
index 0000000..e2734e7
--- /dev/null
+++ b/ld/testsuite/ld-elf/new-dtags-6.d
@@ -0,0 +1,8 @@
+#source: start.s
+#readelf: -d -W
+#ld: -shared -z now
+#target: *-*-linux* *-*-gnu*
+
+#...
+ 0x[0-9a-f]+ +\(FLAGS\) +BIND_NOW
+#pass
diff --git a/ld/testsuite/ld-elf/new-dtags-7.d b/ld/testsuite/ld-elf/new-dtags-7.d
new file mode 100644
index 0000000..fa98065
--- /dev/null
+++ b/ld/testsuite/ld-elf/new-dtags-7.d
@@ -0,0 +1,9 @@
+#source: start.s
+#readelf: -d -W
+#ld: -shared -z now --disable-new-dtags
+#target: *-*-linux* *-*-gnu*
+
+#failif
+#...
+ 0x[0-9a-f]+ +\(FLAGS\) +BIND_NOW
+#pass
diff --git a/ld/testsuite/ld-elf/new-dtags-8.d b/ld/testsuite/ld-elf/new-dtags-8.d
new file mode 100644
index 0000000..421063d
--- /dev/null
+++ b/ld/testsuite/ld-elf/new-dtags-8.d
@@ -0,0 +1,8 @@
+#source: start.s
+#readelf: -d -W
+#ld: -shared -z now --disable-new-dtags
+#target: *-*-linux* *-*-gnu*
+
+#...
+ 0x[0-9a-f]+ +\(BIND_NOW\) +
+#pass