On Fri, 2 May 2025 at 02:30, Bruno Haible <br...@clisp.org> wrote:

>
> Indeed, dladdr sounds like it might well work. It's even in POSIX:2024 [1].
>
> According to gnulib's symbol database, dladdr is
>   - in libc on musl, macOS, FreeBSD, NetBSD, OpenBSD, Solaris, Cygwin,
> Minix,
>   - in libdl on Linux/glibc, Hurd, Android, Haiku,
>   - in libdld on HP-UX.
>
> I don't think requiring -ldl is a "small" price to pay. It increases the
> startup times of the programs linked to that library. Therefore how about
> using dladdr only on those platforms where it is in libc? This would cover
> all the platform that you mentioned, and on Cygwin it would be a speedup
> (likely no system calls instead of reading from the /proc file system).
>

According to the code, the current implementation of
find_shared_library_fullname costs "ca. 0.3ms on Linux, 3 ms on Cygwin 1.5,
and 5 ms on Cygwin 1.7". This code is only enabled when
ENABLE_COSTLY_RELOCATABLE is defined, so perhaps it's not too bad to always
use dladdr in this case on other OSes? (I am assuming that the current
Linux method is cheaper than dladdr; if not, every OS that supports it
should use dladdr, I suppose.)

-- 
https://rrt.sc3d.org

Reply via email to