aboutsummaryrefslogtreecommitdiff
path: root/ld
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2017-04-19 01:26:57 +0930
committerAlan Modra <amodra@gmail.com>2017-04-19 20:39:52 +0930
commit954b63d4c8645f86e40c7ef6c6d60acd2bf019de (patch)
tree7e351a33b44fe2672265e418e9d3d4f9e38215d1 /ld
parent951787ed6d13f8f441d93fc3f6fb870c234774af (diff)
downloadgdb-954b63d4c8645f86e40c7ef6c6d60acd2bf019de.zip
gdb-954b63d4c8645f86e40c7ef6c6d60acd2bf019de.tar.gz
gdb-954b63d4c8645f86e40c7ef6c6d60acd2bf019de.tar.bz2
Implement -z dynamic-undefined-weak
-z nodynamic-undefined-weak is only implemented for x86. (The sparc backend has some support code but doesn't enable the option by including ld/emulparams/dynamic_undefined_weak.sh, and since the support looks like it may be broken I haven't enabled it.) This patch adds the complementary -z dynamic-undefined-weak, extends both options to affect building of shared libraries as well as executables, and adds support for the option on powerpc. include/ * bfdlink.h (struct bfd_link_info <dynamic_undefined_weak>): Revise comment. bfd/ * elflink.c (_bfd_elf_adjust_dynamic_symbol): Hide undefweak or make dynamic for info->dynamic_undefined_weak 0 and 1. * elf32-ppc.c:Formatting. (ensure_undefweak_dynamic): Don't make dynamic when info->dynamic_undefined_weak is zero. (allocate_dynrelocs): Discard undefweak dyn_relocs for info->dynamic_undefined_weak. Discard undef dyn_relocs when not default visibility. Discard undef and undefweak dyn_relocs earlier. (ppc_elf_relocate_section): Adjust to suit. * elf64-ppc.c: Formatting. (ensure_undefweak_dynamic): Don't make dynamic when info->dynamic_undefined_weak is zero. (allocate_dynrelocs): Discard undefweak dyn_relocs for info->dynamic_undefined_weak. Discard them earlier. ld/ * ld.texinfo (dynamic-undefined-weak): Document. (nodynamic-undefined-weak): Document that this option now can be used with shared libs. * emulparams/dynamic_undefined_weak.sh: Support -z dynamic-undefined-weak. * emulparams/elf32ppccommon.sh: Include dynamic_undefined_weak.sh. * testsuite/ld-undefined/weak-undef.exp (undef_weak_so), (undef_weak_exe): New. Use them. Add -z dynamic-undefined-weak and -z nodynamic-undefined-weak tests. * Makefile.am: Update powerpc dependencies. * Makefile.in: Regenerate.
Diffstat (limited to 'ld')
-rw-r--r--ld/ChangeLog14
-rw-r--r--ld/Makefile.am21
-rw-r--r--ld/Makefile.in21
-rw-r--r--ld/emulparams/dynamic_undefined_weak.sh13
-rw-r--r--ld/emulparams/elf32ppccommon.sh2
-rw-r--r--ld/ld.texinfo15
-rw-r--r--ld/testsuite/ld-undefined/weak-undef.exp103
7 files changed, 144 insertions, 45 deletions
diff --git a/ld/ChangeLog b/ld/ChangeLog
index a5732a5..c20ed75 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,17 @@
+2017-04-19 Alan Modra <amodra@gmail.com>
+
+ * ld.texinfo (dynamic-undefined-weak): Document.
+ (nodynamic-undefined-weak): Document that this option now can
+ be used with shared libs.
+ * emulparams/dynamic_undefined_weak.sh: Support -z
+ dynamic-undefined-weak.
+ * emulparams/elf32ppccommon.sh: Include dynamic_undefined_weak.sh.
+ * testsuite/ld-undefined/weak-undef.exp (undef_weak_so),
+ (undef_weak_exe): New. Use them. Add -z dynamic-undefined-weak
+ and -z nodynamic-undefined-weak tests.
+ * Makefile.am: Update powerpc dependencies.
+ * Makefile.in: Regenerate.
+
2017-04-17 H.J. Lu <hongjiu.lu@intel.com>
PR ld/21389
diff --git a/ld/Makefile.am b/ld/Makefile.am
index 9dd31ff..3aa7e80 100644
--- a/ld/Makefile.am
+++ b/ld/Makefile.am
@@ -1157,23 +1157,27 @@ eelf32lmip.c: $(srcdir)/emulparams/elf32lmip.sh \
eelf32lppc.c: $(srcdir)/emulparams/elf32lppc.sh \
$(srcdir)/emulparams/elf32ppccommon.sh \
$(srcdir)/emulparams/elf32ppc.sh \
+ $(srcdir)/emulparams/dynamic_undefined_weak.sh \
$(srcdir)/emultempl/ppc32elf.em ldemul-list.h \
$(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
eelf32lppclinux.c: $(srcdir)/emulparams/elf32lppclinux.sh \
$(srcdir)/emulparams/elf32lppc.sh $(srcdir)/emulparams/elf32ppc.sh \
$(srcdir)/emulparams/elf32ppccommon.sh \
+ $(srcdir)/emulparams/dynamic_undefined_weak.sh \
$(srcdir)/emultempl/ppc32elf.em ldemul-list.h \
$(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
eelf32lppcnto.c: $(srcdir)/emulparams/elf32lppcnto.sh \
$(srcdir)/emulparams/elf32ppc.sh $(srcdir)/emulparams/elf32ppccommon.sh \
+ $(srcdir)/emulparams/dynamic_undefined_weak.sh \
$(srcdir)/emultempl/ppc32elf.em ldemul-list.h \
$(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
eelf32lppcsim.c: $(srcdir)/emulparams/elf32lppcsim.sh \
$(srcdir)/emulparams/elf32lppc.sh $(srcdir)/emulparams/elf32ppc.sh \
$(srcdir)/emulparams/elf32ppccommon.sh \
+ $(srcdir)/emulparams/dynamic_undefined_weak.sh \
$(srcdir)/emultempl/ppc32elf.em ldemul-list.h \
$(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
@@ -1253,31 +1257,37 @@ eelf32or1k_linux.c: $(srcdir)/emulparams/elf32or1k_linux.sh \
eelf32ppc.c: $(srcdir)/emulparams/elf32ppc.sh \
$(srcdir)/emulparams/elf32ppccommon.sh \
+ $(srcdir)/emulparams/dynamic_undefined_weak.sh \
$(srcdir)/emultempl/ppc32elf.em ldemul-list.h \
$(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
eelf32ppc_fbsd.c: $(srcdir)/emulparams/elf32ppc_fbsd.sh \
$(srcdir)/emulparams/elf32ppc.sh $(srcdir)/emulparams/elf32ppccommon.sh \
+ $(srcdir)/emulparams/dynamic_undefined_weak.sh \
$(srcdir)/emultempl/ppc32elf.em ldemul-list.h \
$(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
eelf32ppclinux.c: $(srcdir)/emulparams/elf32ppclinux.sh \
$(srcdir)/emulparams/elf32ppc.sh $(srcdir)/emulparams/elf32ppccommon.sh \
+ $(srcdir)/emulparams/dynamic_undefined_weak.sh \
$(srcdir)/emultempl/ppc32elf.em ldemul-list.h \
$(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
eelf32ppcnto.c: $(srcdir)/emulparams/elf32ppcnto.sh \
$(srcdir)/emulparams/elf32ppc.sh $(srcdir)/emulparams/elf32ppccommon.sh \
+ $(srcdir)/emulparams/dynamic_undefined_weak.sh \
$(srcdir)/emultempl/ppc32elf.em ldemul-list.h \
$(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
eelf32ppcsim.c: $(srcdir)/emulparams/elf32ppcsim.sh \
$(srcdir)/emulparams/elf32ppc.sh $(srcdir)/emulparams/elf32ppccommon.sh \
+ $(srcdir)/emulparams/dynamic_undefined_weak.sh \
$(srcdir)/emultempl/ppc32elf.em ldemul-list.h \
$(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
eelf32ppcvxworks.c: $(srcdir)/emulparams/elf32ppcvxworks.sh \
$(srcdir)/emulparams/elf32ppccommon.sh $(srcdir)/emulparams/vxworks.sh \
+ $(srcdir)/emulparams/dynamic_undefined_weak.sh \
$(srcdir)/emultempl/ppc32elf.em ldemul-list.h \
$(srcdir)/emultempl/vxworks.em \
$(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
@@ -1976,8 +1986,9 @@ eelf64hppa.c: $(srcdir)/emulparams/elf64hppa.sh \
$(ELF_DEPS) $(srcdir)/scripttempl/elf64hppa.sc ${GEN_DEPENDS}
eelf64lppc.c: $(srcdir)/emulparams/elf64lppc.sh \
- $(srcdir)/emulparams/elf64ppc.sh $(srcdir)/emultempl/ppc64elf.em \
- ldemul-list.h \
+ $(srcdir)/emulparams/elf64ppc.sh \
+ $(srcdir)/emulparams/dynamic_undefined_weak.sh \
+ $(srcdir)/emultempl/ppc64elf.em ldemul-list.h \
$(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
eelf64lriscv.c: $(srcdir)/emulparams/elf64lriscv.sh \
@@ -2000,11 +2011,13 @@ eelf64mmix.c: $(srcdir)/emulparams/elf64mmix.sh \
$(ELF_DEPS) $(srcdir)/emultempl/mmix-elfnmmo.em \
$(srcdir)/emultempl/mmixelf.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
-eelf64ppc.c: $(srcdir)/emulparams/elf64ppc.sh $(srcdir)/emultempl/ppc64elf.em \
- ldemul-list.h \
+eelf64ppc.c: $(srcdir)/emulparams/elf64ppc.sh \
+ $(srcdir)/emulparams/dynamic_undefined_weak.sh \
+ $(srcdir)/emultempl/ppc64elf.em ldemul-list.h \
$(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
eelf64ppc_fbsd.c: $(srcdir)/emulparams/elf64ppc_fbsd.sh \
+ $(srcdir)/emulparams/dynamic_undefined_weak.sh \
$(srcdir)/emultempl/ppc64elf.em ldemul-list.h \
$(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
diff --git a/ld/Makefile.in b/ld/Makefile.in
index c464302..f485f4f 100644
--- a/ld/Makefile.in
+++ b/ld/Makefile.in
@@ -2721,23 +2721,27 @@ eelf32lmip.c: $(srcdir)/emulparams/elf32lmip.sh \
eelf32lppc.c: $(srcdir)/emulparams/elf32lppc.sh \
$(srcdir)/emulparams/elf32ppccommon.sh \
$(srcdir)/emulparams/elf32ppc.sh \
+ $(srcdir)/emulparams/dynamic_undefined_weak.sh \
$(srcdir)/emultempl/ppc32elf.em ldemul-list.h \
$(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
eelf32lppclinux.c: $(srcdir)/emulparams/elf32lppclinux.sh \
$(srcdir)/emulparams/elf32lppc.sh $(srcdir)/emulparams/elf32ppc.sh \
$(srcdir)/emulparams/elf32ppccommon.sh \
+ $(srcdir)/emulparams/dynamic_undefined_weak.sh \
$(srcdir)/emultempl/ppc32elf.em ldemul-list.h \
$(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
eelf32lppcnto.c: $(srcdir)/emulparams/elf32lppcnto.sh \
$(srcdir)/emulparams/elf32ppc.sh $(srcdir)/emulparams/elf32ppccommon.sh \
+ $(srcdir)/emulparams/dynamic_undefined_weak.sh \
$(srcdir)/emultempl/ppc32elf.em ldemul-list.h \
$(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
eelf32lppcsim.c: $(srcdir)/emulparams/elf32lppcsim.sh \
$(srcdir)/emulparams/elf32lppc.sh $(srcdir)/emulparams/elf32ppc.sh \
$(srcdir)/emulparams/elf32ppccommon.sh \
+ $(srcdir)/emulparams/dynamic_undefined_weak.sh \
$(srcdir)/emultempl/ppc32elf.em ldemul-list.h \
$(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
@@ -2817,31 +2821,37 @@ eelf32or1k_linux.c: $(srcdir)/emulparams/elf32or1k_linux.sh \
eelf32ppc.c: $(srcdir)/emulparams/elf32ppc.sh \
$(srcdir)/emulparams/elf32ppccommon.sh \
+ $(srcdir)/emulparams/dynamic_undefined_weak.sh \
$(srcdir)/emultempl/ppc32elf.em ldemul-list.h \
$(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
eelf32ppc_fbsd.c: $(srcdir)/emulparams/elf32ppc_fbsd.sh \
$(srcdir)/emulparams/elf32ppc.sh $(srcdir)/emulparams/elf32ppccommon.sh \
+ $(srcdir)/emulparams/dynamic_undefined_weak.sh \
$(srcdir)/emultempl/ppc32elf.em ldemul-list.h \
$(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
eelf32ppclinux.c: $(srcdir)/emulparams/elf32ppclinux.sh \
$(srcdir)/emulparams/elf32ppc.sh $(srcdir)/emulparams/elf32ppccommon.sh \
+ $(srcdir)/emulparams/dynamic_undefined_weak.sh \
$(srcdir)/emultempl/ppc32elf.em ldemul-list.h \
$(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
eelf32ppcnto.c: $(srcdir)/emulparams/elf32ppcnto.sh \
$(srcdir)/emulparams/elf32ppc.sh $(srcdir)/emulparams/elf32ppccommon.sh \
+ $(srcdir)/emulparams/dynamic_undefined_weak.sh \
$(srcdir)/emultempl/ppc32elf.em ldemul-list.h \
$(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
eelf32ppcsim.c: $(srcdir)/emulparams/elf32ppcsim.sh \
$(srcdir)/emulparams/elf32ppc.sh $(srcdir)/emulparams/elf32ppccommon.sh \
+ $(srcdir)/emulparams/dynamic_undefined_weak.sh \
$(srcdir)/emultempl/ppc32elf.em ldemul-list.h \
$(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
eelf32ppcvxworks.c: $(srcdir)/emulparams/elf32ppcvxworks.sh \
$(srcdir)/emulparams/elf32ppccommon.sh $(srcdir)/emulparams/vxworks.sh \
+ $(srcdir)/emulparams/dynamic_undefined_weak.sh \
$(srcdir)/emultempl/ppc32elf.em ldemul-list.h \
$(srcdir)/emultempl/vxworks.em \
$(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
@@ -3540,8 +3550,9 @@ eelf64hppa.c: $(srcdir)/emulparams/elf64hppa.sh \
$(ELF_DEPS) $(srcdir)/scripttempl/elf64hppa.sc ${GEN_DEPENDS}
eelf64lppc.c: $(srcdir)/emulparams/elf64lppc.sh \
- $(srcdir)/emulparams/elf64ppc.sh $(srcdir)/emultempl/ppc64elf.em \
- ldemul-list.h \
+ $(srcdir)/emulparams/elf64ppc.sh \
+ $(srcdir)/emulparams/dynamic_undefined_weak.sh \
+ $(srcdir)/emultempl/ppc64elf.em ldemul-list.h \
$(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
eelf64lriscv.c: $(srcdir)/emulparams/elf64lriscv.sh \
@@ -3564,11 +3575,13 @@ eelf64mmix.c: $(srcdir)/emulparams/elf64mmix.sh \
$(ELF_DEPS) $(srcdir)/emultempl/mmix-elfnmmo.em \
$(srcdir)/emultempl/mmixelf.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
-eelf64ppc.c: $(srcdir)/emulparams/elf64ppc.sh $(srcdir)/emultempl/ppc64elf.em \
- ldemul-list.h \
+eelf64ppc.c: $(srcdir)/emulparams/elf64ppc.sh \
+ $(srcdir)/emulparams/dynamic_undefined_weak.sh \
+ $(srcdir)/emultempl/ppc64elf.em ldemul-list.h \
$(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
eelf64ppc_fbsd.c: $(srcdir)/emulparams/elf64ppc_fbsd.sh \
+ $(srcdir)/emulparams/dynamic_undefined_weak.sh \
$(srcdir)/emultempl/ppc64elf.em ldemul-list.h \
$(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
diff --git a/ld/emulparams/dynamic_undefined_weak.sh b/ld/emulparams/dynamic_undefined_weak.sh
index 82d88d6..a20bbd4 100644
--- a/ld/emulparams/dynamic_undefined_weak.sh
+++ b/ld/emulparams/dynamic_undefined_weak.sh
@@ -1,12 +1,15 @@
-PARSE_AND_LIST_OPTIONS_NODYNAMIC_UNDEFINED_WEAK='
+PARSE_AND_LIST_OPTIONS_DYNAMIC_UNDEFINED_WEAK='
fprintf (file, _("\
- -z nodynamic-undefined-weak Do not treat undefined weak symbol as dynamic\n"));
+ -z dynamic-undefined-weak Make undefined weak symbols dynamic\n\
+ -z nodynamic-undefined-weak Do not make undefined weak symbols dynamic\n"));
'
-PARSE_AND_LIST_ARGS_CASE_Z_NODYNAMIC_UNDEFINED_WEAK='
+PARSE_AND_LIST_ARGS_CASE_Z_DYNAMIC_UNDEFINED_WEAK='
+ else if (strcmp (optarg, "dynamic-undefined-weak") == 0)
+ link_info.dynamic_undefined_weak = TRUE;
else if (strcmp (optarg, "nodynamic-undefined-weak") == 0)
link_info.dynamic_undefined_weak = FALSE;
'
-PARSE_AND_LIST_OPTIONS="$PARSE_AND_LIST_OPTIONS $PARSE_AND_LIST_OPTIONS_NODYNAMIC_UNDEFINED_WEAK"
-PARSE_AND_LIST_ARGS_CASE_Z="$PARSE_AND_LIST_ARGS_CASE_Z $PARSE_AND_LIST_ARGS_CASE_Z_NODYNAMIC_UNDEFINED_WEAK"
+PARSE_AND_LIST_OPTIONS="$PARSE_AND_LIST_OPTIONS $PARSE_AND_LIST_OPTIONS_DYNAMIC_UNDEFINED_WEAK"
+PARSE_AND_LIST_ARGS_CASE_Z="$PARSE_AND_LIST_ARGS_CASE_Z $PARSE_AND_LIST_ARGS_CASE_Z_DYNAMIC_UNDEFINED_WEAK"
diff --git a/ld/emulparams/elf32ppccommon.sh b/ld/emulparams/elf32ppccommon.sh
index d00cf68..44edbd0 100644
--- a/ld/emulparams/elf32ppccommon.sh
+++ b/ld/emulparams/elf32ppccommon.sh
@@ -1,5 +1,7 @@
# The PLT-agnostic parts of a generic 32-bit ELF PowerPC target. Included by:
# elf32ppc.sh elf32ppcvxworks.sh elf64ppc.sh
+. ${srcdir}/emulparams/dynamic_undefined_weak.sh
+
TEMPLATE_NAME=elf32
GENERATE_SHLIB_SCRIPT=yes
GENERATE_PIE_SCRIPT=yes
diff --git a/ld/ld.texinfo b/ld/ld.texinfo
index 909342c..2626b5d 100644
--- a/ld/ld.texinfo
+++ b/ld/ld.texinfo
@@ -1231,11 +1231,18 @@ generated by compiler. Updates on protected data symbols by another
module aren't visible to the resulting shared library. Supported for
i386 and x86-64.
+@item dynamic-undefined-weak
+Make undefined weak symbols dynamic when building a dynamic object,
+if they are referenced from a regular object file and not forced local
+by symbol visibility or versioning. Not all targets support this
+option.
+
@item nodynamic-undefined-weak
-Don't treat undefined weak symbols as dynamic when building executable.
-This option overrides linker backend default. It can be used to avoid
-dynamic relocations against undefined weak symbols in executable.
-Supported for i386 and x86-64.
+Do not make undefined weak symbols dynamic when building a dynamic
+object. Not all targets support this option. If neither
+@option{-z nodynamic-undefined-weak} nor @option{-z dynamic-undefined-weak}
+are given, a target may default to either option being in force, or
+make some other selection of undefined weak symbols dynamic.
@item noreloc-overflow
Disable relocation overflow check. This can be used to disable
diff --git a/ld/testsuite/ld-undefined/weak-undef.exp b/ld/testsuite/ld-undefined/weak-undef.exp
index eb28c2c..4ae22cf 100644
--- a/ld/testsuite/ld-undefined/weak-undef.exp
+++ b/ld/testsuite/ld-undefined/weak-undef.exp
@@ -53,6 +53,52 @@ if { ![is_elf_format] && ![is_pecoff_format] } then {
}
}
+proc undef_weak_so { testname opts passval } {
+ global ld
+ global nm
+
+ if {![ld_link $ld tmpdir/weak-fundef.so \
+ "$opts tmpdir/weak-fundef.o"]} then {
+ fail $testname
+ } elseif {![is_remote host] && [which $nm] == 0} then {
+ unresolved $testname
+ } else {
+ set exec_output [run_host_cmd "$nm" "-D tmpdir/weak-fundef.so"]
+ set exec_output [prune_warnings $exec_output]
+
+ set output_regexp ".*w undef_weak_fun.*"
+ if {[regexp $output_regexp $exec_output] == $passval} then {
+ pass $testname
+ } else {
+ fail $testname
+ }
+ return 1
+ }
+ return 0
+}
+
+proc undef_weak_exe { testname opts passval } {
+ global ld
+ global nm
+
+ if {![ld_link $ld tmpdir/weak-fundef \
+ "$opts tmpdir/weak-fundef.o tmpdir/weak-fundef.so"]} then {
+ fail $testname
+ } elseif {![is_remote host] && [which $nm] == 0} then {
+ unresolved $testname
+ } else {
+ set exec_output [run_host_cmd "$nm" "-D tmpdir/weak-fundef"]
+ set exec_output [prune_warnings $exec_output]
+
+ set output_regexp ".*w undef_weak_fun.*"
+ if {[regexp $output_regexp $exec_output] == $passval} then {
+ pass $testname
+ } else {
+ fail $testname
+ }
+ }
+}
+
# When linking a shared lib, weak undefined symbols should become dynamic.
set testname "weak undefined function symbols in shared lib"
@@ -71,39 +117,40 @@ if { $asflags == "" || ![is_elf_format] || ![check_shared_lib_support]} then {
} elseif {![ld_assemble $as "$asflags $srcdir/$subdir/weak-fundef.s" \
tmpdir/weak-fundef.o]} then {
fail $testname
-} elseif {![ld_link $ld tmpdir/weak-fundef.so \
- "--shared tmpdir/weak-fundef.o"]} then {
- fail $testname
-} elseif {![is_remote host] && [which $nm] == 0} then {
- unresolved $testname
-} else {
- set exec_output [run_host_cmd "$nm" "-D tmpdir/weak-fundef.so"]
- set exec_output [prune_warnings $exec_output]
- verbose -log $exec_output
+} elseif { [undef_weak_so $testname "--shared" 1] } then {
- set output_regexp ".*w undef_weak_fun.*"
+ # When linking a dynamic executable, weak undefined symbols become dynamic.
+ set testname "weak undefined function symbols in dynamic exe"
+ undef_weak_exe $testname "--no-as-needed" 1
- if {[regexp $output_regexp $exec_output]} then {
- pass $testname
- } else {
- fail $testname
+ # Find -z options supported by the default emulation
+ set emul [get_target_emul]
+ set cmd [list "$ld --help 2>&1 | sed -e '1,/^$emul:/d;/^\[^ \]*:/,\$d'"]
+ set status [remote_exec host [concat sh -c $cmd]]
+ if { [lindex $status 0] != 0 } {
+ verbose -log "$cmd exited with status [lindex $status 0]"
}
+ set emulopt [lindex $status 1]
- # When linking a dynamic executable, weak undefined symbols become dynamic.
- set testname "weak undefined function symbols in dynamic exe"
+ if { [string first "dynamic-undefined-weak" $emulopt] >= 0 } {
+ # -z dynamic-undefined-weak is supported. Let's see if it works.
- if {![ld_link $ld tmpdir/weak-fundef \
- "--no-as-needed tmpdir/weak-fundef.o tmpdir/weak-fundef.so"]} then {
- fail $testname
- } else {
- set exec_output [run_host_cmd "$nm" "-D tmpdir/weak-fundef"]
- set exec_output [prune_warnings $exec_output]
- verbose -log $exec_output
+ set testname "weak undefined functions in shared lib, no dyn undef weak"
+ undef_weak_so $testname "--shared -z nodynamic-undefined-weak" 0
- if {[regexp $output_regexp $exec_output]} then {
- pass $testname
- } else {
- fail $testname
- }
+ set testname "weak undefined functions in shared lib, dyn undef weak"
+ undef_weak_so $testname "--shared -z dynamic-undefined-weak" 1
+
+ set testname "weak undefined functions in dynamic exe, no dyn undef weak"
+ undef_weak_exe $testname "-z nodynamic-undefined-weak" 0
+
+ set testname "weak undefined functions in dynamic exe, dyn undef weak"
+ undef_weak_exe $testname "-z dynamic-undefined-weak" 1
+
+ set testname "weak undefined functions in pie, no dyn undef weak"
+ undef_weak_exe $testname "-pie -z nodynamic-undefined-weak" 0
+
+ set testname "weak undefined functions in pie, dyn undef weak"
+ undef_weak_exe $testname "-pie -z dynamic-undefined-weak" 1
}
}