Index: src/runtime/amiga-library.m ================================================================== --- src/runtime/amiga-library.m +++ src/runtime/amiga-library.m @@ -329,12 +329,13 @@ return &child->library; } static void * -expunge(struct ObjFWRTBase *base) +expunge(struct ObjFWRTBase *base, struct ExecBase *sysBase) { +#define SysBase sysBase void *segList; if (base->parent != NULL) { base->parent->library.lib_Flags |= LIBF_DELEXP; return 0; @@ -350,23 +351,31 @@ Remove(&base->library.lib_Node); FreeMem((char *)base - base->library.lib_NegSize, base->library.lib_NegSize + base->library.lib_PosSize); return segList; +#undef SysBase } static void *__saveds lib_expunge(void) { OBJC_M68K_ARG(struct ObjFWRTBase *, base, a6) - return expunge(base); + return expunge(base, SysBase); } static void *__saveds lib_close(void) { + /* + * SysBase becomes invalid during this function, so we store it in + * sysBase and add a define to make the inlines use the right one. + */ + struct ExecBase *sysBase = SysBase; +#define SysBase sysBase + OBJC_M68K_ARG(struct ObjFWRTBase *, base, a6) if (base->parent != NULL) { struct ObjFWRTBase *parent; @@ -386,13 +395,14 @@ base = parent; } if (--base->library.lib_OpenCnt == 0 && (base->library.lib_Flags & LIBF_DELEXP)) - return expunge(base); + return expunge(base, sysBase); return NULL; +#undef SysBase } static void * lib_null(void) {