Build segfault with cross-build if host/target archs are compatible due to LD_LIBRARY_PATH issue


When using the --with-cross-build workflow to build ICU, and the host+target architectures are compatible (host can load target libraries), and the target has an incompatible/different C library than the host, and original $LD_LIBRARY_PATH is empty, the install phase of the target build may segfault as follows (I've replaced the long paths with @identifiers@ for clarity):

This is because the build scripting tries to prepend a few host-side directories to LD_LIBRARY_PATH (which is fine), but there is a problem in the ":$LD_LIBRARY_PATH" at the end of the assignment.
Our original $LD_LIBRARY_PATH is empty, so the final LD_LIBRARY_PATH will end with a colon. This causes the last entry to be "" (empty string), which actually means the current directory ($PWD). Therefore libraries from $PWD will be loaded.

This is a problem - as you can see in the above output, the pkgdata symlink code (in pkg_createSymLinks()) runs cd @TARGET_SYSROOT@/usr/lib so the current directory will actually contain target binaries, which should not be loaded on the host system.
Loading a mix of target and host libraries may cause a crash (e.g. loading a target is the issue is here).

A simple (though a bit ugly with all the multi-level escaping) fix would be to change all the instances of prepending entries to LD_LIBRARY_PATH (I count at least 8 in the source tree) so that instead of

they would use e.g.


which will both only add the colon if LD_LIBRARY_PATH is non-empty (i.e. they eliminate the extra colon if original LD_LIBRARY_PATH is empty).

We encountered this while using buildroot to generate a rootfs for an x86 embedded system that has a different C library than the host machine.




Anssi Hannula







Time Needed


Fix versions