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

vcruntime: Fix and enable RTTI #391

Merged
merged 1 commit into from
Aug 12, 2020
Merged

vcruntime: Fix and enable RTTI #391

merged 1 commit into from
Aug 12, 2020

Conversation

thrimbor
Copy link
Member

@thrimbor thrimbor commented Aug 11, 2020

This fixes the lld: error: undefined symbol: const type_info::'vftable' linker error that would usually appear when enabling RTTI and linking a program that instantiates a class containing virtual methods, and enables RTTI. This is enough to give it a quick test:

class A {
  public:
  virtual ~A() {};
};

A a;

This is achieved by the following changes:

  • Build the type_info class with -fno-rtti to prevent it from emitting a recursive reference to its vftable
  • Implement the empty virtual destructor which acts as the key function
  • Add a hidden constructor, because LLVM will optimize away the vftable if the class is not instantiable.

Removing const in __std_type_info_data is not necessary to get this working, but is required for when we eventually implement name demangling, which will require this structure to be modifiable at runtime. Some missing noexcept's were also fixed.

These changes are not enough to actually profit from having RTTI (such as using typeid and dynamic_cast), as these require functional SEH and C++ exception support to implement.

Fixes #237.

@mborgerson mborgerson merged commit 9ac09ee into XboxDev:master Aug 12, 2020
type_info (type_info const &) = delete;
// According to the standard, this constructor should not exist. However,
// not having any constructors causes LLVM to not emit a vftable.
type_info () noexcept;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please create an issue about this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

char const *_UndecoratedName;
char const _DecoratedName[1];
char *_UndecoratedName;
char _DecoratedName[1];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we demangle at runtime, how will we know when to do it?
Wouldn't it have made more sense to keep it const and deal with it when implementing demangling?

Copy link
Member Author

@thrimbor thrimbor Aug 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we demangle at runtime, how will we know when to do it?

MS demangles the name when type_info::name() is called and _UndecoratedName is NULL. It allocates a buffer for the string, demangles, and puts the address of the string in _UndecoratedName.

Wouldn't it have made more sense to keep it const and deal with it when implementing demangling?

I don't think there's a significant benefit in keeping or removing const at this moment - it just bothered me because it was incorrect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

RTTI is unavailable in C++
3 participants