Index: ELF/Config.h =================================================================== --- ELF/Config.h +++ ELF/Config.h @@ -89,6 +89,7 @@ bool VersionScript = false; bool WarnCommon; bool ZCombreloc; + bool ZDefs; bool ZExecStack; bool ZNodelete; bool ZNow; Index: ELF/Driver.cpp =================================================================== --- ELF/Driver.cpp +++ ELF/Driver.cpp @@ -353,6 +353,7 @@ error("number of threads must be > 0"); Config->ZCombreloc = !hasZOption(Args, "nocombreloc"); + Config->ZDefs = hasZOption(Args, "defs"); Config->ZExecStack = hasZOption(Args, "execstack"); Config->ZNodelete = hasZOption(Args, "nodelete"); Config->ZNow = hasZOption(Args, "now"); Index: ELF/Writer.cpp =================================================================== --- ELF/Writer.cpp +++ ELF/Writer.cpp @@ -793,7 +793,7 @@ if (!Config->NoUndefined) { if (Config->Relocatable) return; - if (Config->Shared) + if (Config->Shared && !Config->ZDefs) if (Sym->symbol()->Visibility == STV_DEFAULT) return; } Index: test/ELF/zdefs.s =================================================================== --- test/ELF/zdefs.s +++ test/ELF/zdefs.s @@ -0,0 +1,7 @@ +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o +# RUN: ld.lld -shared %t.o -o %t1.so + +# RUN: not ld.lld -z defs -shared %t.o -o %t1.so 2>&1 | FileCheck -check-prefix=ERR %s +# ERR: undefined symbol: foo + +callq foo@PLT