From 318ae27d8b03fc02181e102ef660b1ccec79654a Mon Sep 17 00:00:00 2001 From: David Chisnall Date: Fri, 29 Mar 2019 14:42:45 +0000 Subject: [PATCH] Allow attempting to load a module twice. This is necessary because FreeBSD/ARM and possibly other platforms use .init_array and not .ctors, so never call the init functions. As a result, we will need the compiler to move to putting the load function in .init_array and may end up with it being called by both variants. --- loader.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/loader.c b/loader.c index 52dfe17..8c0ed4d 100644 --- a/loader.c +++ b/loader.c @@ -212,6 +212,13 @@ OBJC_PUBLIC void __objc_load(struct objc_init *init) case NewABI: break; } + + // If we've already loaded this module, don't load it again. + if (init->version == ULONG_MAX) + { + return; + } + assert(init->version == 0); assert((((uintptr_t)init->sel_end-(uintptr_t)init->sel_begin) % sizeof(*init->sel_begin)) == 0); assert((((uintptr_t)init->cls_end-(uintptr_t)init->cls_begin) % sizeof(*init->cls_begin)) == 0); @@ -315,7 +322,7 @@ OBJC_PUBLIC void __objc_load(struct objc_init *init) } } #endif - init->version = 0xffffffffffffffffULL; + init->version = ULONG_MAX; } #ifdef OLDABI_COMPAT