Pre-load OMC shared libraries by absolute path in topological order#15
Merged
Merged
Conversation
The prebuilt .so files shipped in the libs-v0.1.0 release have RUNPATH baked to the original build host (/home/johti17/Projects/OpenModelica/ build_cmake/...), so ld.so cannot resolve inter-library DT_NEEDED entries on consumer machines. The previous __init__ only dlopen'd libModelicaCallbacks, libModelicaIO and libModelicaExternalC, leaving libOpenModelicaRuntimeC, libomcgc, libModelicaMatIO, libModelicaStandardTables and libSimulationRuntimeC unresolved. As a result loading libModelicaStandardTables.so fails with "libModelicaIO.so: cannot open shared object file" whenever an external Modelica function is invoked, even though libModelicaIO.so sits next to it on disk. The ENV["LD_LIBRARY_PATH"] mutation in the old __init__ is ineffective on Linux because glibc's ld.so caches LD_LIBRARY_PATH at process start. Dlopen every shipped library by absolute path with RTLD_GLOBAL in a fixed topological order. ld.so reuses the already-loaded library when it sees the same SONAME on a dependent load, so DT_NEEDED references are satisfied without relying on RUNPATH or LD_LIBRARY_PATH. The libModelicaCallbacks shim is still loaded first so its symbols win global resolution and override the default OMC setjmp/longjmp-based error handlers. Verified with the libs-v0.1.0 zip on Linux: dlopen of libModelicaStandardTables.so now succeeds where it previously failed with the same error observed in JKRT/OM.jl#44 CI. Refs JKRT/OM.jl#44 Co-Authored-By: JKRT_CLAUDE <247156613+SVAGEN26@users.noreply.github.com>
Co-Authored-By: JKRT_CLAUDE <247156613+SVAGEN26@users.noreply.github.com>
SVAGEN26
added a commit
to SVAGEN26/OM.jl
that referenced
this pull request
Jun 14, 2026
The OMRuntimeExternalC.jl libs-v0.1.0 Linux zip ships the OMC libraries but not their system dependencies. libSimulationRuntimeC.so has DT_NEEDED entries for liblapack.so.3, libblas.so.3 and libgfortran.so.5, which ubuntu-24.04 runners do not provide out of the box. The Julia __init__ pre-load (OpenModelica/OMRuntimeExternalC.jl#15) loads every shipped OMC library correctly, then fails on libSimulationRuntimeC with "liblapack.so.3: cannot open shared object file", taking down every MSL, Spice3 and external-builtin test that goes through structural_simplify or the OMC nonlinear solver. Install liblapack3, libblas3 and libgfortran5 before julia-actions/ setup-julia runs. The Windows x86_64-mingw32 zip is self-contained (libgfortran-5.dll, libgcc_s_seh-1.dll, libopenblas.dll, libstdc++-6.dll and friends are all bundled), so no install step is needed there. Refs JKRT#44, OpenModelica/OMRuntimeExternalC.jl#15 Co-Authored-By: JKRT_CLAUDE <247156613+SVAGEN26@users.noreply.github.com>
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Tests in
JKRT/OM.jlPR #44 (and any other downstream consumer ofOMRuntimeExternalC.jlon Linux CI) fail with:even though
libModelicaIO.soexists next tolibModelicaStandardTables.soinlib/ext/shared/x86_64-linux-gnu/. Knock-on effect is 8 errored tests underOMRuntimeExternalC APIand 10+ errored / failed tests underexternalBuiltinTests.jland downstream IMTK simulate paths inJKRT/OM.jlCI.Root cause
Every
.soin thelibs-v0.1.0release zip has itsDT_RUNPATHbaked to the original build host:That path does not exist on consumer machines, so ld.so cannot resolve inter-library
DT_NEEDEDreferences on its own. The previous__init__only pre-loadedlibModelicaCallbacks,libModelicaIOandlibModelicaExternalC, leavinglibOpenModelicaRuntimeC,libomcgc,libModelicaMatIO,libModelicaStandardTablesandlibSimulationRuntimeCunresolved.The
ENV["LD_LIBRARY_PATH"]mutation in the old__init__is ineffective on Linux because glibc's ld.so cachesLD_LIBRARY_PATHat process start.Fix
Pre-load every shipped library by absolute path with
RTLD_GLOBALin a fixed topological order:ld.so reuses the already-loaded library when it sees the same SONAME on a dependent load, so DT_NEEDED references are satisfied without relying on RUNPATH or
LD_LIBRARY_PATH. SONAMEs in the release zip match the DT_NEEDED entries verbatim, so reuse is guaranteed.libModelicaCallbacksis still loaded first so its symbols win global resolution and override the default OMC setjmp/longjmp-based error handlers.Test evidence
Reproduced with the
libs-v0.1.0release zip on Linux x86_64, Julia 1.12.6:Before (upstream master):
After this PR:
Identical error string in the before-state to what
JKRT/OM.jlPR #44 CI emits.Follow-ups not in this PR
-Wl,-rpath,'$ORIGIN' -Wl,--enable-new-dtags) is still worth doing eventually so the package does not have to babysit ld.so. This PR makes the Julia-side correct regardless.libs-v0.1.0release shipslibomcgc.sobutpathSetup.jldoes not track it; the new__init__locates it by name fromlibdir, which keeps the change minimal. Tracking it inpathSetup.jlcan come later if anything else needs to reference the path.x86_64-linux-gnu-callbacks.tar.gzinbuild.jlis a separate, pre-existing release-artifact gap (local fallback handles it but should be cleaned up).Refs JKRT/OM.jl#44