According to the dlopen(3) man page:
If the same library is loaded again with dlopen(), the same file handle is returned.
What does "same library" mean? Same filename? Same path? Same inode? Same SONAME? Something else? How does this behavior interact with soft links?
Assume I am interested in ELF so's and mainstream Linux distros (Debian / Arch / RHEL families).
Example consequences:
I decided to dig into the musl source for, well, a possible interpretation of the words. The function in question is load_library()
, at https://github.com/ifduyue/musl/blob/3ab2a4e02682df1382955071919d8aa3c3ec40d4/ldso/dynlink.c#L990.
The "already loaded" search for (p=head->next; p; p=p->next) if (...) return p;
occurs in two places:
libfoo.so
)In addition, the shortname is only saved in a nom-path case.
The #2 case seems to explicitly merge hard links. The use of fopen also implicitly merges symlinks.
At no point was the ELF file itself ever consulted for sameness. So it's not a horrible mess, but not super smart either.
I am way too tired to read glibc right now, but I can't imagine anything unusual there. Node.js's AIX polyfill uses inode too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With