Index: ELF/OutputSections.cpp
===================================================================
--- ELF/OutputSections.cpp
+++ ELF/OutputSections.cpp
@@ -1317,8 +1317,9 @@
 static uint8_t getSymbolBinding(SymbolBody *Body) {
   Symbol *S = Body->symbol();
   uint8_t Visibility = S->Visibility;
-  if (Visibility != STV_DEFAULT && Visibility != STV_PROTECTED)
-    return STB_LOCAL;
+  if (!Config->Relocatable)
+    if (Visibility != STV_DEFAULT && Visibility != STV_PROTECTED)
+      return STB_LOCAL;
   if (Config->NoGnuUnique && S->Binding == STB_GNU_UNIQUE)
     return STB_GLOBAL;
   return S->Binding;
Index: test/ELF/relocatable-visibility.s
===================================================================
--- test/ELF/relocatable-visibility.s
+++ test/ELF/relocatable-visibility.s
@@ -0,0 +1,19 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+# RUN: ld.lld -r %t.o -o %t1
+# RUN: llvm-readobj -t %t1 | FileCheck --check-prefix=RELOCATABLE %s
+
+# RELOCATABLE:      Name: foo
+# RELOCATABLE-NEXT: Value: 0x0
+# RELOCATABLE-NEXT: Size: 0
+# RELOCATABLE-NEXT: Binding: Global
+# RELOCATABLE-NEXT: Type: None
+# RELOCATABLE-NEXT: Other [
+# RELOCATABLE-NEXT:   STV_HIDDEN
+# RELOCATABLE-NEXT: ]
+# RELOCATABLE-NEXT: Section: Undefined
+
+.global _start
+_start:
+ callq foo
+ .hidden foo