// libwait.c: constructor başqa thread-i gözləyir, o thread isə dlopen çağırır
#include <dlfcn.h>
#include <pthread.h>
#include <stdio.h>

static void *helper(void *arg) {
    fprintf(stderr, "helper: dlopen çağırıram...\n");
    void *h = dlopen("libm.so.6", RTLD_NOW);      // loader lock lazımdır
    fprintf(stderr, "helper: dlopen qayıtdı (%p)\n", h);
    return NULL;
}

__attribute__((constructor))
static void init(void) {
    pthread_t t;
    pthread_create(&t, NULL, helper, NULL);
    fprintf(stderr, "ctor: helper-i gözləyirəm...\n");
    pthread_join(t, NULL);                         // ❌ loader lock bizdədir
    fprintf(stderr, "ctor: bitdi\n");
}
