• amelius an hour ago

    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?

    • TheDong 33 minutes ago

      There are things like this.

      The things I know of and can think of off the top of my head are:

      1. appimage https://appimage.org/

      2. nix-bundle https://github.com/nix-community/nix-bundle

      3. guix via guix pack

      4. A small collection of random small projects hardly anyone uses for docker to do this (i.e. https://github.com/NilsIrl/dockerc )

      5. A docker image (a package that runs everywhere, assuming a docker runtime is available)

      6. https://flatpak.org/

      7. https://en.wikipedia.org/wiki/Snap_(software)

      AppImage is the closest to what you want I think.

      • mdavid626 42 minutes ago

        You can "package" all .so files you need into one file, there are many tools which do this (like a zip file).

        But you can't take .so files and make one "static" binary out of them.

        • formerly_proven 11 minutes ago

          I don't think you can link shared objects into a static binary because you'd have to patch all instances where the code reads the PLT/GOT, but this can be arbitrarily mangled by the optimizer, and turn them back into relocations for the linker to then resolve them.

          You can change the rpath though, which is sort of like an LD_LIBRARY_PATH baked into the object, which makes it relatively easy to bundle everything but libc with your binary.

          edit: Mild correction, there is this: https://sourceforge.net/projects/statifier/ But the way this works is that it has the dynamic linker load everything (without ASLR / in a compact layout, presumably) and then dumps an image of the process. Everything else is just increasingly fancy ways of copying shared objects around and making ld.so prefer the bundled libraries.

          • aa-jv 24 minutes ago

            AppImage comes close to fulfilling this need:

            https://appimage.github.io/appimagetool/

            Myself, I've committed to using Lua for all my cross-platform development needs, and in that regard I find luastatic very, very useful ..

          • athrowaway3z 35 minutes ago

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

            • einpoklum an hour ago

              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"?

              • quesomaster9000 an hour ago

                Cosmopolitan goes one further: [binaries] that runs natively on Linux + Mac + Windows + FreeBSD + OpenBSD + NetBSD + BIOS on AMD64 and ARM64

                https://justine.lol/cosmopolitan/

                • oguz-ismail2 43 minutes ago

                  >Linux

                  if you configure binfmt_misc

                  >Windows

                  if you disable Windows Defender

                  >OpenBSD

                  only older versions

                • iberator 21 minutes ago

                  Yup. Just compile it as static executable. Static binaries are very undervalued imo.

                  • flohofwoe 9 minutes ago

                    The "just" is doing a lot of heavylifting here (as detailed in the article), especially for anything that's not a trivial cmdline tool.

                  • sambuccid 32 minutes ago

                    Appimage exists that packs linux applications into a single executable file that you just download and open. It works on most linux distros

                    • greyw 26 minutes ago

                      I vaguely remember that Appimage-based programs would fail for me because of fuse and glibc symbol version incompatibilties.

                      Gave up them afterwards. If I need to tweak dependencies might as well deal with the packet manager of my distro.

                    • Splizard an hour ago

                      Check out Cosmopolitan C, you can compile a single native binary that targets Linux, Windows & Mac OS (even multiple architectures) it includes its own libc.

                    • Meneth 36 minutes ago

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

                      • seba_dos1 2 minutes ago

                        Yeah, in my 20 years of using and developing on GNU/Linux the only binary compatibility issues I experienced that I can think of now were related to either Adobe Flash, Adobe Reader or games.

                        Adobe stuff is of the kind that you'd prefer to not exist at all rather than have it fixed (and today you largely can pretend that it never existed already), and the situation for games has been pretty much fixed by Steam runtimes already.

                        It's fine that some people care about it, but it just doesn't seem to be an actual issue you stumble on in practice much.