diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2017-10-27 21:18:48 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2017-10-27 21:18:48 +0000 |
commit | 2393c3b4e12460cd9c430840e21d333ad6294b5a (patch) | |
tree | fc638ebba802bbde25b96b36455c3443693b84d4 /llvm/lib/Target/TargetMachine.cpp | |
parent | 94f5032aedbd49e2f828e2bb31c006332c2bcaa7 (diff) | |
download | bcm5719-llvm-2393c3b4e12460cd9c430840e21d333ad6294b5a.tar.gz bcm5719-llvm-2393c3b4e12460cd9c430840e21d333ad6294b5a.zip |
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
Diffstat (limited to 'llvm/lib/Target/TargetMachine.cpp')
-rw-r--r-- | llvm/lib/Target/TargetMachine.cpp | 14 |
1 files changed, 11 insertions, 3 deletions
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<GlobalVariable>(GV) && - !GV->hasExternalWeakLinkage(); + bool IsAccessViaCopyRelocs = + Options.MCOptions.MCPIECopyRelocations && GV && isa<GlobalVariable>(GV); Triple::ArchType Arch = TT.getArch(); bool IsPPC = Arch == Triple::ppc || Arch == Triple::ppc64 || Arch == Triple::ppc64le; |