From be9022c50229b3491afe550a938384db75fe62b6 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Thu, 6 Aug 2015 20:56:55 +0000 Subject: [PATCH] [ItaniumCXXABI] Don't import RTTI data for classes with key functions MinGW has some pretty strange behvaior around RTTI and dllimport/dllexport: - RTTI data is never imported - RTTI data is only exported if the class has no key function. llvm-svn: 244266 --- clang/lib/CodeGen/ItaniumCXXABI.cpp | 18 ++++++++++++++---- clang/test/CodeGenCXX/dllimport-rtti.cpp | 7 +++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp b/clang/lib/CodeGen/ItaniumCXXABI.cpp index cb506c3..115bf19 100644 --- a/clang/lib/CodeGen/ItaniumCXXABI.cpp +++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp @@ -2450,10 +2450,13 @@ static bool ShouldUseExternalRTTIDescriptor(CodeGenModule &CGM, // FIXME: this may need to be reconsidered if the key function // changes. + // N.B. We must always emit the RTTI data ourselves if there exists a key + // function. + bool IsDLLImport = RD->hasAttr(); if (CGM.getVTables().isVTableExternal(RD)) - return true; + return IsDLLImport ? false : true; - if (RD->hasAttr()) + if (IsDLLImport) return true; } @@ -2683,8 +2686,15 @@ static llvm::GlobalVariable::LinkageTypes getTypeInfoLinkage(CodeGenModule &CGM, const CXXRecordDecl *RD = cast(Record->getDecl()); if (RD->hasAttr()) return llvm::GlobalValue::WeakODRLinkage; - if (RD->isDynamicClass()) - return CGM.getVTableLinkage(RD); + if (RD->isDynamicClass()) { + llvm::GlobalValue::LinkageTypes LT = CGM.getVTableLinkage(RD); + // MinGW won't export the RTTI information when there is a key function. + // Make sure we emit our own copy instead of attempting to dllimport it. + if (RD->hasAttr() && + llvm::GlobalValue::isAvailableExternallyLinkage(LT)) + LT = llvm::GlobalValue::LinkOnceODRLinkage; + return LT; + } } return llvm::GlobalValue::LinkOnceODRLinkage; diff --git a/clang/test/CodeGenCXX/dllimport-rtti.cpp b/clang/test/CodeGenCXX/dllimport-rtti.cpp index 8c0f863..609ad16 100644 --- a/clang/test/CodeGenCXX/dllimport-rtti.cpp +++ b/clang/test/CodeGenCXX/dllimport-rtti.cpp @@ -15,3 +15,10 @@ struct __declspec(dllimport) S { struct U : S { } u; + +struct __declspec(dllimport) V { + virtual void f(); +} v; +// GNU-DAG: @_ZTV1V = available_externally dllimport +// GNU-DAG: @_ZTS1V = linkonce_odr +// GNU-DAG: @_ZTI1V = linkonce_odr -- 2.7.4