logoalt Hacker News

The Holy Grail of Linux Binary Compatibility: Musl and Dlopen

124 pointsby Splizardtoday at 7:41 AM94 commentsview on HN

Comments

Rochustoday at 12:13 PM

So what we need is essentially a "libc virtualization".

But Musl is only available on Linux, isn't it? Cosmopolitan (https://github.com/jart/cosmopolitan) goes further and is available also on Mac and Windows, and it uses e.g. SIMD and other performance related improvements. Unfortunately, one has to cut through the marketing "magic" to find the main engineering value; stripping away the "polyglot" shell-script hacks and the "Actually Portable Executable" container (which are undoubtedly innovative), the core benefit proposition of Cosmopolitan is indeed a platform-agnostic, statically-linked C standard (plus some Posix) library that performs runtime system call translation, so to say "the Musl we have been waiting for".

show 2 replies
surajrmaltoday at 2:30 PM

Binary comparability extends beyond the vide that runs in your process. These days a lot of functionality occurs by way of IPC which has a variety of wire protocols depending on the interface. For instance there is dbus, Wayland protocols, varlink, etc. Both the wire protocol, and the APIs built on top need to retain backwards comparability to ensure Binary compatibility. Otherwise you're not going to be able to run on various different Linux based platforms arbitrarily. And unlike the kernel, these userspace surfaces do not take backwards compatibility nearly as important. It's also much more difficult to target a subset of these APIs that are available on systems that are only 5 years old. I would argue API endpoints on the web have less risk here (although those break all the time as well)

ValdikSStoday at 2:13 PM

`dlopen`'ing system libraries is an "easy" hack to try to maintain compatibility with wide variety of libraries/ABIs. It's barely used (I know only of SDL, Small HTTP Server, and now Godot).

Without dlopen (with regular dynamic linking), it's much harder to compile for older distros, and I doubt you can easily implement glibc/musl cross-compatibility at all in general.

Take a look what Valve does in a Steam Runtime:

    - https://gitlab.steamos.cloud/steamrt/steam-runtime-tools/-/blob/main/docs/pressure-vessel.md
    - https://gitlab.steamos.cloud/steamrt/steam-runtime-tools/-/blob/main/subprojects/libcapsule/doc/Capsules.txt
ameliustoday at 9:47 AM

Is there a tool that takes an executable, collects all the required .so files and produces either a static executable, or a package that runs everywhere?

show 10 replies
athrowaway3ztoday at 9:58 AM

I'd never heard of detour. That's a pretty cool hack.

show 1 reply
piliftoday at 1:17 PM

Isn't this asking for the exact trouble musl wanted so spare you from by disabling dlopen()?

mgaunardtoday at 11:13 AM

It's funny how people insist on wanting to link everything statically when shared libraries were specifically designed to have a better alternative.

Even worse is containers, which has the disadvantage of both.

show 6 replies
netbioserrortoday at 1:41 PM

I've been statically linking Nim binaries with musl. It's fantastic. Relatively easy to set up (just a few compiler flags and the musl toolchain), and I get an optimized binary that is indistinguishable from any other static C Linux binary. It runs on any machine we throw it at. For a newer-generation systems language, that is a massive selling point.

show 1 reply
einpoklumtoday at 9:17 AM

This seems interesting even regardless of go. Is it realistic to create an executable which would work on very different kinds of Linux distros? e.g. 32-bit and 64-bit? Or maybe some general framework/library for building an arbitrary program at least for "any libc"?

show 5 replies
Menethtoday at 9:57 AM

That seems mostly useful for proprietary programs. I don't like it.

show 2 replies
weebulltoday at 12:40 PM

If you're using dlopen(), you're just reimplementing the dynamic linker.

show 1 reply