Index: ELF/Config.h =================================================================== --- ELF/Config.h +++ ELF/Config.h @@ -30,6 +30,7 @@ bool DiscardNone; bool ExportDynamic; bool NoInhibitExec; + bool NoUndefined; bool Shared; bool Static = false; }; Index: ELF/Driver.cpp =================================================================== --- ELF/Driver.cpp +++ ELF/Driver.cpp @@ -123,6 +123,7 @@ Config->DiscardNone = Args.hasArg(OPT_discard_none); Config->ExportDynamic = Args.hasArg(OPT_export_dynamic); Config->NoInhibitExec = Args.hasArg(OPT_noinhibit_exec); + Config->NoUndefined = Args.hasArg(OPT_no_undefined); Config->Shared = Args.hasArg(OPT_shared); for (auto *Arg : Args) { Index: ELF/Options.td =================================================================== --- ELF/Options.td +++ ELF/Options.td @@ -36,6 +36,11 @@ def noinhibit_exec : Flag<["--"], "noinhibit-exec">, HelpText<"Retain the executable output file whenever it is still usable">; +def no_undefined + : Flag<["--"], "no-undefined">, + HelpText<"Report unresolved symbol references from regular object files " + "even if the linker is creating a non-symbolic shared library.">; + def output : Separate<["-"], "o">, MetaVarName<"">, HelpText<"Path to file to write output">; Index: ELF/Writer.cpp =================================================================== --- ELF/Writer.cpp +++ ELF/Writer.cpp @@ -271,7 +271,7 @@ typedef typename ELFFile::Elf_Sym Elf_Sym; typedef typename ELFFile::Elf_Sym_Range Elf_Sym_Range; - if (Config->Shared) + if (Config->Shared && !Config->NoUndefined) return; const Elf_Sym &SymE = cast>(Sym).Sym; Index: test/elf2/Inputs/no-undefined.s =================================================================== --- test/elf2/Inputs/no-undefined.s +++ test/elf2/Inputs/no-undefined.s @@ -0,0 +1,2 @@ +.globl _start +_start: Index: test/elf2/no-undefined.s =================================================================== --- test/elf2/no-undefined.s +++ test/elf2/no-undefined.s @@ -0,0 +1,16 @@ +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t +# RUN: not lld --no-undefined -shared -flavor gnu2 %t -o %t.so +# RUN: lld -shared -flavor gnu2 %t -o %t1.so + +# Try to make a DSO that links to another DSO with unresolved. +# Specify --no-undefined and that should not fail because this flag +# does not control the behaviour for reporting unresolved references +# found in shared libraries being linked in. +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/no-undefined.s -o %t2 +# RUN: lld -shared --no-undefined -flavor gnu2 %t2 %t1.so -o %t3.so + + + +.globl _shared +_shared: + call _unresolved