Index: src/runtime/ObjFW_RT.sfd ================================================================== --- src/runtime/ObjFW_RT.sfd +++ src/runtime/ObjFW_RT.sfd @@ -2,11 +2,11 @@ ==basetype struct Library * ==libname objfw_rt.library ==bias 30 ==public * Functions for the linklib -void objc_set_libc(struct objc_libc *libc)(a0) +void objc_init(struct objc_libc *libc)(a0) * Used by the compiler - these need glue code void glue___objc_exec_class(void *module)(a0) IMP glue_objc_msg_lookup(id obj, SEL sel)(a0,a1) IMP glue_objc_msg_lookup_stret(id obj, SEL sel)(a0,a1) IMP glue_objc_msg_lookup_super(struct objc_super *super, SEL sel)(a0,a1) Index: src/runtime/amiga-library.m ================================================================== --- src/runtime/amiga-library.m +++ src/runtime/amiga-library.m @@ -42,10 +42,11 @@ } struct ObjFWRTBase { struct Library library; BPTR seg_list; + bool initialized; }; struct ExecBase *SysBase; #ifdef OF_MORPHOS const ULONG __abox__ = 1; @@ -52,10 +53,12 @@ #endif struct WBStartup *_WBenchMsg; struct objc_libc *libc; FILE *stdout; FILE *stderr; +extern uintptr_t __CTOR_LIST__[]; +extern uintptr_t __DTOR_LIST__[]; static struct Library * lib_init(struct ExecBase *exec_base OBJC_M68K_REG("a6"), BPTR seg_list OBJC_M68K_REG("a0"), struct ObjFWRTBase *base OBJC_M68K_REG("d0")) @@ -111,10 +114,17 @@ OBJC_M68K_ARG(struct ObjFWRTBase *, base, REG_A6) if (--base->library.lib_OpenCnt == 0 && (base->library.lib_Flags & LIBF_DELEXP)) return expunge(base); + + if (base->initialized) { + for (uintptr_t *iter = &__DTOR_LIST__[1]; *iter != 0; iter++) { + void (*dtor)(void) = (void (*)(void))*iter++; + dtor(); + } + } return 0; } static BPTR @@ -122,16 +132,29 @@ { return 0; } static void -objc_set_libc(struct objc_libc *libc_ OBJC_M68K_REG("a0")) +objc_init(struct ObjFWRTBase *base OBJC_M68K_REG("a6"), + struct objc_libc *libc_ OBJC_M68K_REG("a0")) { + uintptr_t *iter, *iter0; + libc = libc_; stdout = libc->stdout; stderr = libc->stderr; + + iter0 = &__CTOR_LIST__[1]; + for (iter = iter0; *iter != 0; iter++); + + while (iter > iter0) { + void (*ctor)(void) = (void (*)(void))*--iter; + ctor(); + } + + base->initialized = true; } void * malloc(size_t size) {