ELF: Forbid undefined symbols with non-default visibility in DSOs.

llvm-svn: 267315
This commit is contained in:
Peter Collingbourne
2016-04-24 02:31:04 +00:00
parent d869a040ee
commit 6d01a35ef6
2 changed files with 21 additions and 2 deletions

View File

@@ -730,8 +730,13 @@ void Writer<ELFT>::scanRelocs(InputSectionBase<ELFT> &S,
template <class ELFT>
static void reportUndefined(SymbolTable<ELFT> &Symtab, SymbolBody *Sym) {
if ((Config->Relocatable || Config->Shared) && !Config->NoUndefined)
return;
if (!Config->NoUndefined) {
if (Config->Relocatable)
return;
if (Config->Shared)
if (Sym->Backref->Visibility == STV_DEFAULT)
return;
}
std::string Msg = "undefined symbol: " + Sym->getName().str();
if (InputFile *File = Symtab.findFile(Sym))

View File

@@ -0,0 +1,14 @@
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
# RUN: not ld.lld %t.o -o %t 2>&1 | FileCheck %s
# CHECK: undefined symbol: hidden in {{.*}}
.global hidden
.hidden hidden
# CHECK: undefined symbol: internal in {{.*}}
.global internal
.internal internal
# CHECK: undefined symbol: protected in {{.*}}
.global protected
.protected protected