From bb68f22c8e648032a0d1c1d17353eec599ff5e6a Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Wed, 20 May 2020 18:31:39 -0700 Subject: [PATCH] ld: Handle --dynamic-list* before -Bsymbolic -Bsymbolic-functions --dynamic-list* should work both before and after -Bsymbolic and -Bsymbolic-functions. PR ld/26018 * lexsup.c (parse_args): Simplify. * testsuite/ld-elf/dl4e.out: New. * testsuite/ld-elf/shared.exp: Updated for PR ld/26018 tests. --- ld/ChangeLog | 7 +++++++ ld/lexsup.c | 37 ++++++++++++++-------------------- ld/testsuite/ld-elf/dl4e.out | 6 ++++++ ld/testsuite/ld-elf/shared.exp | 12 ++++++++--- 4 files changed, 37 insertions(+), 25 deletions(-) create mode 100644 ld/testsuite/ld-elf/dl4e.out diff --git a/ld/ChangeLog b/ld/ChangeLog index 0a2efa13053..533685b363d 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,10 @@ +2020-05-24 Fangrui Song + + PR ld/26018 + * lexsup.c (parse_args): Simplify. + * testsuite/ld-elf/dl4e.out: New. + * testsuite/ld-elf/shared.exp: Updated for PR ld/26018 tests. + 2020-05-23 H.J. Lu PR ld/26018 diff --git a/ld/lexsup.c b/ld/lexsup.c index fe9526b5271..04db2f129f8 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; @@ -1632,6 +1624,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) @@ -1651,25 +1656,13 @@ parse_args (unsigned argc, char **argv) free (link_info.dynamic_list); link_info.dynamic_list = NULL; } - opt_dynamic_list = dynamic_list_unset; break; case symbolic_functions: - opt_dynamic_list = dynamic_list_data; + link_info.dynamic = TRUE; + link_info.dynamic_data = TRUE; 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 00000000000..e5da6e21859 --- /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 33664305150..7d35f3f3795 100644 --- a/ld/testsuite/ld-elf/shared.exp +++ b/ld/testsuite/ld-elf/shared.exp @@ -598,6 +598,9 @@ set build_tests { {"Build libdl2c.so with --dynamic-list-data and dl2xxx.list" "-shared -Wl,--dynamic-list-data,--dynamic-list=dl2xxx.list" "-fPIC" {dl2.c dl2xxx.c} {} "libdl2c.so"} + {"Build libdl2d.so with --dynamic-list-data -Bsymbolic" + "-shared -Wl,-Bsymbolic,--dynamic-list-data" "-fPIC" + {dl2.c dl2xxx.c} {} "libdl2d.so"} {"Build libdl4a.so with --dynamic-list=dl4.list" "-shared -Wl,--dynamic-list=dl4.list" "-fPIC" {dl4.c dl4xxx.c} {} "libdl4a.so"} @@ -874,6 +877,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 +894,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 +994,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.30.2