| 1 |
# General behavior of dynamic linkers on linux and macOS |
| 2 |
|
| 3 |
## Linking only |
| 4 |
|
| 5 |
Symbols are found based on link order. If two libraries export the same symbol, |
| 6 |
the first library in the link list is the library which is called. |
| 7 |
|
| 8 |
## Loading |
| 9 |
|
| 10 |
Applications cannot load symbols without specifying a library. |
| 11 |
Putting RTLD_NEXT in dlsym will not find any symbols even if a loaded library |
| 12 |
should contain them. |
| 13 |
An app _must_ reference a library that was loaded with `dlopen` to be able to |
| 14 |
get at its exported symbols through `dlsym`. |
| 15 |
If a loaded library loads subsequent libraries, and they all export the same |
| 16 |
symbols, the library which the application explicitly loaded is the one whose |
| 17 |
symbols are used. |
| 18 |
|
| 19 |
## Linking and Loading |
| 20 |
|
| 21 |
Applications can now use RTLD_NEXT to query symbols. |
| 22 |
They will always be the first linked library is that exported the symbol. |
| 23 |
In other words, loading a library explicitly doesn't change the behavior. |
| 24 |
|
| 25 |
Similarly, explicitly loaded libraries behave the same. |
| 26 |
Symbols from loaded libraries must be referenced to load the symbol, RTLD_NEXT |
| 27 |
doesn't work. |
| 28 |
If a loaded library subsequently loads another library which exports the same |
| 29 |
symbols, then the library the application explicitly loaded is used. |
| 30 |
If one of the subsequently loaded libraries happened to be linked, this doesn't |
| 31 |
affect the behavior when querying functions from the application loaded library. |