Skip to content

Provide official CGO/libfuse build of rclone for Linux #5090

Open

Description

@ivandeex

What is your current rclone version (output from rclone version)?

1.54.0

What problem are you are trying to solve?

Currently https://downloads.rclone.org/ provides libfuse builds of rclone only for Windows and OSX.
For Linux, both zip and deb artifacts contain a static executable. Thus, passing custom fuse flags is not possible.
See #3545 for an example why it can be useful.

How do you think rclone should be changed to solve that?

Provide official CGO/libfuse build of rclone for Linux

Activity

  1. ncw commented on Mar 5, 2021

    @ncw
    Member

    There was some discussion of this here: #4702 - I quite liked the idea of compiling against an ancient glibc for the maximum compatibility

    I also did some investigation about what symbols rclone would use from glibc but I can't find those notes :-( The conclusion was it didn't use much.

    The main problem with this is rclone builds for zillions of GOARCH for linux, and we'll need a native compiler for each one, or to use something like xgo

    You'll note we do already have an xgo build but I stopped building the desktop OS builds because they were hard to keep working.

    So I'd propose that we just try amd64 to start with with a new build target in build.yml linux_dynamic

  2. ivandeex commented on Mar 9, 2021

    @ivandeex
    MemberAuthor

    So let's narrow the request to:
    OS=linux ARCH=amd64 MakeTarget=linux_dynamic Builder=xgo
    I've been using such a build in my deployments for some time.
    I think I can look into this as part of my work on the mount improvements later this year.
    We can announce it as an experimental package and see what people say.

  3. self-assigned this
    on Mar 9, 2021
  4. ncw commented on Mar 15, 2021

    @ncw
    Member

    There is another option for doing this...

    You can use zig as a C compiler and it bundles all the cross compile libcs with it - see this article for details: https://dev.to/kristoff/zig-makes-go-cross-compilation-just-work-29ho

    So I think it would be possible to use zig to cross compile static builds (using musl) for all architectures which would include cmount and be static builds.

  5. modified the milestones: v1.57, Soon on Apr 4, 2021
  6. billziss-gh commented on Apr 19, 2021

    @billziss-gh
    Contributor

    Adding myself to this issue as it is related to cgofuse and I am also looking for ways to produce cgo binaries that can run on any distro.

    • A promising project that I have found for this purpose is Holy Build Box.

      • This one works by providing an old version of Centos that has an old version of GLIBC. I believe the project also includes a modern toolchain. See Features.

      • I have not tried this myself.

    • An alternative approach is to include a header file that contains asm symver directives that instruct the compiler to reference older GLIBC symbols. I follow this approach in my new project libc-compat (Work In Progress).

      • The reason that I am contemplating this alternative is that I find it easier to retrofit a cgo build to reference the libc-compat.h header. For example, it should be relatively easy to modify xgo-cgofuse to perform such builds.

      • There are potential issues with this approach:

        • Might miss important bug fixes in newer symbols.

        • It is likely that multiple versions of the same symbol might be used when dyna-linking with other libs. For example, both fprintf@GLIBC_2.1 and fprintf@GLIBC_2.2 might be used. I have seen claims on the Internet that this should work, but nothing authoritative.

        • It is possible that using old symbols with new headers can also cause problems. For example, suppose that a new header changed the definition of an internal struct that is accessed via a macro or inline from the header file. We could then have code in the executable using both the new struct definition via the macro and the old struct definition via the old symbol reference. (I am not aware of any such cases, but it is a possibility.)

    Both these approaches would build executables that run on glibc-based systems. Distros that uses other libc's (e.g. Alpine/MUSL) may not be supported (but here is an interesting project: gcompat).

    Finally there is the possibility to statically link libfuse (and everything else). I seem to remember that the libfuse build system used to support this, but I am not certain that it currently does. Related GitHub issue: libfuse/libfuse#383

  7. ncw commented on Apr 19, 2021

    @ncw
    Member

    It is interesting to observe which GLIBC symbols rclone actually uses

    $ go build -tags cmount
    $ nm ~/go/bin/rclone | grep GLIBC
                     U abort@@GLIBC_2.2.5
                     U calloc@@GLIBC_2.2.5
                     U dlerror@@GLIBC_2.2.5
                     U dlopen@@GLIBC_2.2.5
                     U dlsym@@GLIBC_2.2.5
                     U __errno_location@@GLIBC_2.2.5
                     U exit@@GLIBC_2.2.5
                     U __fprintf_chk@@GLIBC_2.3.4
                     U fputc@@GLIBC_2.2.5
                     U freeaddrinfo@@GLIBC_2.2.5
                     U free@@GLIBC_2.2.5
                     U fwrite@@GLIBC_2.2.5
                     U gai_strerror@@GLIBC_2.2.5
                     U getaddrinfo@@GLIBC_2.2.5
                     U getgrgid_r@@GLIBC_2.2.5
                     U getgrnam_r@@GLIBC_2.2.5
                     U getgrouplist@@GLIBC_2.2.5
                     U getnameinfo@@GLIBC_2.2.5
                     U getpwnam_r@@GLIBC_2.2.5
                     U getpwuid_r@@GLIBC_2.2.5
                     U __libc_start_main@@GLIBC_2.2.5
                     U malloc@@GLIBC_2.2.5
                     U mmap@@GLIBC_2.2.5
                     U munmap@@GLIBC_2.2.5
                     U nanosleep@@GLIBC_2.2.5
                     U posix_spawn@@GLIBC_2.15
                     U pthread_attr_destroy@@GLIBC_2.2.5
                     U pthread_attr_getstacksize@@GLIBC_2.2.5
                     U pthread_attr_init@@GLIBC_2.2.5
                     U pthread_cond_broadcast@@GLIBC_2.3.2
                     U pthread_cond_wait@@GLIBC_2.3.2
                     U pthread_create@@GLIBC_2.2.5
                     U pthread_detach@@GLIBC_2.2.5
                     U pthread_mutex_lock@@GLIBC_2.2.5
                     U pthread_mutex_unlock@@GLIBC_2.2.5
                     U pthread_sigmask@@GLIBC_2.2.5
                     U realloc@@GLIBC_2.2.5
                     U realpath@@GLIBC_2.3
                     U setegid@@GLIBC_2.2.5
                     U setenv@@GLIBC_2.2.5
                     U seteuid@@GLIBC_2.2.5
                     U setgid@@GLIBC_2.2.5
                     U setgroups@@GLIBC_2.2.5
                     U setregid@@GLIBC_2.2.5
                     U setresgid@@GLIBC_2.2.5
                     U setresuid@@GLIBC_2.2.5
                     U setreuid@@GLIBC_2.2.5
                     U setuid@@GLIBC_2.2.5
                     U sigaction@@GLIBC_2.2.5
                     U sigaddset@@GLIBC_2.2.5
                     U sigemptyset@@GLIBC_2.2.5
                     U sigfillset@@GLIBC_2.2.5
                     U sigismember@@GLIBC_2.2.5
                     U __stack_chk_fail@@GLIBC_2.4
                     U stderr@@GLIBC_2.2.5
                     U strerror@@GLIBC_2.2.5
                     U sysconf@@GLIBC_2.2.5
                     U umount2@@GLIBC_2.2.5
                     U unsetenv@@GLIBC_2.2.5
                     U __vfprintf_chk@@GLIBC_2.3.4
                     U waitpid@@GLIBC_2.2.5
                     U write@@GLIBC_2.2.5
    

    and

    $ nm ~/go/bin/rclone | grep GLIBC | cut -d@ -f3 | sort | uniq -c | sort -n
          1 GLIBC_2.15
          1 GLIBC_2.3
          1 GLIBC_2.4
          2 GLIBC_2.3.2
          2 GLIBC_2.3.4
         55 GLIBC_2.2.5
    

    So all the symbols are very old, except for posix_spawn@@GLIBC_2.15 and that was introduced in 2012-03-21.

    So maybe we don't need to do anything special here?

  8. billziss-gh commented on Apr 19, 2021

    @billziss-gh
    Contributor

    So all the symbols are very old, except for posix_spawn@@GLIBC_2.15 and that was introduced in 2012-03-21.

    So maybe we don't need to do anything special here?

    This certainly seems to suggest so, yes.

    Of course if GLIBC adds a new version for a symbol that we use in GLIBC 2.34+ we may start having problems.

    In an earlier message you said:

    You'll note we do already have an xgo build but I stopped building the desktop OS builds because they were hard to keep working.

    What were the issues you were having with xgo then? Were they on Linux?

  9. ncw commented on Apr 20, 2021

    @ncw
    Member

    So all the symbols are very old, except for posix_spawn@@GLIBC_2.15 and that was introduced in 2012-03-21.
    So maybe we don't need to do anything special here?

    This certainly seems to suggest so, yes.

    OK

    Of course if GLIBC adds a new version for a symbol that we use in GLIBC 2.34+ we may start having problems.

    Yes you are right.

    This would be easy to detect (with a cleaned up version of the one liner above).

    In an earlier message you said:

    You'll note we do already have an xgo build but I stopped building the desktop OS builds because they were hard to keep working.

    What were the issues you were having with xgo then? Were they on Linux?

    We've stopped using xgo completely now.

    The main problem is that xgo wasn't being updated so the go version it used was (go1.13) was falling behind the go version rclone wanted to use (go1.16). When dependencies start using new go features I have to gate them in on that go version so it meant that trying to build with go1.13 was missing a lot of stuff. It also stopped building the macOS version.

    I gradually chopped off the desktop builds 0afd5a2, then the ios build and then we put native builders in for the android build so it became superflous 5577c7b

    You can use zig as a C compiler and it bundles all the cross compile libcs with it - see this article for details: https://dev.to/kristoff/zig-makes-go-cross-compilation-just-work-29ho

    So I think it would be possible to use zig to cross compile static builds (using musl) for all architectures which would include cmount and be static builds.

    I tried this and the dynamic builds with zig work fine :-)

    With zcc as

    #!/bin/sh
    ZIG_LOCAL_CACHE_DIR="$HOME/tmp" zig cc -target x86_64-linux-gnu $@
    

    and

    CGO_ENABLED=1 GOOS=linux GOARCH=amd64 CC="zcc" go build --tags cmount -v
    

    Howver if I attempt to do a static build with -target x86_64-linux or -target x86_64-linux-musl then the build works, but cmount/cgofuse doesn't with the error

    ./rclone cmount -vv /tmp/ /mnt/tmp/
    2021/04/20 08:33:07 Fatal error: failed to mount FUSE fs: mount stopped before calling Init: mount failed: cgofuse: cannot find FUSE
    

    I think that is because the dlopen in cgofuse doesn't work in a static binary.

    The solution for this would be for cgofuse to have a build tag which means it doesn't use dlopen but links against libfuse in the traditional C manner I think. Though I had a great deal of difficulty trying to link libfuse into the static build so maybe that won't work either.

  10. ivandeex commented on Oct 1, 2021

    @ivandeex
    MemberAuthor
  11. ivandeex commented on Oct 21, 2021

    @ivandeex
    MemberAuthor

    Good to document that cgo-based package enables more mount options:
    #5643 (comment)

  12. ivandeex commented on Oct 22, 2021

    @ivandeex
    MemberAuthor

    from ncw comment in the other ticket:

    Here is another idea for cross building dynamic libraries: https://dev.to/kristoff/zig-makes-go-cross-compilation-just-work-29ho

    zig can act as a C toolchain and out of the box can cross compile for many platforms.

  13. modified the milestones: Soon, v1.59 on Nov 9, 2021
  14. ivandeex commented on Nov 9, 2021

    @ivandeex
    MemberAuthor
  15. ivandeex commented on Jan 19, 2022

    @ivandeex
    MemberAuthor
  16. ncw commented on Jan 28, 2022

    @ncw
    Member

    This issue also came up in #4984 - the solution export GODEBUG=netdns=cgo requires a dynamically built rclone.

  17. modified the milestones: v1.59, v1.60 on Feb 13, 2022
  18. modified the milestones: v1.60, Help Wanted on Dec 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions