diff options
author | Reid Kleckner <reid@kleckner.net> | 2013-05-20 14:02:37 +0000 |
---|---|---|
committer | Reid Kleckner <reid@kleckner.net> | 2013-05-20 14:02:37 +0000 |
commit | b144d366934f3160ff4b1341db47dd15cd2a8c18 (patch) | |
tree | ec4ef604035da6ce9174caa61e33a732c8a23d7e /clang/lib/CodeGen/CodeGenModule.cpp | |
parent | 95935c5de142edf90273dc76ebafb7d09561821e (diff) | |
download | bcm5719-llvm-b144d366934f3160ff4b1341db47dd15cd2a8c18.tar.gz bcm5719-llvm-b144d366934f3160ff4b1341db47dd15cd2a8c18.zip |
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
llvm-svn: 182266
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 07368790372..3a967c6fdc3 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -1937,7 +1937,13 @@ CodeGenModule::GetLLVMLinkageVarDefinition(const VarDecl *D, return llvm::Function::DLLImportLinkage; else if (D->hasAttr<DLLExportAttr>()) return llvm::Function::DLLExportLinkage; - else if (D->hasAttr<WeakAttr>()) { + else if (D->hasAttr<SelectAnyAttr>()) { + // 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<WeakAttr>()) { if (GV->isConstant()) return llvm::GlobalVariable::WeakODRLinkage; else |