[lld] r265792 - Produce STV_DEFAULT for symbols in shared libraries.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 8 08:43:43 PDT 2016


Author: rafael
Date: Fri Apr  8 10:43:43 2016
New Revision: 265792

URL: http://llvm.org/viewvc/llvm-project?rev=265792&view=rev
Log:
Produce STV_DEFAULT for symbols in shared libraries.

The spec says:
If a symbol definition with STV_PROTECTED visibility from a shared
object is taken as resolving a reference from an executable or another
shared object, the SHN_UNDEF symbol table entry created has STV_DEFAULT
visibility.

Added:
    lld/trunk/test/ELF/Inputs/protected-shared.s
    lld/trunk/test/ELF/protected-shared.s
Modified:
    lld/trunk/ELF/OutputSections.cpp

Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=265792&r1=265791&r2=265792&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Fri Apr  8 10:43:43 2016
@@ -1458,6 +1458,12 @@ void SymbolTableSection<ELFT>::writeLoca
   }
 }
 
+static uint8_t getSymbolVisibility(SymbolBody *Body) {
+  if (Body->isShared())
+    return STV_DEFAULT;
+  return Body->getVisibility();
+}
+
 template <class ELFT>
 void SymbolTableSection<ELFT>::writeGlobalSymbols(uint8_t *Buf) {
   // Write the internal symbol table contents to the output symbol table
@@ -1473,7 +1479,7 @@ void SymbolTableSection<ELFT>::writeGlob
     ESym->setBindingAndType(getSymbolBinding(Body), Type);
     ESym->st_size = Size;
     ESym->st_name = StrOff;
-    ESym->setVisibility(Body->getVisibility());
+    ESym->setVisibility(getSymbolVisibility(Body));
     ESym->st_value = Body->getVA<ELFT>();
 
     if (const OutputSectionBase<ELFT> *OutSec = getOutputSection(Body))

Added: lld/trunk/test/ELF/Inputs/protected-shared.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/Inputs/protected-shared.s?rev=265792&view=auto
==============================================================================
--- lld/trunk/test/ELF/Inputs/protected-shared.s (added)
+++ lld/trunk/test/ELF/Inputs/protected-shared.s Fri Apr  8 10:43:43 2016
@@ -0,0 +1,3 @@
+        .global foo
+        .protected foo
+foo:

Added: lld/trunk/test/ELF/protected-shared.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/protected-shared.s?rev=265792&view=auto
==============================================================================
--- lld/trunk/test/ELF/protected-shared.s (added)
+++ lld/trunk/test/ELF/protected-shared.s Fri Apr  8 10:43:43 2016
@@ -0,0 +1,18 @@
+// REQUIRES: x86
+// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/protected-shared.s -o %t2.o
+// RUN: ld.lld -shared %t2.o -o %t2.so
+// RUN: ld.lld %t.o %t2.so -o %t
+// RUN: llvm-readobj -t %t | FileCheck %s
+
+        .global  _start
+_start:
+        .quad foo
+
+// CHECK:      Name: foo
+// CHECK-NEXT: Value: 0x0
+// CHECK-NEXT: Size: 0
+// CHECK-NEXT: Binding: Global
+// CHECK-NEXT: Type: None
+// CHECK-NEXT: Other: 0
+// CHECK-NEXT: Section: Undefined




More information about the llvm-commits mailing list