Sysupgrade fails if openwrt is compiled with external toolchain

When openwrt builds it's own musl toolchain and installs the musl libs it creates a symlink from /lib/libc.so -> /usr/bin/ldd. This symlink is required for sysupgrade to work. Without it, the system uses LD_TRACE_LOADED_OBJECTS=1 which doesn't work under musl.

When openwrt builds from an external musl toolchain (even it's own) it doesn't create the symlink and sysupgrade fails with:

Failed to exec upgraded

The solutions I have are to either create a symlink or use /lib/libc.so --list for the ldd command. I've created this topic to help others that have this sysupgrade error because it is hard to debug without console access.

I'm not sure how the developers would want to add the symlink. Because an external musl toolchain sets USE_MUSL the ldd package is disabled. Maybe make the ldd package applicable to musl and creating the symlink there. Or key off the EXTERNAL_TOOLCHAIN_LIBC_USE_MUSL and create a generic symlink?

Is there a fool proof way of finding the loader at runtime so the:

[ -x /usr/bin/ldd ] || ldd() { LD_TRACE_LOADED_OBJECTS=1 $*; }

can be changed to:

[ -x /usr/bin/ldd ] || ldd() { SOME_LOADER --list $*; }

Indeed, could you try the following solution?

diff --git a/package/base-files/files/lib/upgrade/common.sh b/package/base-files/files/lib/upgrade/common.sh
index af1182cb16..01a7ed439c 100644
--- a/package/base-files/files/lib/upgrade/common.sh
+++ b/package/base-files/files/lib/upgrade/common.sh
@@ -2,7 +2,12 @@ RAM_ROOT=/tmp/root
 
 export BACKUP_FILE=sysupgrade.tgz      # file extracted by preinit
 
-[ -x /usr/bin/ldd ] || ldd() { LD_TRACE_LOADED_OBJECTS=1 $*; }
+if [ -x /lib/libc.so ]; then
+       ldd() { (exec -a ldd /lib/libc.so $*); }
+else
+       ldd() { LD_TRACE_LOADED_OBJECTS=1 $*; }
+fi
+
 libs() { ldd $* 2>/dev/null | sed -E 's/(.* => )?(.*) .*/\2/'; }
 
 install_file() { # <file> [ <file> ... ]

This will make sysupgrade independent of any existing ldd executable.

I'm sure it will work. I have an update to the toolchain makefile which will create a proper link for both internal and external toolchains that use musl. I thought that would have the smallest impact and the ldd link should be created anyway. I was going to submit a PR but I haven't gotten to it yet. Let me know which solution you think is best.

This was fixed couple of days ago:

Great. Thanks.