ELF: Forbid undefined symbols with non-default visibility in DSOs.
authorPeter Collingbourne <peter@pcc.me.uk>
Sun, 24 Apr 2016 02:31:04 +0000 (02:31 +0000)
committerPeter Collingbourne <peter@pcc.me.uk>
Sun, 24 Apr 2016 02:31:04 +0000 (02:31 +0000)
llvm-svn: 267315

lld/ELF/Writer.cpp
lld/test/ELF/undef-shared.s [new file with mode: 0644]

index 6f42386..0f82ef6 100644 (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))
diff --git a/lld/test/ELF/undef-shared.s b/lld/test/ELF/undef-shared.s
new file mode 100644 (file)
index 0000000..ea7f06e
--- /dev/null
@@ -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