[lld] 4adf7a7 - [ELF] Add -Bno-symbolic
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Fri May 14 09:40:38 PDT 2021
Author: Fangrui Song
Date: 2021-05-14T09:40:32-07:00
New Revision: 4adf7a7604069331849c26c0f808a9bb6e22e461
URL: https://github.com/llvm/llvm-project/commit/4adf7a7604069331849c26c0f808a9bb6e22e461
DIFF: https://github.com/llvm/llvm-project/commit/4adf7a7604069331849c26c0f808a9bb6e22e461.diff
LOG: [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
Added:
Modified:
lld/ELF/Config.h
lld/ELF/Driver.cpp
lld/ELF/Options.td
lld/docs/ReleaseNotes.rst
lld/docs/ld.lld.1
lld/test/ELF/bsymbolic.s
Removed:
################################################################################
diff --git a/lld/ELF/Config.h b/lld/ELF/Config.h
index ab55c60bb6f99..3b13ff773c71b 100644
--- a/lld/ELF/Config.h
+++ b/lld/ELF/Config.h
@@ -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;
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 104742b9d0ec3..c3adeeca6e465 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -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);
diff --git a/lld/ELF/Options.td b/lld/ELF/Options.td
index 8315ab2ff0af6..8af1255eb6efe 100644
--- a/lld/ELF/Options.td
+++ b/lld/ELF/Options.td
@@ -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)">;
diff --git a/lld/docs/ReleaseNotes.rst b/lld/docs/ReleaseNotes.rst
index a3b577e48fb12..84fbc1b72ff8d 100644
--- a/lld/docs/ReleaseNotes.rst
+++ b/lld/docs/ReleaseNotes.rst
@@ -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
----------------
diff --git a/lld/docs/ld.lld.1 b/lld/docs/ld.lld.1
index c230b19ea2712..b338832172b3e 100644
--- a/lld/docs/ld.lld.1
+++ b/lld/docs/ld.lld.1
@@ -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
diff --git a/lld/test/ELF/bsymbolic.s b/lld/test/ELF/bsymbolic.s
index a578234f8ac25..a083d2cebe887 100644
--- 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 -
More information about the llvm-commits
mailing list