Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MS ABI: Implement compatible RTTI #19325

Closed
rnk opened this issue Feb 24, 2014 · 9 comments
Closed

MS ABI: Implement compatible RTTI #19325

rnk opened this issue Feb 24, 2014 · 9 comments
Assignees
Labels
bugzilla Issues migrated from bugzilla clang:codegen

Comments

@rnk
Copy link
Collaborator

rnk commented Feb 24, 2014

Bugzilla Link 18951
Resolution FIXED
Resolved on Sep 07, 2015 01:08
Version unspecified
OS Windows NT
Blocks #12849 #19404
CC @majnemer,@eldiener,@nico,@pcc,@timurrrr

Extended Description

We already have lots of issues about "cannot mangle RTTI descriptors for type 'foo'", but most of them have been resolved with workarounds:
http://llvm.org/bugs/show_bug.cgi?id=18332
http://llvm.org/bugs/show_bug.cgi?id=17403

This issue covers implementing compatible RTTI that works with the implementation the the Microsoft C++ runtime.

This will require changes to LLVM IR. We will need a new linkage type to represent IMAGE_COMDAT_SELECT_LARGEST, and we will need a way to represent a non-zero symbol offset.

MSVC produces vftables where a pointer to RTTI data is at slot -1 in the vftable. They use a scheme that appears to carefully attempt to allow mixing of TUs with and without RTTI, so long as RTTI is never used on classes that are never constructed in a TU with RTTI enabled. Forcing emission of the constructor and therefore vftable will cause emission of RTTI data.

First, the vftable is placed into a COMDAT section with IMAGE_COMDAT_SELECT_LARGEST. The idea is that the vftable with RTTI enabled will be larger and therefore win.

However, once you deduplicate an RTTI vftable with a no-RTTI vftable, all offsets from the vftable symbol in no-RTTI TUs will be off by one slot. To solve this problem, the vftable symbol actually points to the first vftable slot that contains a pointer to a virtual method. We can't represent this in LLVM IR today. Implementing this will require something like symbol_offset proposed here:
http://lists.cs.uiuc.edu/pipermail/llvmdev/2013-April/061511.html

There are a couple of alternatives, like "place_before", but we don't have COMDAT groups in LLVM IR, which makes this awkward.

For symbol_offset, the preferred design so far is one where the offset is handled by the MC layer, and is ignored by GVN and GlobalOpt. In other words, GEPing to the 0th field of a vftable would give you the RTTI data. When we LTO a binary with mixed RTTI TUs, the linker would be required to look at the symbol offset and fix up the GEPs.

@rnk
Copy link
Collaborator Author

rnk commented Feb 24, 2014

assigned to @majnemer

@llvmbot
Copy link
Collaborator

llvmbot commented Feb 25, 2014

For the non-zero offset, it would be really nice if we could reuse COMDATs and alias support in the IR. The idea is to represent it with:

  • a private symbol in a comdat
  • a visible alias that is an offset of that symbol.

@rnk
Copy link
Collaborator Author

rnk commented Feb 26, 2014

Are comdats worth the complexity? What's the best idea we have for representing them in LLVM IR? I asked this on IRC, and people generally wanted to be able to represent them, but nobody knew what it would look like.

My strawman would look like COFF's IMAGE_COMDAT_SELECT_ASSOCIATIVE, where everyone in the comdat group points to one 'key' symbol. Any key would not be allowed to be associative, which would avoid multi-level structures and cycles.

We could also use comdat groups in LLVM IR to fix #17333 , which is one-time dynamic initialization of linkonce data. However, it wouldn't use the llvm.global_ctors array. It would have to use a special section instead.

@pcc
Copy link
Contributor

pcc commented Feb 26, 2014

Beginnings of a symbol_offset diff
I started hacking on symbol_offset a few months ago. I've attached a diff (which may need to be refreshed), but it isn't complete because, as I recall, some object formats needed to be fixed to handle offseted aliases. I managed to fix ELF but I don't remember what the status of COFF was.

@llvmbot
Copy link
Collaborator

llvmbot commented Feb 26, 2014

Are comdats worth the complexity?

We want them so we can implement constructors and destructors in the same way as gcc, so that is way it would be nice to use it for this too.

They are also needed for some corner cases of the ABI that we currently get wrong. See the thread at http://lists.cs.uiuc.edu/pipermail/llvmdev/2011-November/044927.html for the details.

What's the best idea we have for
representing them in LLVM IR? I asked this on IRC, and people generally
wanted to be able to represent them, but nobody knew what it would look like.

The only "design" I ever did on it is on http://lists.cs.uiuc.edu/pipermail/llvmdev/2011-November/045524.html. So something like

@​_ZN1UI1SE1kE = weak_odr constant i32 42, align 4, comdat _ZN1UI1SE1kE
@​_ZGVN1UI1SE1kE = weak_odr global i64 1, comdat _ZN1UI1SE1kE

My strawman would look like COFF's IMAGE_COMDAT_SELECT_ASSOCIATIVE, where
everyone in the comdat group points to one 'key' symbol.

Looks about the same to ELF.

Any key would not
be allowed to be associative, which would avoid multi-level structures and
cycles.

We could also use comdat groups in LLVM IR to fix #17333 ,
which is one-time dynamic initialization of linkonce data. However, it
wouldn't use the llvm.global_ctors array. It would have to use a special
section instead.

@nico
Copy link
Contributor

nico commented May 23, 2014

@majnemer
Copy link
Mannequin

majnemer mannequin commented Jul 2, 2014

COMDATs landed in r211920.
Referencing the RTTI data in the VFTable landed in r212125.
The semantic impact of /GR- landed in r212138.

@rnk
Copy link
Collaborator Author

rnk commented Nov 26, 2021

mentioned in issue #19404

@rnk
Copy link
Collaborator Author

rnk commented Nov 26, 2021

mentioned in issue llvm/llvm-bugzilla-archive#20106

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 9, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla clang:codegen
Projects
None yet
Development

No branches or pull requests

4 participants