5 ms·
This seems to "statically link" binaries in the sense that each program it ships with is a standalone binary. Does anyone know whether it's possible to truly st
by HALtheWise 6y ago
This seems to "statically link" binaries in the sense that each program it ships with is a standalone binary. Does anyone know whether it's possible to truly statically link an entire Linux install, in the sense that the whole system is a single statically linked file including the kernel, display manager, web browser, etc so that link-time optimization can deduplicate code across the entire system?
- Subsentient 6y agoYes, I know that it's NOT possible. Anything that uses the same libraries, e.g. GTK+, will end up calling gtk_init() multiple times. Callback functions with the same names will collide at link-time. Despite the madness of the code that would be generated if the compiler allowed it, since it doesn't, you can expect a list of linker errors so long, that you can go to bed and wake up in the morning and it's still spewing to stderr.
- nybble41 6y agoIt could be done. Obviously you would only run one of the main functions (via a wrapper) per process invocation and you would need to rename conflicting global symbols at some point before the link step, but this is basically how tools like busybox work. If the application uses global constructors or init functions then those would require special handling since they bypass main—C tends to work better than C++ in this regard. Applying LTO to the resulting code for inter-application optimization would be an interesting twist.
- Subsentient 6y agoIt could be done if you heavily patched everything you linked in, or developed an entirely new compiler, or both, but as-is, no.
- nybble41 6y agoApart from the global initializers, everything necessary could be accomplished with a reasonable-length shell script applying "objcopy --redefine-syms" to the object files between the compilation and linking steps to add application-specific prefixes to all external symbols defined in any of the application's object files, without any changes to the source code or the compiler. I'm not saying it would be trivial, but it wouldn't require writing an entirely new compiler. Source: I've implemented programs similar to busybox before by merging programs originally intended to be compiled separately, albeit on a smaller scale than an entire Linux distribution.
- m463 6y ago> Does anyone know whether it's possible to truly statically link an entire Linux install I think if you give busybox enough time, it might happen. That's if systemd doesn't get there first, of course...
- ldng 6y agoThe answer is probably downvoted because of the systemd comment but I think that busybox is statically linkable, is it not ?
- yjftsjthsd-h 6y agoIt absolutely is; busybox is quite happy to be built into a single binary with no outside dependencies. Worked example: https://hub.docker.com/_/busybox https://hub.docker.com/_/busybox
- asveikau 6y agoI am not sure what you mean. The Linux kernel has dynamically loaded modules but you can build modules as statically part of the kernel. 'Y' instead of 'M' in the config. It doesn't make sense to "statically link" a kernel to a program, or multiple programs together, which I read your comment to suggest. That would be a different thing than the term "statically link" refers to.
- AnIdiotOnTheNet 6y ago> It doesn't make sense to "statically link" a kernel to a program That's kinda what a Unikernel is.
- deleted 6y ago[deleted]
- singron 6y agoI think they might be referring to a unikernel. https://en.m.wikipedia.org/wiki/Unikernel https://en.m.wikipedia.org/wiki/Unikernel In userspace, you can do what busybox does and link a bunch of programs together with a single main function that decides which program to actually run.
- birktj 6y agoI don't know if this is what you are thinking of, but there is this concept in embedded systems sometimes refereed to as library operating systems [1]. My understanding is that in this model the operating system is implemented as a library and you your system would consider of one application that uses the os library to do tasks usually handled by the operating system. [1]: https://en.wikipedia.org/wiki/Operating_system#Library https://en.wikipedia.org/wiki/Operating_system#Library
- cyphar 6y agoThis is kind of the idea behind unikernels. There are experimental Linux-based unikernels, but the more mature unikernels are custom.
- dleslie 6y agoYou're asking for something similar to a Lisp machine, or perhaps even an Amiga. Everything runs in the same address space and has access to all available library functions; "processes", such as they are, are in no way isolated.