mirror of
https://github.com/libretro/RetroArch
synced 2025-03-31 19:21:06 +00:00
[WiiU] Toolchain: Fix C++ constructor/destructor handling
The old setup relied on there being at least one constructor *or* the value of *__CTOR_LIST__ being NULL. Neither of these are guaranteed; and having no C++ constructors actually resulted in a random value being read (which passed the NULL check!). This new setup uses the __CTOR_END__ symbol; which is a pointer to just after the end of the list. When there are no constructors, it has the same value as __CTOR_LIST__; so the while loop is never entered. This fix also allows us to re-enable destructors; in case they're ever needed.
This commit is contained in:
parent
f48460b114
commit
26a006cfac
@ -523,22 +523,26 @@ void __eabi()
|
||||
__attribute__((weak))
|
||||
void __init(void)
|
||||
{
|
||||
extern void(*__CTOR_LIST__[])(void);
|
||||
void(**ctor)(void) = __CTOR_LIST__;
|
||||
extern void (**const __CTOR_LIST__)(void);
|
||||
extern void (**const __CTOR_END__)(void);
|
||||
|
||||
while (*ctor)
|
||||
void (**ctor)(void) = __CTOR_LIST__;
|
||||
while (ctor < __CTOR_END__) {
|
||||
(*ctor++)();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
__attribute__((weak))
|
||||
void __fini(void)
|
||||
{
|
||||
extern void(*__DTOR_LIST__[])(void);
|
||||
void(**ctor)(void) = __DTOR_LIST__;
|
||||
extern void (**const __DTOR_LIST__)(void);
|
||||
extern void (**const __DTOR_END__)(void);
|
||||
|
||||
while (*ctor)
|
||||
(*ctor++)();
|
||||
void (**dtor)(void) = __DTOR_LIST__;
|
||||
while (dtor < __DTOR_END__) {
|
||||
(*dtor++)();
|
||||
}
|
||||
}
|
||||
|
||||
/* libiosuhax related */
|
||||
@ -633,7 +637,7 @@ int __entry_menu(int argc, char **argv)
|
||||
int ret = main(argc, argv);
|
||||
|
||||
fsdev_exit();
|
||||
// __fini();
|
||||
__fini();
|
||||
memoryRelease();
|
||||
return ret;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user