lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Also note that a POSIX system does not need any specific file format for **non-shared** libraries: they can just be represented simply as a simple archive (similar to a .zip file) or as a directory. In both cases, trhe units stored in these archives or directories are in random order (which is not warrantied to be stable across time, notably if you add or remove units or any other files from the archive or directory). The archive or directory may expose the list of their contents in arbitrary random order, or ordered in some arbitry collation order (depending on user's locale), so this is not stable and portable.

But you can make the order of units predictable by adding a supplementary "manifest" file in this directory or archive, to specify the explicit order in which units present in that directory or archive must be resolved.

Le sam. 24 nov. 2018 à 16:18, Philippe Verdy <verdy_p@wanadoo.fr> a écrit :
Note that Windows and the ELF format in general allows a shared library to be "pre-linked" within its set of internal references, but still be replaceable by a linker: the "pre-link" is kept as a default if there's no other implementation specified but this default is overridable if you specify a prior unit taking the priority, in which case that unit will become the implementation used by the shared libary itself at run-time (the default implementation will still be part of the modules possibly loaded in memory but they won't be used (and a VMM may not even need to page in these unused parts if they are larger than a single memory page, so this won't take too much memory; this unused implementation will still use some amount of virtual memory)...
For that case, the same symbol may be present in the list of imports and the list of exports in a "pre-linked" module (executable file, or shared-library)...

A "pre-linked" module may also specify restrictions in their list of imports, such as specifying that the symbol must be loaded from specific module names, or specifying that it must be in modules matching a specific digital signature, or other security constraints (like version number). The module also specifies also for its list of exports a set of properties, that allows other modules to check these constraints, notably the export list contains the name of the module itself, its version, and some data signature or globally unique identifier.


Le sam. 24 nov. 2018 à 16:01, Philippe Verdy <verdy_p@wanadoo.fr> a écrit :
If you use non-shared libraries, in fact the result is unpredictable, you could as well have seen:

Hello from main
        Hello from func1
        Hello from func2
        Back to func1
Back to main
        Hello from func2
Back to main

That's what I was demonstrating: there's undefined behavior ONLY if you use non-shared libraries because the order of units in these libraries is NOT significant.
And in fact makes the use of "pre-linked" even more relevant to this discussion.

Only non-shared libraries are not portable if you have multiple units defining the same symbol.
But you are not required to use them if, instead, you use a linker directly and specify a full list of units names (or shared library names) where the order of resolution is entirely determined.