Fix nested dynamic library loading via RPATH
There is a bug with dynamic library loading. Suppose liba.so is on LD_LIBRARY_PATH and it has an RPATH of $ORIGIN/other_dir and loads libb.so from other_dir. Then suppose libb.so has an RPATH of $ORIGIN and wants to load libc.so also from other_dir.
Before this PR this doesn't work. The problem is that flags.rpath.parentLibPath is set to libb.so and we replace $ORIGIN with PATH.dirname(parentLibName) which is .. So unless other_dir is on the LD_LIBRARY_PATH or is the current working directory, loading will fail.
The fix: if findLibraryFS() returns a value that is not undefined, replace libName with the returned value.
I think this is the same thing I wanted to fix in https://github.com/emscripten-core/emscripten/pull/24234 and which is already in Pyodide patches
Apologies for now getting around to reviewing #24234 for such a long time.
@hoodmane does that look like it solving the same issue? Do you have a preference which approach is better?
Does this also fix https://github.com/emscripten-core/emscripten/issues/25814?
I think we can probably close this now that #24234 has landed. If #24234 doesn't solve your issue feel free to re-open