About dlclose in rtl
chrisj at rtems.org
Tue Jun 6 23:55:09 UTC 2017
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:
This Linux man page:
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.
More information about the users