[OpenWrt-Devel] Setting LD_LIBRARY_PATH is not cool

Kirill Elagin kirelagin at gmail.com
Thu May 21 01:59:06 EDT 2015

Git commit 98b0429
added the `$staging_dir/host/lib` directory to `$LD_LIBRARY_PATH`.
The problem with this approach is that some host tools used during the
build might need libraries from non-standard locations. They know where to
look for the libraries as they have proper `RUNPATH`.

Setting `$LD_LIBRARY_PATH` makes `ld.so` try to load libraries from the
wrong location first, and if it happens so that it finds the library there,
the program will fail.
And that’s exactly what’s happening in my case:

[nix-shell:~/proj/openwrt/openwrt]$ make V=s
make: *** [world] Segmentation fault

It turns, the failing line is `mkdir -p tmp` from the
`staging_dir/host/.prereq-build` in `include/toplevel.mk`. `mkdir` is
trying to load `libc.so` and loads an incompatible libc that is found in
`/lib`, instead of the one it needs, which resides in a non-standard

And that brings me to the second issue. The mentioned commit adds
`$(STAGING_DIR_HOST)/lib` to `$LIBRARY_PATH`, but, as far as I can tell,
`$(STAGING_DIR_HOST)` is not available there, so it ends up adding `/lib`.

I might be missing something crucial, but this last point makes me suspect
that the original idea never actually worked, and the fact that no one
noticed this suggests that the two lines can be safely dropped. Binaries in
`$(STAGING_DIR_HOST)/bin` that need special libraries have proper `RUNPATH`
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.infradead.org/pipermail/openwrt-devel/attachments/20150521/46fa57e2/attachment.htm>
-------------- next part --------------
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org

More information about the openwrt-devel mailing list