How to signal kernel that shared library is not in use by any process anymore ?

Bernd Petrovitsch bernd at petrovitsch.priv.at
Fri Dec 21 21:34:04 EST 2018


Hi all!

On 21/12/2018 15:20, Lev Olshvang wrote:
[...]
> I have  an executable (C++) which is the exclusive user of the some shared library that it uses only during  the initialization phase.
> 
> I would like to free memory used by this shared library, because I am running on embedded system.
> 
> How can I achieve this?
> 
> I know that dlopen() will load shared library, and hope that following dlclose() will free this lib memory. 
> 
> 1. Still  I do not know what method should be used to make dynamic linker look again into executable and resolve symbols of the newly appeared symbols ?

There is no such method TTBOMK. Since the linker (and thus the shared
loader) do not know of this library, they can't do anything (see below).

The C++ application has to resolve the symbols with dlsym() (after a
successful dlopen()) and call it with an appropriate type cast.
After dlclose(), the pointers from dlasym() are invalid (obviously - as
the lib is gone/unmapped).

> 2. And  how to tell the dynamic linker ld-linux.so to postpone the symbol resolution until dlopen()  will load  the library?

Do not mention that library (when linking the application).

> 3. Whether to compile and link executable with this library or leave unresolved symbols?

You do not call the functions directly (and you cannot as the linker
cannot resolve them anyways as the linker doesn't know the library).

MfG,
	Bernd
-- 
Bernd Petrovitsch                  Email : bernd at petrovitsch.priv.at
                     LUGA : http://www.luga.at



More information about the Kernelnewbies mailing list