<div xmlns="http://www.w3.org/1999/xhtml">Boker tov,</div><div xmlns="http://www.w3.org/1999/xhtml"> </div><div xmlns="http://www.w3.org/1999/xhtml">Thanks for all of your replies that helped me to understand what question I really wanted to ask.</div><div xmlns="http://www.w3.org/1999/xhtml"> </div><div xmlns="http://www.w3.org/1999/xhtml">So this is a question.</div><div xmlns="http://www.w3.org/1999/xhtml"> </div><div xmlns="http://www.w3.org/1999/xhtml">I have C++ program which calls many services of third party library.</div><div xmlns="http://www.w3.org/1999/xhtml">This library is needed only on initialization phase of my program.</div><div xmlns="http://www.w3.org/1999/xhtml"> </div><div xmlns="http://www.w3.org/1999/xhtml"> </div><div xmlns="http://www.w3.org/1999/xhtml">Linker has resolved symbols of this library and now it is bound to executable and in a run tine</div><div xmlns="http://www.w3.org/1999/xhtml">this lib will be mapped will have use count > 0 while executable is in use.</div><div xmlns="http://www.w3.org/1999/xhtml">I would like to unmap it to release memory, but i do not know how to do it in user space.</div><div xmlns="http://www.w3.org/1999/xhtml"> </div><div xmlns="http://www.w3.org/1999/xhtml">As an alternative I know that by using dynamic loader calls dlopen() .. dlclose() I can achieve the desired effect</div><div xmlns="http://www.w3.org/1999/xhtml"> </div><div xmlns="http://www.w3.org/1999/xhtml">The problem that I need to add a lot of dlfind() calls, and I looked for a way dynamic loader can do it.</div><div xmlns="http://www.w3.org/1999/xhtml">I am not that lazy, but since the code is C++, function names are mangled and I was tring to avoid this</div><div xmlns="http://www.w3.org/1999/xhtml">by looking as a subject of this mail said, way to ask kernel to unmap this lib</div><div xmlns="http://www.w3.org/1999/xhtml"> </div><div xmlns="http://www.w3.org/1999/xhtml">I wish we have __init attribute in a user land !</div><div xmlns="http://www.w3.org/1999/xhtml"> </div><div xmlns="http://www.w3.org/1999/xhtml">Many Many Thanks again,</div><div xmlns="http://www.w3.org/1999/xhtml"> </div><div xmlns="http://www.w3.org/1999/xhtml">Lev.</div><div xmlns="http://www.w3.org/1999/xhtml"> </div><div xmlns="http://www.w3.org/1999/xhtml"> </div><div xmlns="http://www.w3.org/1999/xhtml">21.12.2018, 20:18, "Shachar Shemesh" <shachar@shemesh.biz>:</div><blockquote type="cite">
<div bidimailui-charset-is-forced="true" style="direction:ltr;" text="#000000" bgcolor="#FFFFFF">
<div>On 21/12/2018 16:20, Lev Olshvang
wrote:<br />
</div>
<blockquote type="cite" cite="mid:965981545402036@sas1-2b3c3045b736.qloud-c.yandex.net">
<pre wrap="">Hi All,
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 ?
2. And how to tell the dynamic linker ld-linux.so to postpone the symbol resolution until dlopen() will load the library?
3. Whether to compile and link executable with this library or leave unresolved symbols?</pre>
</blockquote>
<p>What you are asking for, as asked, is not possible. If you
explain your use case better, we might better understand what
you're trying to do.</p>
<p><br />
</p>
<p>With that said, I think you should just link the library.</p>
<p><br />
</p>
<p>All the text segments of the library (i.e. - code) will be loaded
with a read only shared mapping. This means that if they are not
used, they will be unmapped the first time memory becomes
constrained. If you do not use them later on, they will simply not
be loaded to memory. They will still be mapped, but will not load
your embedded system's memory in any significant way.</p>
<p><br />
</p>
<p>Shachar<br />
</p>
<br />
</div>
,<p>_______________________________________________<br />Linux-il mailing list<br /><a href="mailto:Linux-il@cs.huji.ac.il">Linux-il@cs.huji.ac.il</a><br /><a href="http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il">http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il</a><br /></p></blockquote>