[PATCH] D46665: [Itanium] Emit type info names with external linkage.

Eric Fiselier via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 9 16:32:11 PDT 2018


EricWF created this revision.
EricWF added reviewers: rsmith, rjmccall, majnemer, vsapsai.

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++.


https://reviews.llvm.org/D46665

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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46665.146029.patch
Type: text/x-patch
Size: 7321 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180509/bb3df488/attachment-0001.bin>


More information about the cfe-commits mailing list