[ELF] Add -Bno-symbolic

This option will be available in GNU ld 2.27 (https://sourceware.org/bugzilla/show_bug.cgi?id=27834).
This option can cancel previously specified -Bsymbolic and
-Bsymbolic-functions.  This is useful for excluding some links when the
default uses -Bsymbolic-functions.

Reviewed By: jhenderson, peter.smith

Differential Revision: https://reviews.llvm.org/D102383
This commit is contained in:
Fangrui Song 2021-05-14 09:40:32 -07:00
parent da9b6d0656
commit 4adf7a7604
6 changed files with 39 additions and 13 deletions

View file

@ -143,8 +143,8 @@ struct Configuration {
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;

View file

@ -953,8 +953,13 @@ static void readConfigs(opt::InputArgList &args) {
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 @@ static void readConfigs(opt::InputArgList &args) {
// 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<MemoryBufferRef> buffer = readFile(arg->getValue()))
readDynamicList(*buffer);

View file

@ -36,10 +36,12 @@ multiclass B<string name, string help1, string help2> {
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)">;

View file

@ -24,7 +24,10 @@ Non-comprehensive list of changes in this release
ELF Improvements
----------------
* ...
* ``-Bsymbolic -Bsymbolic-functions`` has been changed to behave the same as ``-Bsymbolic-functions``. This matches GNU ld.
(`D102461 <https://reviews.llvm.org/D102461>`_)
* ``-Bno-symbolic`` has been added.
(`D102461 <https://reviews.llvm.org/D102461>`_)
Breaking changes
----------------

View file

@ -72,10 +72,19 @@ field to the specified name.
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

View file

@ -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 -