From 2393c3b4e12460cd9c430840e21d333ad6294b5a Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Fri, 27 Oct 2017 21:18:48 +0000 Subject: Handle undefined weak hidden symbols on all architectures. We were handling the non-hidden case in lib/Target/TargetMachine.cpp, but the hidden case was handled in architecture dependent code and only X86_64 and AArch64 were covered. While it is true that some code sequences in some ABIs might be able to produce the correct value at runtime, that doesn't seem to be the common case. I left the AArch64 code in place since it also forces a got access for non-pic code. It is not clear if that is needed, but it is probably better to change that in another commit. llvm-svn: 316799 --- llvm/lib/Target/TargetMachine.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'llvm/lib/Target/TargetMachine.cpp') diff --git a/llvm/lib/Target/TargetMachine.cpp b/llvm/lib/Target/TargetMachine.cpp index dd6c288607c..1b05e6ce9f4 100644 --- a/llvm/lib/Target/TargetMachine.cpp +++ b/llvm/lib/Target/TargetMachine.cpp @@ -128,6 +128,15 @@ bool TargetMachine::shouldAssumeDSOLocal(const Module &M, if (TT.isOSBinFormatCOFF() || (TT.isOSWindows() && TT.isOSBinFormatMachO())) return true; + // Most PIC code sequences that assume that a symbol is local cannot + // produce a 0 if it turns out the symbol is undefined. While this + // is ABI and relocation depended, it seems worth it to handle it + // here. + // FIXME: this is probably not ELF specific. + if (GV && isPositionIndependent() && TT.isOSBinFormatELF() && + GV->hasExternalWeakLinkage()) + return false; + if (GV && (GV->hasLocalLinkage() || !GV->hasDefaultVisibility() || GV->isDSOLocal())) return true; @@ -149,9 +158,8 @@ bool TargetMachine::shouldAssumeDSOLocal(const Module &M, return true; bool IsTLS = GV && GV->isThreadLocal(); - bool IsAccessViaCopyRelocs = Options.MCOptions.MCPIECopyRelocations && GV && - isa(GV) && - !GV->hasExternalWeakLinkage(); + bool IsAccessViaCopyRelocs = + Options.MCOptions.MCPIECopyRelocations && GV && isa(GV); Triple::ArchType Arch = TT.getArch(); bool IsPPC = Arch == Triple::ppc || Arch == Triple::ppc64 || Arch == Triple::ppc64le; -- cgit v1.2.3