About dlclose in rtl

xuelin.tian at qkmtech.com xuelin.tian at qkmtech.com
Thu Jun 8 10:29:23 UTC 2017


Yeah, I just checked the Linux man page to notice that there is a flag RTLD_NODELETE
I just took a look at a book called "The Linux Programming Interface"
https://books.google.com.hk/books?id=2SAQAQAAQBAJ&pg=PA861&lpg=PA861&dq=susv3+RTLD_NODELETE&source=bl&ots=qQy3e8EDzr&sig=eINfLM3BX8bD2FrS9BHXn7wNhDQ&hl=zh-CN&sa=X&ved=0ahUKEwjW1-PJhK7UAhUBwJQKHeX2C7MQ6AEIIDAA#v=onepage&q=susv3%20RTLD_NODELETE&f=false 
And this may be copied from Linux man page.




Best wishes,
xuelin.tian at qkmtech.com
 
From: Chris Johns
Date: 2017-06-07 07:55
To: xuelin.tian at qkmtech.com
CC: users at rtems.org
Subject: Re: About dlclose in rtl
On 06/06/2017 19:11, xuelin.tian at qkmtech.com wrote:
> I check this flag becomes available in SUSv3 standard after glibc2.2. 
 
Do you have a link to the standard you found so I could have a look?
 
I found the The Open Group Base Specifications Issue 7, IEEE Std 1003.1™-2008,
2016 Edition and there is no mention of this option:
 
http://pubs.opengroup.org/onlinepubs/9699919799/functions/dlopen.html
 
This Linux man page:
 
https://linux.die.net/man/3/dlopen
 
states the flags RTLD_NODELETE, RTLD_NOLOAD and RTLD_DEEPBIND are not in
POSIX.1-2001. A recent debian install says the same thing.
 
> My concern is whether dlclose can reset (or delete) the static variables defined
> in loaded xxx.rap. Or we need to delete static variables manually?
 
Anything declared in the loaded module is removed from the address space with
dlclose and the memory is returned to the heap.
 
The underlying detail used to implement dynamic loading on RTEMS is different to
Unix and I am not sure what the exact semantics required are and if it is
possible to match them on RTEMS.
 
I cannot determine the intent for these glibc additions. For example the dlopen
Linux man page's doco for RTLD_NODELETE provides a rather specific piece of
detail related to static variables and I am left wondering why are static
variables the only type of data effected and why not functions or anything else
in the module? FreeBSD's man page avoids such specifics. I am then left
wondering what the difference between calling dlopen and never calling dlclose
on the module is verses calling dlopen with RTLD_NODELETE and calling dlclose on
the module? Are symbols removed from the symbol table or is there more happening
here? Is it just a way to simplify user management of dynamically loaded
modules? I do not know.
 
In RTEMS calling dlopen, dlclose and then dlopen is not the same as Unix. My
understanding for Unix is the shared library is loaded to the same address each
time and this means RTLD_NODELETE and the man page comment "the library's static
variables are not reinitialized if the library is reloaded with dlopen() at a
later time" is achievable. On RTEMS the load address is related to the state of
the C heap (if using the standard RTL allocator) when dlopen is called so the
load address can change. I suppose implementing RTLD_NODELETE would mean the
module is only unloaded if the reference count is 0 and RTLD_NODELETE is not
set. The RTLD_NOLOAD flag is interesting, an app would not need to hold and
maintain the dlopen returned handle. This makes me wonder if these additions are
all to help make using loaded modules simpler.
 
Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/users/attachments/20170608/7c09bc56/attachment-0002.html>


More information about the users mailing list