Re-did 60519. It turns out Darwin's handling of hidden visibility symbols are a bit more complicate than I expected. Both declarations and weak definitions still need a stub indirection. However, the stubs are in data section and they contain the addresses of the actual symbols.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60571 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Target/ARM/ARMISelLowering.cpp b/lib/Target/ARM/ARMISelLowering.cpp
index 69452c1..02a0ed6 100644
--- a/lib/Target/ARM/ARMISelLowering.cpp
+++ b/lib/Target/ARM/ARMISelLowering.cpp
@@ -830,9 +830,12 @@
 /// GVIsIndirectSymbol - true if the GV will be accessed via an indirect symbol
 /// even in non-static mode.
 static bool GVIsIndirectSymbol(GlobalValue *GV, Reloc::Model RelocM) {
-  return RelocM != Reloc::Static &&
-    (GV->hasWeakLinkage() || GV->hasLinkOnceLinkage() ||
-     (GV->isDeclaration() && !GV->hasNotBeenReadFromBitcode()));
+  // If symbol visibility is hidden, the extra load is not needed if
+  // the symbol is definitely defined in the current translation unit.
+  bool isDecl = GV->isDeclaration() && !GV->hasNotBeenReadFromBitcode();
+  if (GV->hasHiddenVisibility() && (!isDecl && !GV->hasCommonLinkage()))
+    return false;
+  return RelocM != Reloc::Static && (isDecl || GV->mayBeOverridden());
 }
 
 SDValue ARMTargetLowering::LowerGlobalAddressDarwin(SDValue Op,