diff options
author | Johannes Stoelp <johannes.stoelp@gmail.com> | 2023-06-10 22:04:06 +0200 |
---|---|---|
committer | Johannes Stoelp <johannes.stoelp@gmail.com> | 2023-06-10 22:04:06 +0200 |
commit | 80195b7c24fb742b7886e613e14189c3b29dd368 (patch) | |
tree | c4425c5a9b2990cc237f03244100b3c4124a9604 /src/development | |
parent | d2013ee5952bbcf88906a832748783e372f3a939 (diff) | |
download | notes-80195b7c24fb742b7886e613e14189c3b29dd368.tar.gz notes-80195b7c24fb742b7886e613e14189c3b29dd368.zip |
ld.so: note about dlopen and LD_LIBRARY_PATH
Diffstat (limited to 'src/development')
-rw-r--r-- | src/development/ld.so.md | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/development/ld.so.md b/src/development/ld.so.md index 311d1be..062bac6 100644 --- a/src/development/ld.so.md +++ b/src/development/ld.so.md @@ -11,6 +11,21 @@ =bindings show against which definition a symbol is bound ``` +### LD_LIBRARY_PATH and dlopen(3) +When dynamically loading a shared library during program runtime with +`dlopen(3)`, only the `LD_LIBRARY_PATH` as it was during program startup is +evaluated. +Therefore the following is a code smell: +```c +// at startup LD_LIBRARY_PATH=/moose + +// Assume /foo/libbar.so +setenv("LD_LIBRARY_PATH", "/foo", true /* overwrite */); + +// Will look in /moose and NOT in /foo. +dlopen("libbar.so", RTLD_LAZY); +``` + ## LD_PRELOAD: Initialization Order and Link Map Libraries specified in `LD_PRELOAD` are loaded from `left-to-right` but initialized from `right-to-left`. |