]> granicus.if.org Git - clang/commit
[Itanium] Emit type info names with external linkage.
authorEric Fiselier <eric@efcs.ca>
Thu, 10 May 2018 05:25:15 +0000 (05:25 +0000)
committerEric Fiselier <eric@efcs.ca>
Thu, 10 May 2018 05:25:15 +0000 (05:25 +0000)
commitd90f87dd04be931a4ffecf3349541e2e125ca810
tree06ec111db1f55ecf0a77be654215c016526b0eda
parent1d6049b739c78b327ed25599c19ed7764cb21947
[Itanium] Emit type info names with external linkage.

Summary:
The Itanium ABI requires that the type info for pointer-to-incomplete types to have internal linkage, so that it doesn't interfere with the type info once completed.  Currently it also marks the type info name as internal as well. However, this causes a bug with the STL implementations, which use the type info name pointer to perform ordering and hashing of type infos.
For example:

```
// header.h
struct T;
extern std::type_info const& Info;

// tu_one.cpp
#include "header.h"
std::type_info const& Info = typeid(T*);

// tu_two.cpp
#include "header.h"
struct T {};
int main() {
  auto &TI1 = Info;
  auto &TI2 = typeid(T*);
  assert(TI1 == TI2); // Fails
  assert(TI1.hash_code() == TI2.hash_code()); // Fails
}
```

This patch fixes the STL bug by emitting the type info name as linkonce_odr when the type-info is for a pointer-to-incomplete type.

Note that libc++ could fix this without a compiler change, but the quality of fix would be poor. The library would either have to:

(A) Always perform strcmp/string hashes.
(B) Determine if we have a pointer-to-incomplete type, and only do strcmp then. This would require an ABI break for libc++.

Reviewers: rsmith, rjmccall, majnemer, vsapsai

Reviewed By: rjmccall

Subscribers: smeenai, cfe-commits

Differential Revision: https://reviews.llvm.org/D46665

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@331957 91177308-0d34-0410-b5e6-96231b3b80d8
lib/CodeGen/ItaniumCXXABI.cpp
test/CodeGenCXX/rtti-linkage.cpp