dynstage: desperate safeguard for race against the linker

Even with LIBRARY_BUMP_DELAY, on some systems we'll try to reload the
shared library too early. If dlopen fails, try to repeat it a few times
with short but increasing delays. This should be extremely rare.
This commit is contained in:
Andrei Alexeyev 2022-11-20 05:33:53 +01:00
parent d74f54eb8e
commit 8927edae65
No known key found for this signature in database
GPG key ID: 72D26128040B9690

View file

@ -58,13 +58,26 @@ static struct {
} dynstage;
static stageslib_t dynstage_dlopen(void) {
stageslib_t lib = dlopen(TAISEI_BUILDCONF_DYNSTAGE_LIB, RTLD_NOW | RTLD_LOCAL);
int attempts = 7;
int delay = 10;
if(UNLIKELY(!lib)) {
log_fatal("Failed to load stages library: %s", dlerror());
for(;;) {
stageslib_t lib = dlopen(TAISEI_BUILDCONF_DYNSTAGE_LIB, RTLD_NOW | RTLD_LOCAL);
if(LIKELY(lib != NULL)) {
return lib;
}
if(--attempts) {
log_error("Failed to load stages library (%i attempt%s left): %s", attempts, attempts > 1? "s" : "", dlerror());
SDL_Delay(delay);
delay *= 2;
} else {
break;
}
}
return lib;
log_fatal("Failed to load stages library: %s", dlerror());
}
static void dynstage_bump_lib_generation(void) {