From 80195b7c24fb742b7886e613e14189c3b29dd368 Mon Sep 17 00:00:00 2001 From: Johannes Stoelp Date: Sat, 10 Jun 2023 22:04:06 +0200 Subject: ld.so: note about dlopen and LD_LIBRARY_PATH --- src/development/ld.so.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/development') 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`. -- cgit v1.2.3