[Bug 286505] dlopen deadlocks when target library contains IFUNC

From: <bugzilla-noreply_at_freebsd.org>
Date: Thu, 01 May 2025 16:46:11 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=286505

            Bug ID: 286505
           Summary: dlopen deadlocks when target library contains IFUNC
           Product: Base System
           Version: Unspecified
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Only Me
          Priority: ---
         Component: threads
          Assignee: threads@FreeBSD.org
          Reporter: dapeng.gao@cl.cam.ac.uk
                CC: kib@FreeBSD.org

An ifunc resolver enters _rtld_bind, which attempts to acquire _rtld_bind_lock.
But since we are in the middle of dlopen, the lock has been acquired already,
hence deadlocking.

This is similar to bug #286502 but does not involve filter libraries.

Tested on AArch64 but should be reproducible on AMD64. pthread required.

Commands:
cc main.c -lthr -Wl,-rpath=. -o main
cc foo.c -shared -o foo.so
./main

Setup:
$ cat main.c
#include <dlfcn.h>

int main() {
        dlopen("foo.so", RTLD_LAZY);
}

$ cat foo.c
#include <stdio.h>

static void foo_impl() {
}

static void *foo_resolver() {
        puts("foo_resolver()");
        return &foo_impl;
}

void foo() __attribute__((ifunc("foo_resolver")));

void (*foo_ptr)() = &foo;

-- 
You are receiving this mail because:
You are the assignee for the bug.