casaroli commented on code in PR #20492: URL: https://github.com/apache/nuttx/pull/20492#discussion_r4292141563
########## Documentation/os/binfmt/kernel_modules_vs_shared_libraries.rst: ########## @@ -139,40 +139,52 @@ FLAT build. Opening a Library More Than Once ================================ -In the FLAT and PROTECTED builds, ``dlopen()`` of a library that is already +In the FLAT and PROTECTED builds, each task group has its own list of +loaded libraries. ``dlopen()`` of a library that the task group already loaded does not load a second copy and does not fail. It returns a handle to the library that is already loaded and takes an additional reference on it. Each successful ``dlopen()`` must be matched by a ``dlclose()``; the library is unloaded only when the last handle is closed. Up to 255 handles may be outstanding on one library; beyond that ``dlopen()`` fails with ``EMFILE``. +The libraries that a task group did not close are closed when it exits. +In the PROTECTED build only ``exit()`` closes them, so a task group that +ends in another way leaves them loaded. Some consequences worth keeping in mind: * A library is identified by the *basename* of the path passed to ``dlopen()``. Two files with the same basename in different directories are treated as the same library, and the second ``dlopen()`` will return the first one. -* There is only one instance of the library's ``.data`` and ``.bss``. Global - and static data are shared by every user of the library, and by every task - group in the system. -* Constructors in ``.init_array`` run once, when the library is first loaded, - and destructors in ``.fini_array`` run once, when the last handle is - closed. They do not run per ``dlopen()``/``dlclose()`` pair. +* Each task group that opens a library loads its own copy. Global and static + data are shared by the threads of one task group, not between task groups. + Only an FDPIC library executed in place from xipfs shares its ``.text`` + between task groups. +* Constructors in ``.init_array`` run once per task group, when the library + is first loaded in it, and destructors in ``.fini_array`` run once, when + its last handle in the task group is closed. They do not run per + ``dlopen()``/``dlclose()`` pair. +* The libraries that a program loaded by ``exec()`` names in ``DT_NEEDED`` + belong to its task group in the FLAT build, so ``dlopen()`` of one of them Review Comment: @xiaoxiang781216 I think we can make it work in kernel mode as well, and I would like to do it. However, the kernel work is relatively small compared to the userspace. So I suggest we merge this one as it is, as it wraps up the fdpic (XIP) shared object support. And since my next batch of work is focused on improving kernel mode, I will add shared object support in next PRs. What do you think? Can we merge this one? Thank you for the reviews! -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
