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

Florian Weimer fweimer@redhat.com
Fri Nov 13 21:41:33 GMT 2020


* Daniel Villeneuve via Libc-help:

> 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.

The files are stilled mapped while the objects are still loaded, so they
must exist unnamed in the the file system.  Their content is also
accessible via /proc/PID/map_files.  I believe the inode/device pair is
indeed unique under these circumstances.

> 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?

It depends on what the soname of the library is.  If you set it to a
fixed value, the new library may be opened, but not loaded eventually
because the soname is already known to the system.

Thanks,
Florian
-- 
Red Hat GmbH, https://de.redhat.com/ , Registered seat: Grasbrunn,
Commercial register: Amtsgericht Muenchen, HRB 153243,
Managing Directors: Charles Cachera, Brian Klemm, Laurie Krebs, Michael O'Neill



More information about the Libc-help mailing list