aboutsummaryrefslogtreecommitdiff
path: root/ld/testsuite/ld-dynamic
diff options
context:
space:
mode:
authorFangrui Song <maskray@google.com>2020-06-03 06:37:39 -0700
committerH.J. Lu <hjl.tools@gmail.com>2020-06-03 06:37:39 -0700
commit37a141bfed4dd3c33d77c15dfde00e4b4f5b24c7 (patch)
tree05fc3a047c219a7e59357a758472a566e926a570 /ld/testsuite/ld-dynamic
parent433953ffa1a59531a5537327a4e3ce24565e609c (diff)
downloadfsf-binutils-gdb-37a141bfed4dd3c33d77c15dfde00e4b4f5b24c7.zip
fsf-binutils-gdb-37a141bfed4dd3c33d77c15dfde00e4b4f5b24c7.tar.gz
fsf-binutils-gdb-37a141bfed4dd3c33d77c15dfde00e4b4f5b24c7.tar.bz2
ld: Add --export-dynamic-symbol and --export-dynamic-symbol-list
--export-dynamic-symbol-list is like a dynamic list, but without the symbolic property for unspecified symbols. When creating an executable, --export-dynamic-symbol-list is treated like --dynamic-list. When creating a shared library, it is treated like --dynamic-list if -Bsymbolic or --dynamic-list are used, otherwise, it is ignored, so that references to matched symbols will not be bound to the definitions within the shared library. PR ld/25910 * NEWS: Mention --export-dynamic-symbol[-list]. * ld.texi: Document --export-dynamic-symbol[-list]. * ldgram.y: Pass current_dynamic_list_p to lang_append_dynamic_list. * ldlang.c (current_dynamic_list_p): New. (ang_append_dynamic_list): Updated to take a pointer to struct bfd_elf_dynamic_list * argument instead of using link_info.dynamic_list. (lang_append_dynamic_list_cpp_typeinfo): Pass &link_info.dynamic_list to ang_append_dynamic_list. (lang_append_dynamic_list_cpp_new): Likewise. * ldlang.h (current_dynamic_list_p): New. (lang_append_dynamic_list): Add a pointer to struct bfd_elf_dynamic_list * argument. * ldlex.h (option_values): Add OPTION_EXPORT_DYNAMIC_SYMBOL and OPTION_EXPORT_DYNAMIC_SYMBOL_LIST. * lexsup.c (ld_options): Add entries for OPTION_EXPORT_DYNAMIC_SYMBOL and OPTION_EXPORT_DYNAMIC_SYMBOL_LIST. (parse_args): Handle --export-dynamic-symbol and --export-dynamic-symbol-list. * testsuite/ld-dynamic/export-dynamic-symbol-1.d: New. * testsuite/ld-dynamic/export-dynamic-symbol-2.d: New. * testsuite/ld-dynamic/export-dynamic-symbol-glob.d: New. * testsuite/ld-dynamic/export-dynamic-symbol-list-1.d: New. * testsuite/ld-dynamic/export-dynamic-symbol-list-2.d: New. * testsuite/ld-dynamic/export-dynamic-symbol-list-glob.d: New. * testsuite/ld-dynamic/export-dynamic-symbol.exp: New. * testsuite/ld-dynamic/export-dynamic-symbol.s: New. * testsuite/ld-dynamic/foo-bar.list: New. * testsuite/ld-dynamic/foo.list: New. * testsuite/ld-dynamic/foo.s: New. * testsuite/ld-dynamic/fstar.list: New. * testsuite/ld-elf/dlempty.list: New. * testsuite/ld-elf/shared.exp: Add tests for --export-dynamic-symbol and --export-dynamic-symbol-list.
Diffstat (limited to 'ld/testsuite/ld-dynamic')
-rw-r--r--ld/testsuite/ld-dynamic/export-dynamic-symbol-1.d9
-rw-r--r--ld/testsuite/ld-dynamic/export-dynamic-symbol-2.d9
-rw-r--r--ld/testsuite/ld-dynamic/export-dynamic-symbol-glob.d8
-rw-r--r--ld/testsuite/ld-dynamic/export-dynamic-symbol-list-1.d9
-rw-r--r--ld/testsuite/ld-dynamic/export-dynamic-symbol-list-2.d9
-rw-r--r--ld/testsuite/ld-dynamic/export-dynamic-symbol-list-glob.d8
-rw-r--r--ld/testsuite/ld-dynamic/export-dynamic-symbol.exp70
-rw-r--r--ld/testsuite/ld-dynamic/export-dynamic-symbol.s17
-rw-r--r--ld/testsuite/ld-dynamic/foo-bar.list1
-rw-r--r--ld/testsuite/ld-dynamic/foo.list1
-rw-r--r--ld/testsuite/ld-dynamic/foo.s4
-rw-r--r--ld/testsuite/ld-dynamic/fstar.list1
12 files changed, 146 insertions, 0 deletions
diff --git a/ld/testsuite/ld-dynamic/export-dynamic-symbol-1.d b/ld/testsuite/ld-dynamic/export-dynamic-symbol-1.d
new file mode 100644
index 0000000..25ae130
--- /dev/null
+++ b/ld/testsuite/ld-dynamic/export-dynamic-symbol-1.d
@@ -0,0 +1,9 @@
+#name: --export-dynamic-symbol foo archive
+#source: export-dynamic-symbol.s
+#ld: -pie --export-dynamic-symbol foo tmpdir/libpr25910.a
+#nm: -n
+
+#failif
+#...
+[0-9a-f]+ T +foo
+#...
diff --git a/ld/testsuite/ld-dynamic/export-dynamic-symbol-2.d b/ld/testsuite/ld-dynamic/export-dynamic-symbol-2.d
new file mode 100644
index 0000000..d38508a
--- /dev/null
+++ b/ld/testsuite/ld-dynamic/export-dynamic-symbol-2.d
@@ -0,0 +1,9 @@
+#name: -u --export-dynamic-symbol foo archive
+#source: export-dynamic-symbol.s
+#ld: -pie -u foo --export-dynamic-symbol foo --export-dynamic-symbol=bar tmpdir/libpr25910.a
+#nm: -D
+
+#...
+[0-9a-f]+ T +bar
+[0-9a-f]+ T +foo
+#...
diff --git a/ld/testsuite/ld-dynamic/export-dynamic-symbol-glob.d b/ld/testsuite/ld-dynamic/export-dynamic-symbol-glob.d
new file mode 100644
index 0000000..f8187be
--- /dev/null
+++ b/ld/testsuite/ld-dynamic/export-dynamic-symbol-glob.d
@@ -0,0 +1,8 @@
+#name: -u --export-dynamic-symbol "f*" archive
+#source: export-dynamic-symbol.s
+#ld: -pie -u foo --export-dynamic-symbol "f*" tmpdir/libpr25910.a
+#nm: -D
+
+#...
+[0-9a-f]+ T +foo
+#...
diff --git a/ld/testsuite/ld-dynamic/export-dynamic-symbol-list-1.d b/ld/testsuite/ld-dynamic/export-dynamic-symbol-list-1.d
new file mode 100644
index 0000000..fc58af9
--- /dev/null
+++ b/ld/testsuite/ld-dynamic/export-dynamic-symbol-list-1.d
@@ -0,0 +1,9 @@
+#name: --export-dynamic-symbol-list foo archive
+#source: export-dynamic-symbol.s
+#ld: -pie --export-dynamic-symbol-list foo.list tmpdir/libpr25910.a
+#nm: -n
+
+#failif
+#...
+[0-9a-f]+ T +foo
+#...
diff --git a/ld/testsuite/ld-dynamic/export-dynamic-symbol-list-2.d b/ld/testsuite/ld-dynamic/export-dynamic-symbol-list-2.d
new file mode 100644
index 0000000..337f642
--- /dev/null
+++ b/ld/testsuite/ld-dynamic/export-dynamic-symbol-list-2.d
@@ -0,0 +1,9 @@
+#name: -u --export-dynamic-symbol-list foo bar archive
+#source: export-dynamic-symbol.s
+#ld: -pie -u foo --export-dynamic-symbol-list foo-bar.list tmpdir/libpr25910.a
+#nm: -D
+
+#...
+[0-9a-f]+ T +bar
+[0-9a-f]+ T +foo
+#...
diff --git a/ld/testsuite/ld-dynamic/export-dynamic-symbol-list-glob.d b/ld/testsuite/ld-dynamic/export-dynamic-symbol-list-glob.d
new file mode 100644
index 0000000..916a22c
--- /dev/null
+++ b/ld/testsuite/ld-dynamic/export-dynamic-symbol-list-glob.d
@@ -0,0 +1,8 @@
+#name: -u --export-dynamic-symbol-list fstar archive
+#source: export-dynamic-symbol.s
+#ld: -pie -u foo --export-dynamic-symbol-list fstar.list tmpdir/libpr25910.a
+#nm: -D
+
+#...
+[0-9a-f]+ T +foo
+#...
diff --git a/ld/testsuite/ld-dynamic/export-dynamic-symbol.exp b/ld/testsuite/ld-dynamic/export-dynamic-symbol.exp
new file mode 100644
index 0000000..ae53036
--- /dev/null
+++ b/ld/testsuite/ld-dynamic/export-dynamic-symbol.exp
@@ -0,0 +1,70 @@
+# Expect script for ld --export-dynamic-symbol tests
+# Copyright (C) 2020 Free Software Foundation, Inc.
+#
+# This file is part of the GNU Binutils.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+# MA 02110-1301, USA.
+#
+
+if ![is_elf_format] {
+ return
+}
+
+# Skip targets where -shared is not supported
+
+if ![check_shared_lib_support] {
+ return
+}
+
+set old_ASFLAGS $ASFLAGS
+
+# These targets require extra GAS options when building code for shared
+# libraries.
+if [istarget "nds32*-*"] {
+ append ASFLAGS " -mpic"
+}
+if [istarget "tic6x-*-*"] {
+ append ASFLAGS " -mpic -mpid=near"
+}
+if [istarget "sparc*-*-*"] {
+ append ASFLAGS " -K PIC -Av9"
+}
+
+set old_LDFLAGS $LDFLAGS
+
+# These targets require a non-default emulation for successful shared
+# library/executable builds.
+if [istarget "tic6x-*-*"] {
+ append LDFLAGS " -melf32_tic6x_le"
+}
+
+set build_tests {
+ {"Build libpr25910.a"
+ "" "" ""
+ {foo.s} {} "libpr25910.a"}
+}
+
+run_ld_link_tests $build_tests
+
+set test_list [lsort [glob -nocomplain $srcdir/$subdir/export-dynamic-symbol-*.d]]
+foreach test_file $test_list {
+ set test_name [file rootname $test_file]
+ verbose $test_name
+ run_dump_test $test_name
+}
+
+set ASFLAGS $old_ASFLAGS
+set LDFLAGS $old_LDFLAGS
diff --git a/ld/testsuite/ld-dynamic/export-dynamic-symbol.s b/ld/testsuite/ld-dynamic/export-dynamic-symbol.s
new file mode 100644
index 0000000..c55da53
--- /dev/null
+++ b/ld/testsuite/ld-dynamic/export-dynamic-symbol.s
@@ -0,0 +1,17 @@
+ .text
+ .global start /* Used by SH targets. */
+start:
+ .global _start
+_start:
+ .global __start
+__start:
+ .global main /* Used by HPPA targets. */
+main:
+ .globl _main /* Used by LynxOS targets. */
+_main:
+ .word 0
+
+ .section .text.1, "ax"
+ .global bar
+bar:
+ .word 0
diff --git a/ld/testsuite/ld-dynamic/foo-bar.list b/ld/testsuite/ld-dynamic/foo-bar.list
new file mode 100644
index 0000000..87732e1
--- /dev/null
+++ b/ld/testsuite/ld-dynamic/foo-bar.list
@@ -0,0 +1 @@
+{ foo; bar; };
diff --git a/ld/testsuite/ld-dynamic/foo.list b/ld/testsuite/ld-dynamic/foo.list
new file mode 100644
index 0000000..f89f569
--- /dev/null
+++ b/ld/testsuite/ld-dynamic/foo.list
@@ -0,0 +1 @@
+{ foo; };
diff --git a/ld/testsuite/ld-dynamic/foo.s b/ld/testsuite/ld-dynamic/foo.s
new file mode 100644
index 0000000..4a70181
--- /dev/null
+++ b/ld/testsuite/ld-dynamic/foo.s
@@ -0,0 +1,4 @@
+ .text
+ .globl foo
+foo:
+ .byte 0
diff --git a/ld/testsuite/ld-dynamic/fstar.list b/ld/testsuite/ld-dynamic/fstar.list
new file mode 100644
index 0000000..330d1dd
--- /dev/null
+++ b/ld/testsuite/ld-dynamic/fstar.list
@@ -0,0 +1 @@
+{ f*; };