diff --git a/lld/ELF/Config.h b/lld/ELF/Config.h --- a/lld/ELF/Config.h +++ b/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; diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp --- a/lld/ELF/Driver.cpp +++ b/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); diff --git a/lld/ELF/Options.td b/lld/ELF/Options.td --- a/lld/ELF/Options.td +++ b/lld/ELF/Options.td @@ -298,6 +298,9 @@ def no_omagic: F<"no-omagic">, MetaVarName<"">, 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">; diff --git a/lld/ELF/Symbols.cpp b/lld/ELF/Symbols.cpp --- a/lld/ELF/Symbols.cpp +++ b/lld/ELF/Symbols.cpp @@ -479,6 +479,10 @@ return; } + if (other.file && dyn_cast(other.file) && + !config->searchStaticLibForShlibUndefined) + return; + // Do extra check for --warn-backrefs. // // --warn-backrefs is an option to prevent an undefined reference from