Introduce a new rpath.0 custom section into Emscripten WASM module that stores runtime path for the module and can be used to locate shared libraries per-module (or extend the current dylink.0 section to have such value?)
Background
ELF binaries (or shared libraries) has rpath or runtime path section that is used to locate its dependent shared libraries. In addition to LD_LIBRARY_PATH which is a system-wide path for searching shared libraries, rpath can be used per-module path for searching its dependencies.
For now, -rpath flag is ignored when it is passed to emcc.
it would be nice if this is also available in Emscripten.
Alternatives / Current workaround
Currently, Pyodide performs rpath-like behavior in the following ways.
We directly use loadDynamicLibrary JS function instead of using dlopen.
When calling loadDynamicLibrary, we pass fs parameter with custom findObject function.
1.a. This function was removed in latest emscripten, but we are using a patched-version of it (https://github.com/emscripten-core/emscripten/pull/19310)
In out custom findObject function, we search shared libraries by looking at some pre-defined search path per module, which behaves like rpath.
Seems like a reasonable request yes. It would make sense to add this to the existing dylink.0. That section is deliberately designed to be extensible to include stuff like this.
Proposal
Introduce a new
rpath.0
custom section into Emscripten WASM module that stores runtime path for the module and can be used to locate shared libraries per-module (or extend the currentdylink.0
section to have such value?)Background
ELF binaries (or shared libraries) has
rpath
orruntime path
section that is used to locate its dependent shared libraries. In addition toLD_LIBRARY_PATH
which is a system-wide path for searching shared libraries,rpath
can be used per-module path for searching its dependencies.For now,
-rpath
flag is ignored when it is passed to emcc.Reason for the proposal
Pyodide loads python packages with shared libraries in runtime. In order to ensure that each Python package is self-contained, Python utilizes rpaths to locate dependent dynamic libraries within a single package.
For instance,
numpy
Python package for linux has following runtime path:and it is used to locate shared libraries in
numpy.libs
, which is not inLD_LIBRARY_PATH
.it would be nice if this is also available in Emscripten.
Alternatives / Current workaround
Currently, Pyodide performs rpath-like behavior in the following ways.
loadDynamicLibrary
JS function instead of usingdlopen
.loadDynamicLibrary
, we passfs
parameter with customfindObject
function. 1.a. This function was removed in latest emscripten, but we are using a patched-version of it (https://github.com/emscripten-core/emscripten/pull/19310)findObject
function, we search shared libraries by looking at some pre-defined search path per module, which behaves like rpath.References
Above all, thank you for maintaining such an amazing project! We (Pyodide) benefit a lot from Emscripten :)
cc: @hoodmane @agriyakhetarpal for visibility