void parlib_dtors()
{
typedef void (*dtor)(void);
- extern dtor __DTOR_LIST__[], __DTOR_END__[];
+ extern char __DTOR_LIST__[],__DTOR_END__[];
+ int ndtor = ((unsigned int)(__DTOR_END__ - __DTOR_LIST__))/sizeof(void*);
// make sure only one thread actually runs the dtors
static size_t already_done = 0;
if(hart_swap(&already_done,1) == 1)
return;
- for(int i = 0; i < __DTOR_END__ - __DTOR_LIST__; i++)
- __DTOR_LIST__[i]();
+ for(int i = 0; i < ndtor; i++)
+ ((dtor*)__DTOR_LIST__)[i]();
}
// call static constructors.
void parlib_ctors()
{
typedef void (*ctor)(void);
- extern ctor __CTOR_LIST__[],__CTOR_END__[];
+ extern char __CTOR_LIST__[],__CTOR_END__[];
+ int nctor = ((unsigned int)(__CTOR_END__ - __CTOR_LIST__))/sizeof(void*);
- for(int i = -1; i >= __CTOR_LIST__-__CTOR_END__; i--)
- __CTOR_END__[i]();
+ for(int i = 0; i < nctor; i++)
+ ((ctor*)__CTOR_LIST__)[nctor-i-1]();
}
void parlibmain()