3 ms·
Unfortunately not even Linux allows full static linking (as far as I'm aware at least) as soon as libraries like OpenGL are involved. Dynamic linking with core
by flohofwoe 5y ago
Unfortunately not even Linux allows full static linking (as far as I'm aware at least) as soon as libraries like OpenGL are involved.
Dynamic linking with core system libraries which are guaranteed to exist(!) is fine though, for everything else dynamic linking mostly has downsides.
Also: it's only Linux where this is an issue, because it's nearly impossible to build small self-contained executables which run on another Linux machine, thanks to glibc's versioning mess (at least there's MUSL as an alternative to create portable command line tools).
- Macha 5y agoDidn't Go have to throw in the towel on not dynamically linking libc on macOS as there's no guarantee of syscall stability at all?
- flohofwoe 5y agoDon't know, I only know that I can build a macOS command line tool on one machine, and run it on a different machine without problems, while on Linux it's very easy to run into the glibc version compatibility problem.
- onei 5y agoI always understood the glibc versioning problem to be solved by just building on the oldest common ancestor. If you have rhel5 through 8, you build on rhel5 and move on. If you depend on more than glibc... Well rhel5 is less fun.
- ptsneves 5y agoIndeed, the only difference is that you might be using less optimal system calls, but there is no reason to be blocked and not target ancient kernels. I linked to 2.6 this year and everything ran fine.
- ghoward 5y agoAuthor here. Unfortunately, building on the oldest common ancestor will still not save you from ABI breaks. An example is [1]. If the size of `intmax_t` changes between that oldest ancestor and the machines you are running on, get ready for pain. [1]: https://thephd.dev/intmax_t-hell-c++-c https://thephd.dev/intmax_t-hell-c++-c
- patrakov 5y agoI don't know about macOS, but they also did this on OpenBSD. The reason is a recent security addition in OpenBSD, where they made it illegal (as in: violate it, and the process will be killed) to issue syscalls to the kernel from anything other than libc.
- Someone 5y agohttps://lwn.net/Articles/806776/ https://lwn.net/Articles/806776/ discusses that feature and says “Switching Go to use the libc wrappers (as is already done on Solaris and macOS)”, so yes, they did that on macOS, too. Reading https://golang.org/doc/go1.11#runtime https://golang.org/doc/go1.11#runtime, that’s fairly recent (since go 1.11)
- p_l 5y agoAt least one can statically link the application except for forcibly-dynamic libs like libGL (also, apparently using dlopen() is often faster than naive dynamic linking...)
- tyingq 5y agoIt's also tricky if you need to call gethostbyname() and expect system local behavior.
- edflsafoiewq 5y agoWell yeah, the GL calls are actually different on different machines right? Isn't that the absolute first consideration when deciding if you should dynamically link?
- flohofwoe 5y agoI'd rather expect that the 'user-facing' GL implementation (GL2.x, GL3.x, ...) is identical and can be statically linked, and that only the graphics driver layer differs between machines (which would be similar to an executable which links the C library statically, which in turn talks to the operating system through syscalls). But to be fair, dynamically linked GL wouldn't be a problem, if this wouldn't also pull in a dynamically linked glibc (it always comes back to glibc unfortunately).
- creshal 5y agoIsn't this the point of libglvnd?
- cesarb 5y ago> I'd rather expect that the 'user-facing' GL implementation (GL2.x, GL3.x, ...) is identical and can be statically linked, and that only the graphics driver layer differs between machines (which would be similar to an executable which links the C library statically, which in turn talks to the operating system through syscalls). The problem is that the "graphics driver layer" (except a small amount of security-sensitive pieces) runs in user space, in the same process which is doing the OpenGL/Vulkan/Metal/etc calls. The way modern graphics hardware works is that the application writes a very complex and hardware-dependent set of command buffers, which are then submitted to the hardware, and only this final submission goes through the kernel (for security reasons). If the application had to call the kernel for each and every step of the creation of the command buffers, it would kill the performance.
- simias 5y agoThat's normally what kernel abstractions are for, but unfortunately for various historical reasons graphics API often bypass the kernel in part or in full. There's also the problem that graphics are often very performance-sensitive so costly abstractions may not be desirable.