Index: ELF/Relocations.cpp =================================================================== --- ELF/Relocations.cpp +++ ELF/Relocations.cpp @@ -557,6 +557,7 @@ const RelTy &RI = *I; SymbolBody &Body = File.getRelocTargetSym(RI); uint32_t Type = RI.getType(Config->Mips64EL); + Body.IsRelocTarget = true; RelExpr Expr = Target->getRelExpr(Type, Body); bool Preemptible = isPreemptible(Body, Type); Index: ELF/Symbols.h =================================================================== --- ELF/Symbols.h +++ ELF/Symbols.h @@ -52,7 +52,7 @@ LazyObjectKind, }; - SymbolBody(Kind K) : SymbolKind(K) {} + SymbolBody(Kind K) : SymbolKind(K), IsRelocTarget(false) {} Symbol *symbol(); const Symbol *symbol() const { @@ -121,6 +121,9 @@ // True if this symbol has an entry in the global part of MIPS GOT. unsigned IsInGlobalMipsGot : 1; + // True if the symbol is relocation target. + unsigned IsRelocTarget : 1; + // The following fields have the same meaning as the ELF symbol attributes. uint8_t Type; // symbol type uint8_t StOther; // st_other field value Index: ELF/Writer.cpp =================================================================== --- ELF/Writer.cpp +++ ELF/Writer.cpp @@ -317,9 +317,10 @@ std::string Msg = "undefined symbol: "; Msg += Config->Demangle ? demangle(Sym->getName()) : Sym->getName().str(); + bool Unused = !Sym->IsRelocTarget && !Sym->symbol()->includeInDynsym(); if (Sym->File) Msg += " in " + getFilename(Sym->File); - if (Config->UnresolvedSymbols == UnresolvedPolicy::Warn) + if (Config->UnresolvedSymbols == UnresolvedPolicy::Warn || Unused) warn(Msg); else error(Msg); Index: test/ELF/libsearch.s =================================================================== --- test/ELF/libsearch.s +++ test/ELF/libsearch.s @@ -16,7 +16,7 @@ // NOLIBRARY: missing arg value for "-l", expected 1 argument. // Should not link because of undefined symbol _bar -// RUN: not ld.lld -o %t3 %t.o 2>&1 \ +// RUN: ld.lld -o %t3 %t.o 2>&1 \ // RUN: | FileCheck --check-prefix=UNDEFINED %s // UNDEFINED: undefined symbol: _bar Index: test/ELF/sysroot.s =================================================================== --- test/ELF/sysroot.s +++ test/ELF/sysroot.s @@ -7,7 +7,7 @@ // REQUIRES: x86 // Should not link because of undefined symbol _bar -// RUN: not ld.lld -o %t/r %t/m.o 2>&1 \ +// RUN: ld.lld -o %t/r %t/m.o 2>&1 \ // RUN: | FileCheck --check-prefix=UNDEFINED %s // UNDEFINED: undefined symbol: _bar