summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Target/TargetMachine.cpp
diff options
context:
space:
mode:
authorReid Kleckner <rnk@google.com>2019-05-07 23:06:21 +0000
committerReid Kleckner <rnk@google.com>2019-05-07 23:06:21 +0000
commit6bf108d77a3c15f2bd47a8fa21e8e9357f873a70 (patch)
treec82b45b5c081bbbe0a7620afba033c111c17c165 /llvm/lib/Target/TargetMachine.cpp
parente088d03b9c8b25589bbf35545399ae28a34df182 (diff)
downloadbcm5719-llvm-6bf108d77a3c15f2bd47a8fa21e8e9357f873a70.tar.gz
bcm5719-llvm-6bf108d77a3c15f2bd47a8fa21e8e9357f873a70.zip
[COFF] Use COFF stubs for extern_weak functions
Summary: A COFF stub indirects the reference to a symbol through memory. A .refptr.$sym global variable pointer is created to refer to $sym. Typically mingw uses these for external global variable declarations, but we can use them for weak function declarations as well. Updates the dso_local classification to add a special case for extern_weak symbols on COFF in both clang and LLVM. Fixes PR37598 Reviewers: smeenai, mstorsjo Subscribers: hiraditya, cfe-commits, llvm-commits Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D61615 llvm-svn: 360207
Diffstat (limited to 'llvm/lib/Target/TargetMachine.cpp')
-rw-r--r--llvm/lib/Target/TargetMachine.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/llvm/lib/Target/TargetMachine.cpp b/llvm/lib/Target/TargetMachine.cpp
index 7a1e01bdab6..5b2bdc37af8 100644
--- a/llvm/lib/Target/TargetMachine.cpp
+++ b/llvm/lib/Target/TargetMachine.cpp
@@ -144,6 +144,12 @@ bool TargetMachine::shouldAssumeDSOLocal(const Module &M,
isa<GlobalVariable>(GV))
return false;
+ // On COFF, don't mark 'extern_weak' symbols as DSO local. If these symbols
+ // remain unresolved in the link, they can be resolved to zero, which is
+ // outside the current DSO.
+ if (TT.isOSBinFormatCOFF() && GV && GV->hasExternalWeakLinkage())
+ return false;
+
// Every other GV is local on COFF.
// Make an exception for windows OS in the triple: Some firmware builds use
// *-win32-macho triples. This (accidentally?) produced windows relocations
OpenPOWER on IntegriCloud