summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2016-04-08 15:43:43 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2016-04-08 15:43:43 +0000
commitb729b2131dc8314b64abcef057dc75e0dfac7bab (patch)
tree945a31f49b5206be2e5d4a210c77baa2a87f73d3
parentbadd397aa7c2af53dd302cd7ebd6a96e68f9df1c (diff)
downloadbcm5719-llvm-b729b2131dc8314b64abcef057dc75e0dfac7bab.tar.gz
bcm5719-llvm-b729b2131dc8314b64abcef057dc75e0dfac7bab.zip
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. llvm-svn: 265792
-rw-r--r--lld/ELF/OutputSections.cpp8
-rw-r--r--lld/test/ELF/Inputs/protected-shared.s3
-rw-r--r--lld/test/ELF/protected-shared.s18
3 files changed, 28 insertions, 1 deletions
diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp
index 64949f2e23e..24258fe40cc 100644
--- a/lld/ELF/OutputSections.cpp
+++ b/lld/ELF/OutputSections.cpp
@@ -1458,6 +1458,12 @@ void SymbolTableSection<ELFT>::writeLocalSymbols(uint8_t *&Buf) {
}
}
+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>::writeGlobalSymbols(uint8_t *Buf) {
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))
diff --git a/lld/test/ELF/Inputs/protected-shared.s b/lld/test/ELF/Inputs/protected-shared.s
new file mode 100644
index 00000000000..a4c16df7ab4
--- /dev/null
+++ b/lld/test/ELF/Inputs/protected-shared.s
@@ -0,0 +1,3 @@
+ .global foo
+ .protected foo
+foo:
diff --git a/lld/test/ELF/protected-shared.s b/lld/test/ELF/protected-shared.s
new file mode 100644
index 00000000000..64c187edae3
--- /dev/null
+++ b/lld/test/ELF/protected-shared.s
@@ -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
OpenPOWER on IntegriCloud