ld: Add -Bno-symbolic

Message ID 20210512061045.1700795-1-maskray@google.com
State New
Headers show
Series
  • ld: Add -Bno-symbolic
Related show

Commit Message

H.J. Lu via Binutils May 12, 2021, 6:10 a.m.
PR 27834
    * ldlex.h (enum option_values): Add OPTION_NO_SYMBOLIC.
    * lexsup.c (ld_options): Add -Bno-symbolic.
    (parse_args): Handle -Bno-symbolic.
    * ld.texi: Document -Bno-symbolic.
    * NEWS: Mention -Bno-symbolic.
    * testsuite/ld-elf/shared.exp: Add a test.
---
 ld/NEWS                        | 2 ++
 ld/ld.texi                     | 5 +++++
 ld/ldlex.h                     | 1 +
 ld/lexsup.c                    | 5 +++++
 ld/testsuite/ld-elf/shared.exp | 7 +++++++
 5 files changed, 20 insertions(+)

-- 
2.31.1.607.g51e8a6a459-goog

Patch

diff --git a/ld/NEWS b/ld/NEWS
index d1aa3b07000..a5ed9058c04 100644
--- a/ld/NEWS
+++ b/ld/NEWS
@@ -8,6 +8,8 @@ 
 * Add -z start-stop-gc to disable special treatment of __start_*/__stop_*
   references when --gc-sections.
 
+* Add -Bno-symbolic to cancel -Bsymbolic and -Bsymbolic-functions.
+
 Changes in 2.36:
 
 * Add libdep plugin, for linking dependencies of static libraries that
diff --git a/ld/ld.texi b/ld/ld.texi
index fe653daacd7..29874688a73 100644
--- a/ld/ld.texi
+++ b/ld/ld.texi
@@ -1633,6 +1633,11 @@  symbols to the definition within the shared library, if any.
 This option is only meaningful on ELF platforms which support shared
 libraries.
 
+@kindex -Bno-symbolic
+@item -Bno-symbolic
+This option can cancel previously specified @samp{-Bsymbolic} and
+@samp{-Bsymbolic-functions}.
+
 @kindex --dynamic-list=@var{dynamic-list-file}
 @item --dynamic-list=@var{dynamic-list-file}
 Specify the name of a dynamic list file to the linker.  This is
diff --git a/ld/ldlex.h b/ld/ldlex.h
index 3ce1ad44716..e0f0241d9cc 100644
--- a/ld/ldlex.h
+++ b/ld/ldlex.h
@@ -54,6 +54,7 @@  enum option_values
   OPTION_OFORMAT,
   OPTION_RELAX,
   OPTION_NO_RELAX,
+  OPTION_NO_SYMBOLIC,
   OPTION_RETAIN_SYMBOLS_FILE,
   OPTION_RPATH,
   OPTION_RPATH_LINK,
diff --git a/ld/lexsup.c b/ld/lexsup.c
index f6b6b2ec202..dcb2d9d9ab3 100644
--- a/ld/lexsup.c
+++ b/ld/lexsup.c
@@ -302,6 +302,8 @@  static const struct ld_option ld_options[] =
     '\0', NULL, NULL, ONE_DASH },
   { {"static", no_argument, NULL, OPTION_NON_SHARED},
     '\0', NULL, NULL, ONE_DASH },
+  { {"Bno-symbolic", no_argument, NULL, OPTION_NO_SYMBOLIC},
+    '\0', NULL, N_("Don't bind global references locally"), ONE_DASH },
   { {"Bsymbolic", no_argument, NULL, OPTION_SYMBOLIC},
     '\0', NULL, N_("Bind global references locally"), ONE_DASH },
   { {"Bsymbolic-functions", no_argument, NULL, OPTION_SYMBOLIC_FUNCTIONS},
@@ -1301,6 +1303,9 @@  parse_args (unsigned argc, char **argv)
 	case OPTION_STATS:
 	  config.stats = true;
 	  break;
+	case OPTION_NO_SYMBOLIC:
+	  opt_symbolic = symbolic_unset;
+	  break;
 	case OPTION_SYMBOLIC:
 	  opt_symbolic = symbolic;
 	  break;
diff --git a/ld/testsuite/ld-elf/shared.exp b/ld/testsuite/ld-elf/shared.exp
index 6bf49785a55..cb9caea13a7 100644
--- a/ld/testsuite/ld-elf/shared.exp
+++ b/ld/testsuite/ld-elf/shared.exp
@@ -618,6 +618,10 @@  set build_tests {
   {"Build libdl2k.so with --export-dynamic-symbol-list=dl2.list and -Bsymbolic"
    "-shared -Wl,--export-dynamic-symbol-list=dl2.list,-Bsymbolic" "-fPIC"
    {dl2.c dl2xxx.c} {} "libdl2k.so"}
+  # Check that -Bno-symbolic cancels -Bsymbolic.
+  {"Build libdl2i.so with -Bsymbolic -Bno-symbolic and --export-dynamic-symbol=foo"
+   "-shared -Wl,-Bsymbolic,-Bno-symbolic,--export-dynamic-symbol=foo" "-fPIC"
+   {dl2.c dl2xxx.c} {} "libdl2l.so"}
   {"Build libdl4a.so with --dynamic-list=dl4.list"
    "-shared -Wl,--dynamic-list=dl4.list" "-fPIC"
    {dl4.c dl4xxx.c} {} "libdl4a.so"}
@@ -1028,6 +1032,9 @@  set run_tests [list \
     [list "Run with libdl2k.so" \
      "-Wl,--no-as-needed tmpdir/libdl2k.so" "" \
      {dl2main.c} "dl2k" "dl2a.out" ] \
+    [list "Run with libdl2l.so" \
+     "-Wl,--no-as-needed tmpdir/libdl2l.so" "" \
+     {dl2main.c} "dl2l" "dl2b.out" ] \
     [list "Run with libdl4a.so" \
      "-Wl,--no-as-needed tmpdir/libdl4a.so" "" \
      {dl4main.c} "dl4a" "dl4a.out" "-fPIC"] \