[PATCH] D62429: Fix linkage of _ZTS strings for types involving incomplete classes to match the Itanium ABI rules.

2019-05-27 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

In D62429#1518602 , @EricWF wrote:

> I think this is llvm.org/PR37398
>
> I tried fixing this a while back in r332028 but the fix got reverted for 
> causing llvm.org/PR37545.


Looks like I had a fix for that in https://reviews.llvm.org/D47092 but it seems 
we decided to not go that way because the issue is really an ASan 
instrumentation bug and should be fixed in ASan instead... so I guess this is 
blocked on a fix to ASan :-/


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D62429/new/

https://reviews.llvm.org/D62429



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D62429: Fix linkage of _ZTS strings for types involving incomplete classes to match the Itanium ABI rules.

2019-05-27 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF added a comment.

I think this is llvm.org/PR37398

I tried fixing this a while back in r332028 but the fix got reverted for 
causing llvm.org/PR37545.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D62429/new/

https://reviews.llvm.org/D62429



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D62429: Fix linkage of _ZTS strings for types involving incomplete classes to match the Itanium ABI rules.

2019-05-24 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith created this revision.
rsmith added a reviewer: rjmccall.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Without this patch, type_info objects for pointers to incomplete classes
compare unequal with libc++ when formed in multiple translation units,
because each translation unit has its own copy of the _ZTS symbol, in
violation of the Itanium ABI's uniqueness rule.


Repository:
  rC Clang

https://reviews.llvm.org/D62429

Files:
  lib/CodeGen/ItaniumCXXABI.cpp
  test/CodeGenCXX/rtti-linkage.cpp

Index: test/CodeGenCXX/rtti-linkage.cpp
===
--- test/CodeGenCXX/rtti-linkage.cpp
+++ test/CodeGenCXX/rtti-linkage.cpp
@@ -3,27 +3,36 @@
 
 #include 
 
-// CHECK-BOTH: _ZTSP1C = internal constant
-// CHECK-BOTH: _ZTS1C = internal constant
+// CHECK: _ZTSP1C = linkonce_odr constant
+// CHECK-WITH-HIDDEN: _ZTSP1C = linkonce_odr hidden constant
+// CHECK: _ZTS1C = linkonce_odr constant
+// CHECK-WITH-HIDDEN: _ZTS1C = linkonce_odr hidden constant
 // CHECK-BOTH: _ZTI1C = internal constant
 // CHECK-BOTH: _ZTIP1C = internal constant
-// CHECK-BOTH: _ZTSPP1C = internal constant
+// CHECK: _ZTSPP1C = linkonce_odr constant
+// CHECK-WITH-HIDDEN: _ZTSPP1C = linkonce_odr hidden constant
 // CHECK-BOTH: _ZTIPP1C = internal constant
-// CHECK-BOTH: _ZTSM1Ci = internal constant
+// CHECK: _ZTSM1Ci = linkonce_odr constant
+// CHECK-WITH-HIDDEN: _ZTSM1Ci = linkonce_odr hidden constant
 // CHECK-BOTH: _ZTIM1Ci = internal constant
-// CHECK-BOTH: _ZTSPM1Ci = internal constant
+// CHECK: _ZTSPM1Ci = linkonce_odr constant
+// CHECK-WITH-HIDDEN: _ZTSPM1Ci = linkonce_odr hidden constant
 // CHECK-BOTH: _ZTIPM1Ci = internal constant
-// CHECK-BOTH: _ZTSM1CS_ = internal constant
+// CHECK: _ZTSM1CS_ = linkonce_odr constant
+// CHECK-WITH-HIDDEN: _ZTSM1CS_ = linkonce_odr hidden constant
 // CHECK-BOTH: _ZTIM1CS_ = internal constant
-// CHECK-BOTH: _ZTSM1CPS_ = internal constant
+// CHECK: _ZTSM1CPS_ = linkonce_odr constant
+// CHECK-WITH-HIDDEN: _ZTSM1CPS_ = linkonce_odr hidden constant
 // CHECK-BOTH: _ZTIM1CPS_ = internal constant
-// CHECK-BOTH: _ZTSM1A1C = internal constant
+// CHECK: _ZTSM1A1C = linkonce_odr constant
+// CHECK-WITH-HIDDEN: _ZTSM1A1C = linkonce_odr hidden constant
 // CHECK: _ZTS1A = linkonce_odr constant
 // CHECK-WITH-HIDDEN: _ZTS1A = linkonce_odr hidden constant
 // CHECK: _ZTI1A = linkonce_odr constant
 // CHECK-WITH-HIDDEN: _ZTI1A = linkonce_odr hidden constant
 // CHECK-BOTH: _ZTIM1A1C = internal constant
-// CHECK-BOTH: _ZTSM1AP1C = internal constant
+// CHECK: _ZTSM1AP1C = linkonce_odr constant
+// CHECK-WITH-HIDDEN: _ZTSM1AP1C = linkonce_odr hidden constant
 // CHECK-BOTH: _ZTIM1AP1C = internal constant
 
 // CHECK-WITH-HIDDEN: _ZTSFN12_GLOBAL__N_11DEvE = internal constant
Index: lib/CodeGen/ItaniumCXXABI.cpp
===
--- lib/CodeGen/ItaniumCXXABI.cpp
+++ lib/CodeGen/ItaniumCXXABI.cpp
@@ -3155,18 +3155,6 @@
 /// should have for the given type.
 static llvm::GlobalVariable::LinkageTypes getTypeInfoLinkage(CodeGenModule ,
  QualType Ty) {
-  // Itanium C++ ABI 2.9.5p7:
-  //   In addition, it and all of the intermediate abi::__pointer_type_info
-  //   structs in the chain down to the abi::__class_type_info for the
-  //   incomplete class type must be prevented from resolving to the
-  //   corresponding type_info structs for the complete class type, possibly
-  //   by making them local static objects. Finally, a dummy class RTTI is
-  //   generated for the incomplete type that will not resolve to the final
-  //   complete class RTTI (because the latter need not exist), possibly by
-  //   making it a local static object.
-  if (ContainsIncompleteClassType(Ty))
-return llvm::GlobalValue::InternalLinkage;
-
   switch (Ty->getLinkage()) {
   case NoLinkage:
   case InternalLinkage:
@@ -3184,6 +3172,11 @@
 
 if (const RecordType *Record = dyn_cast(Ty)) {
   const CXXRecordDecl *RD = cast(Record->getDecl());
+  // If the class is incomplete, we're forming the pointee of an incomplete
+  // pointer typeinfo. This linkage will only be used for the type name;
+  // give it linkonce_odr linkage.
+  if (!RD->isCompleteDefinition())
+return llvm::GlobalValue::LinkOnceODRLinkage;
   if (RD->hasAttr())
 return llvm::GlobalValue::WeakODRLinkage;
   if (CGM.getTriple().isWindowsItaniumEnvironment())
@@ -3255,20 +3248,20 @@
 
 llvm::Constant *ItaniumRTTIBuilder::BuildTypeInfo(
   QualType Ty,
-  llvm::GlobalVariable::LinkageTypes Linkage,
-  llvm::GlobalValue::VisibilityTypes Visibility,
+  llvm::GlobalVariable::LinkageTypes TypeNameLinkage,
+  llvm::GlobalValue::VisibilityTypes TypeNameVisibility,
   llvm::GlobalValue::DLLStorageClassTypes DLLStorageClass) {
   // Add the vtable pointer.
   BuildVTablePointer(cast(Ty));
 
   // And the