diff --git a/lld/ELF/Config.h b/lld/ELF/Config.h --- a/lld/ELF/Config.h +++ b/lld/ELF/Config.h @@ -143,8 +143,8 @@ bool armHasMovtMovw = false; bool armJ1J2BranchEncoding = false; bool asNeeded = false; - bool bsymbolic; - bool bsymbolicFunctions; + bool bsymbolic = false; + bool bsymbolicFunctions = false; bool callGraphProfileSort; bool checkSections; bool compressDebugSections; diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -953,8 +953,13 @@ OPT_no_allow_multiple_definition, false) || hasZOption(args, "muldefs"); config->auxiliaryList = args::getStrings(args, OPT_auxiliary); - config->bsymbolic = args.hasArg(OPT_Bsymbolic); - config->bsymbolicFunctions = args.hasArg(OPT_Bsymbolic_functions); + if (opt::Arg *arg = args.getLastArg(OPT_Bno_symbolic, OPT_Bsymbolic_functions, + OPT_Bsymbolic)) { + if (arg->getOption().matches(OPT_Bsymbolic_functions)) + config->bsymbolicFunctions = true; + else if (arg->getOption().matches(OPT_Bsymbolic)) + config->bsymbolic = true; + } config->checkSections = args.hasFlag(OPT_check_sections, OPT_no_check_sections, true); config->chroot = args.getLastArgValue(OPT_chroot); @@ -1316,8 +1321,7 @@ // When producing an executable, --dynamic-list specifies non-local defined // symbols which are required to be exported. When producing a shared object, // symbols not specified by --dynamic-list are non-preemptible. - config->symbolic = - args.hasArg(OPT_Bsymbolic) || args.hasArg(OPT_dynamic_list); + config->symbolic = config->bsymbolic || args.hasArg(OPT_dynamic_list); for (auto *arg : args.filtered(OPT_dynamic_list)) if (Optional buffer = readFile(arg->getValue())) readDynamicList(*buffer); diff --git a/lld/ELF/Options.td b/lld/ELF/Options.td --- a/lld/ELF/Options.td +++ b/lld/ELF/Options.td @@ -36,10 +36,12 @@ defm auxiliary: Eq<"auxiliary", "Set DT_AUXILIARY field to the specified name">; -def Bsymbolic: F<"Bsymbolic">, HelpText<"Bind defined symbols locally">; +def Bno_symbolic: F<"Bno-symbolic">, HelpText<"Don't bind default visibility defined symbols locally for -shared (default)">; + +def Bsymbolic: F<"Bsymbolic">, HelpText<"Bind default visibility defined symbols locally for -shared">; def Bsymbolic_functions: F<"Bsymbolic-functions">, - HelpText<"Bind defined function symbols locally">; + HelpText<"Bind default visibility defined function symbols locally for -shared">; def Bdynamic: F<"Bdynamic">, HelpText<"Link against shared libraries (default)">; diff --git a/lld/docs/ReleaseNotes.rst b/lld/docs/ReleaseNotes.rst --- a/lld/docs/ReleaseNotes.rst +++ b/lld/docs/ReleaseNotes.rst @@ -24,7 +24,10 @@ ELF Improvements ---------------- -* ... +* ``-Bsymbolic -Bsymbolic-functions`` has been changed to behave the same as ``-Bsymbolic-functions``. This matches GNU ld. + (`D102461 `_) +* ``-Bno-symbolic`` has been added. + (`D102461 `_) Breaking changes ---------------- diff --git a/lld/docs/ld.lld.1 b/lld/docs/ld.lld.1 --- a/lld/docs/ld.lld.1 +++ b/lld/docs/ld.lld.1 @@ -72,10 +72,19 @@ Link against shared libraries. .It Fl -Bstatic , Fl -static , Fl -dn Do not link against shared libraries. -.It Fl -Bsymbolic -Bind defined symbols locally. -.It Fl -Bsymbolic-functions -Bind defined function symbols locally. +.It Fl Bno-symbolic +Don't bind default visibility defined symbols locally for +.Fl shared +(default). +.It Fl Bsymbolic +Bind default visibility defined symbols locally for +.Fl shared. +Also set the +.Dv DF_SYMBOLIC +flag. +.It Fl Bsymbolic-functions +Bind default visibility defined function symbols locally for +.Fl shared. .It Fl -build-id Ns = Ns Ar value Generate a build ID note. .Ar value diff --git a/lld/test/ELF/bsymbolic.s b/lld/test/ELF/bsymbolic.s --- a/lld/test/ELF/bsymbolic.s +++ b/lld/test/ELF/bsymbolic.s @@ -19,8 +19,16 @@ # RUN: ld.lld -shared -Bsymbolic-functions -Bsymbolic %t/a.o %t/b.o -o %t.so # RUN: cmp %t.so %t2.so # RUN: ld.lld -shared -Bsymbolic -Bsymbolic-functions %t/a.o %t/b.o -o %t.so +# RUN: cmp %t.so %t1.so +# RUN: ld.lld -shared -Bno-symbolic -Bsymbolic %t/a.o %t/b.o -o %t.so # RUN: cmp %t.so %t2.so +## -Bno-symbolic can cancel previously specified -Bsymbolic and -Bsymbolic-functions. +# RUN: ld.lld -shared -Bsymbolic -Bno-symbolic %t/a.o %t/b.o -o %t.so +# RUN: cmp %t.so %t0.so +# RUN: ld.lld -shared -Bsymbolic-functions -Bno-symbolic %t/a.o %t/b.o -o %t.so +# RUN: cmp %t.so %t0.so + # REL_DEF: .rela.dyn { # REL_DEF-NEXT: R_X86_64_RELATIVE - # REL_DEF-NEXT: R_X86_64_RELATIVE -