From 1cac0481166dd383a5d685fd53154661fbac5896 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Tue, 21 May 2013 00:06:11 +0000 Subject: Merging r182266: ------------------------------------------------------------------------ r182266 | rnk | 2013-05-20 07:02:37 -0700 (Mon, 20 May 2013) | 13 lines Implement __declspec(selectany) under -fms-extensions selectany only applies to externally visible global variables. It has the effect of making the data weak_odr. The MSDN docs suggest that unused definitions can only be dropped at linktime, so Clang uses weak instead of linkonce. MSVC optimizes away references to constant selectany data, so it must assume that there is only one definition, hence weak_odr. Reviewers: espindola Differential Revision: http://llvm-reviews.chandlerc.com/D814 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/cfe/branches/release_33@182337 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenModule.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'lib/CodeGen/CodeGenModule.cpp') diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 0b03a3c4b6..b3b05199a5 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -1900,7 +1900,13 @@ CodeGenModule::GetLLVMLinkageVarDefinition(const VarDecl *D, return llvm::Function::DLLImportLinkage; else if (D->hasAttr()) return llvm::Function::DLLExportLinkage; - else if (D->hasAttr()) { + else if (D->hasAttr()) { + // selectany symbols are externally visible, so use weak instead of + // linkonce. MSVC optimizes away references to const selectany globals, so + // all definitions should be the same and ODR linkage should be used. + // http://msdn.microsoft.com/en-us/library/5tkz6s71.aspx + return llvm::GlobalVariable::WeakODRLinkage; + } else if (D->hasAttr()) { if (GV->isConstant()) return llvm::GlobalVariable::WeakODRLinkage; else -- cgit v1.2.3-18-g5258