[PATCH] D108006: [lld][ELF] Add --no-search-static-libs-for-shlib-undefined flag
Pirama Arumuga Nainar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 12 18:01:57 PDT 2021
pirama created this revision.
pirama added reviewers: peter.smith, MaskRay, srhines.
Herald added subscribers: dang, arichardson, emaste.
pirama requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
This change addresses PR43554.
Android platform builds have two properties:
- Always build executables and libraries with -Wl,--no-undefined
- Several util libraries linked as statically or as a shared object
across executables and libraries.
This flag will make ld.lld not open static libraries to provide
undefined symbols from a shared library. In Android, those symbols are
guaranteed to be available at runtime (because of -Wl,--no-undefined).
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D108006
Files:
lld/ELF/Config.h
lld/ELF/Driver.cpp
lld/ELF/Options.td
lld/ELF/Symbols.cpp
Index: lld/ELF/Symbols.cpp
===================================================================
--- lld/ELF/Symbols.cpp
+++ lld/ELF/Symbols.cpp
@@ -479,6 +479,10 @@
return;
}
+ if (other.file && dyn_cast<SharedFile>(other.file) &&
+ !config->searchStaticLibForShlibUndefined)
+ return;
+
// Do extra check for --warn-backrefs.
//
// --warn-backrefs is an option to prevent an undefined reference from
Index: lld/ELF/Options.td
===================================================================
--- lld/ELF/Options.td
+++ lld/ELF/Options.td
@@ -298,6 +298,9 @@
def no_omagic: F<"no-omagic">, MetaVarName<"<magic>">,
HelpText<"Do not set the text data sections to be writable, page align sections (default)">;
+def no_search_static_libs_for_shlib_undefined: F<"no-search-static-libs-for-shlib-undefined">,
+ HelpText<"Do not search static libraries for undefined symbols in shared libraries">;
+
def no_undefined: F<"no-undefined">,
HelpText<"Report unresolved symbols even if the linker is creating a shared library">;
Index: lld/ELF/Driver.cpp
===================================================================
--- lld/ELF/Driver.cpp
+++ lld/ELF/Driver.cpp
@@ -1099,6 +1099,8 @@
args.hasFlag(OPT_mmap_output_file, OPT_no_mmap_output_file, true);
config->nmagic = args.hasFlag(OPT_nmagic, OPT_no_nmagic, false);
config->noinhibitExec = args.hasArg(OPT_noinhibit_exec);
+ config->searchStaticLibForShlibUndefined =
+ !args.hasArg(OPT_no_search_static_libs_for_shlib_undefined, false);
config->nostdlib = args.hasArg(OPT_nostdlib);
config->oFormatBinary = isOutputFormatBinary(args);
config->omagic = args.hasFlag(OPT_omagic, OPT_no_omagic, false);
Index: lld/ELF/Config.h
===================================================================
--- lld/ELF/Config.h
+++ lld/ELF/Config.h
@@ -211,6 +211,7 @@
bool symbolic;
bool isStatic = false;
bool sysvHash = false;
+ bool searchStaticLibForShlibUndefined = true;
bool target1Rel;
bool trace;
bool thinLTOEmitImportsFiles;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108006.366160.patch
Type: text/x-patch
Size: 2073 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210813/ea3879d6/attachment.bin>
More information about the llvm-commits
mailing list