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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ NXDK_CFLAGS = -target i386-pc-win32 -march=pentium3 \
-Wno-ignored-attributes -DNXDK -D__STDC__=1
NXDK_ASFLAGS = -target i386-pc-win32 -march=pentium3 \
-nostdlib -I$(NXDK_DIR)/lib -I$(NXDK_DIR)/lib/xboxrt
NXDK_CXXFLAGS = -I$(NXDK_DIR)/lib/libcxx/include $(NXDK_CFLAGS) -fno-rtti
NXDK_CXXFLAGS = -I$(NXDK_DIR)/lib/libcxx/include $(NXDK_CFLAGS)
NXDK_LDFLAGS = -subsystem:windows -fixed:no -entry:XboxCRTEntry \
-stack:$(NXDK_STACKSIZE) -safeseh:no -include:__fltused -include:__xlibc_check_stack

Expand Down
5 changes: 5 additions & 0 deletions lib/xboxrt/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ XBOXRT_SRCS := \

XBOXRT_OBJS = $(addsuffix .obj, $(basename $(XBOXRT_SRCS)))

# This file needs to be always built with -fno-rtti because it contains the
# type_info class. If the parameter is missing, clang will generate an invalid
# reference from type_info to its own vftable.
$(NXDK_DIR)/lib/xboxrt/vcruntime/vcruntime_typeinfo.obj: NXDK_CXXFLAGS += -fno-rtti

$(NXDK_DIR)/lib/libxboxrt.lib: $(XBOXRT_OBJS)

main.exe: $(NXDK_DIR)/lib/libxboxrt.lib
Expand Down
8 changes: 8 additions & 0 deletions lib/xboxrt/vcruntime/vcruntime_typeinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,11 @@ extern "C"
return hash;
}
}

type_info::~type_info() noexcept
{
}

type_info::type_info () noexcept
{
}
12 changes: 8 additions & 4 deletions lib/xboxrt/vcruntime/vcruntime_typeinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

struct __std_type_info_data
{
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.

};

extern "C"
Expand All @@ -25,7 +25,7 @@ extern "C"
class type_info
{
public:
virtual ~type_info ();
virtual ~type_info () noexcept;

const char *name () const noexcept
{
Expand Down Expand Up @@ -60,7 +60,11 @@ class type_info
}

private:
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.


type_info (type_info const &) noexcept = delete;
type_info &operator= (type_info const &) = delete;

mutable __std_type_info_data _Data;
Expand Down