what is the dlopen criterion used to decide if library needs to be loaded?

Daniel Villeneuve dvilleneuve.4142@gmail.com
Fri Nov 13 21:24:13 GMT 2020


Hi,

I am compiling/linking/loading libraries from a long-running program.
I tend to reuse the same build directory and names.

But it seems that dlopen skips loading a new library if I reuse the same name as a previously (still loaded) library.
I could check that with the RTLD_NOLOAD option.
This happens even if the library itself has changed.

By looking at the code in glibc, there seems to be a test using inode/xdev, which does not rely on the name.
However, inodes can be reused immediately after unlink, so it seems fragile to infer equality of contents just comparing inodes.

In the end, I've rebuilt the library using the same name (not being sure whether the inode would be the same or not), and before dlopen, I create a hard link with a new unique name on the library and use that as arg to dlopen (and then delete the hard link).

Is this a safe way to ensure a newly built library is really loaded?
Would a symlink work? It seems that in /proc/$pid/maps, symlinks are resolved to canonical file names, so a new symlink name might not be sufficient...

Regards,
--
Daniel Villeneuve




More information about the Libc-help mailing list