From: David Majnemer Date: Thu, 6 Aug 2015 20:56:55 +0000 (+0000) Subject: [ItaniumCXXABI] Don't import RTTI data for classes with key functions X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=aab85400928b3b80bef50d00f6226d90248fb738;p=clang [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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@244266 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/ItaniumCXXABI.cpp b/lib/CodeGen/ItaniumCXXABI.cpp index cb506c32cb..115bf19d97 100644 --- a/lib/CodeGen/ItaniumCXXABI.cpp +++ b/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/test/CodeGenCXX/dllimport-rtti.cpp b/test/CodeGenCXX/dllimport-rtti.cpp index 8c0f86306c..609ad1637c 100644 --- a/test/CodeGenCXX/dllimport-rtti.cpp +++ b/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