[PATCH] ld: Make --dynamic-list* override -Bsymbolic -Bsymbolic-functions
Fangrui Song
maskray@google.com
Thu May 21 01:31:39 GMT 2020
They aren't used together in reality, so it is safe to change the
semantics. --dynamic-list is refined -Bsymbolic. -Bsymbolic-functions
should be considered as a subset of -Bsymbolic, so --dynamic-list
overridding -Bsymbolic implies that --dynamic-list overridding
-Bsymbolic-functions.
This also helps PR ld/25910, which would make the situation more
difficult to understand.
PR ld/26018
* lexsup.c: Simplify.
* ld.texi: Update documentation.
* testsuite/ld-elf/shared.exp: Update tests.
* testsuite/ld-elf/dl4e.out: New.
---
ld/ld.texi | 3 ++-
ld/lexsup.c | 33 +++++++++++++--------------------
ld/testsuite/ld-elf/dl4e.out | 6 ++++++
ld/testsuite/ld-elf/shared.exp | 10 +++++++---
4 files changed, 28 insertions(+), 24 deletions(-)
create mode 100644 ld/testsuite/ld-elf/dl4e.out
diff --git a/ld/ld.texi b/ld/ld.texi
index 4dc78e65fa..6969e4f4e8 100644
--- a/ld/ld.texi
+++ b/ld/ld.texi
@@ -1496,7 +1496,8 @@ typically used when creating shared libraries to specify a list of
global symbols whose references shouldn't be bound to the definition
within the shared library, or creating dynamically linked executables
to specify a list of symbols which should be added to the symbol table
-in the executable. This option is only meaningful on ELF platforms
+in the executable. This option overrides @option{-Bsymbolic} and
+@option{-Bsymbolic-functions}. This option is only meaningful on ELF platforms
which support shared libraries.
The format of the dynamic list is the same as the version node without
diff --git a/ld/lexsup.c b/ld/lexsup.c
index c02041d5f1..26b14edfa3 100644
--- a/ld/lexsup.c
+++ b/ld/lexsup.c
@@ -1390,22 +1390,16 @@ parse_args (unsigned argc, char **argv)
break;
case OPTION_DYNAMIC_LIST_DATA:
opt_dynamic_list = dynamic_list_data;
- if (opt_symbolic == symbolic)
- opt_symbolic = symbolic_unset;
break;
case OPTION_DYNAMIC_LIST_CPP_TYPEINFO:
lang_append_dynamic_list_cpp_typeinfo ();
if (opt_dynamic_list != dynamic_list_data)
opt_dynamic_list = dynamic_list;
- if (opt_symbolic == symbolic)
- opt_symbolic = symbolic_unset;
break;
case OPTION_DYNAMIC_LIST_CPP_NEW:
lang_append_dynamic_list_cpp_new ();
if (opt_dynamic_list != dynamic_list_data)
opt_dynamic_list = dynamic_list;
- if (opt_symbolic == symbolic)
- opt_symbolic = symbolic_unset;
break;
case OPTION_DYNAMIC_LIST:
/* This option indicates a small script that only specifies
@@ -1422,8 +1416,6 @@ parse_args (unsigned argc, char **argv)
}
if (opt_dynamic_list != dynamic_list_data)
opt_dynamic_list = dynamic_list;
- if (opt_symbolic == symbolic)
- opt_symbolic = symbolic_unset;
break;
case OPTION_WARN_COMMON:
config.warn_common = TRUE;
@@ -1633,6 +1625,19 @@ parse_args (unsigned argc, char **argv)
&& command_line.check_section_addresses < 0)
command_line.check_section_addresses = 0;
+ switch (opt_dynamic_list)
+ {
+ case dynamic_list_unset:
+ break;
+ case dynamic_list_data:
+ link_info.dynamic_data = TRUE;
+ /* Fall through. */
+ case dynamic_list:
+ link_info.dynamic = TRUE;
+ opt_symbolic = symbolic_unset;
+ break;
+ }
+
/* -Bsymbolic and -Bsymbols-functions are for shared library output. */
if (bfd_link_dll (&link_info))
switch (opt_symbolic)
@@ -1659,18 +1664,6 @@ parse_args (unsigned argc, char **argv)
break;
}
- switch (opt_dynamic_list)
- {
- case dynamic_list_unset:
- break;
- case dynamic_list_data:
- link_info.dynamic_data = TRUE;
- /* Fall through. */
- case dynamic_list:
- link_info.dynamic = TRUE;
- break;
- }
-
if (!bfd_link_dll (&link_info))
{
if (command_line.filter_shlib)
diff --git a/ld/testsuite/ld-elf/dl4e.out b/ld/testsuite/ld-elf/dl4e.out
new file mode 100644
index 0000000000..e5da6e2185
--- /dev/null
+++ b/ld/testsuite/ld-elf/dl4e.out
@@ -0,0 +1,6 @@
+bar OK2
+bar OK4
+DSO1
+DSO2
+OK2
+OK4
diff --git a/ld/testsuite/ld-elf/shared.exp b/ld/testsuite/ld-elf/shared.exp
index 3366430515..df810d91d2 100644
--- a/ld/testsuite/ld-elf/shared.exp
+++ b/ld/testsuite/ld-elf/shared.exp
@@ -610,6 +610,7 @@ set build_tests {
{"Build libdl4d.so with --dynamic-list-data and dl4xxx.list"
"-shared -Wl,--dynamic-list-data,--dynamic-list=dl4xxx.list" "-fPIC"
{dl4.c dl4xxx.c} {} "libdl4d.so"}
+ # --dynamic-list* overrides -Bsymbolic*.
{"Build libdl4e.so with -Bsymbolic-functions --dynamic-list-cpp-new"
"-shared -Wl,-Bsymbolic-functions,--dynamic-list-cpp-new" "-fPIC"
{dl4.c dl4xxx.c} {} "libdl4e.so"}
@@ -874,6 +875,9 @@ set run_tests [list \
[list "Run with libdl2c.so" \
"-Wl,--no-as-needed tmpdir/libdl2c.so" "" \
{dl2main.c} "dl2c" "dl2b.out" ] \
+ [list "Run with libdl2d.so" \
+ "-Wl,--no-as-needed tmpdir/libdl2d.so" "" \
+ {dl2main.c} "dl2d" "dl2a.out" ] \
[list "Run with libdl4a.so" \
"-Wl,--no-as-needed tmpdir/libdl4a.so" "" \
{dl4main.c} "dl4a" "dl4a.out" ] \
@@ -888,10 +892,10 @@ set run_tests [list \
{dl4main.c} "dl4d" "dl4b.out" ] \
[list "Run with libdl4e.so" \
"-Wl,--no-as-needed tmpdir/libdl4e.so" "" \
- {dl4main.c} "dl4e" "dl4a.out" ] \
+ {dl4main.c} "dl4e" "dl4e.out" ] \
[list "Run with libdl4f.so" \
"-Wl,--no-as-needed tmpdir/libdl4f.so" "" \
- {dl4main.c} "dl4f" "dl4a.out" ] \
+ {dl4main.c} "dl4f" "dl4e.out" ] \
[list "Run with libdata1.so" \
"-Wl,--no-as-needed tmpdir/libdata1.so" "" \
{dynbss1.c} "dynbss1" "pass.out" ] \
@@ -988,7 +992,7 @@ set dlopen_run_tests [list \
{dl6cmain.c} "dl6c1" "dl6b.out" ] \
[list "Run dl6d1 with --dynamic-list-data and dlopen on libdl6d.so" \
"-Wl,--no-as-needed,--dynamic-list-data $extralibs" "" \
- {dl6dmain.c} "dl6d1" "dl6b.out" ] \
+ {dl6dmain.c} "dl6d1" "dl6a.out" ] \
[list "Run pr21964-2" \
"-Wl,--no-as-needed,-rpath,tmpdir tmpdir/pr21964-2a.so $extralibs" "" \
{pr21964-2c.c} "pr21964-2" "pass.out" ] \
--
2.26.2.761.g0e0b3e54be-goog
More information about the Binutils
mailing list