You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Provide official CGO/libfuse build of rclone for Linux #5090
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
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.
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.
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
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
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
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.
Activity
ncw commentedon Mar 5, 2021
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_dynamicivandeex commentedon Mar 9, 2021
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.
ncw commentedon Mar 15, 2021
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.
billziss-gh commentedon Apr 19, 2021
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 symverdirectives 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.hheader. 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.1andfprintf@GLIBC_2.2might 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
structthat 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
ncw commentedon Apr 19, 2021
It is interesting to observe which GLIBC symbols rclone actually uses
and
So all the symbols are very old, except for
posix_spawn@@GLIBC_2.15and that was introduced in 2012-03-21.So maybe we don't need to do anything special here?
billziss-gh commentedon Apr 19, 2021
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:
What were the issues you were having with xgo then? Were they on Linux?
ncw commentedon Apr 20, 2021
OK
Yes you are right.
This would be easy to detect (with a cleaned up version of the one liner above).
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
I tried this and the dynamic builds with zig work fine :-)
With zcc as
and
Howver if I attempt to do a static build with
-target x86_64-linuxor-target x86_64-linux-muslthen the build works, but cmount/cgofuse doesn't with the errorI think that is because the
dlopenincgofusedoesn't work in a static binary.The solution for this would be for
cgofuseto have a build tag which means it doesn't usedlopenbut 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.ivandeex commentedon Oct 1, 2021
Will be good to document how CGO build affects go DNS resolver:
ivandeex commentedon Oct 21, 2021
Good to document that cgo-based package enables more mount options:
#5643 (comment)
ivandeex commentedon Oct 22, 2021
from ncw comment in the other ticket:
ivandeex commentedon Nov 9, 2021
See OpenWRT issue with rclone CGO build
ivandeex commentedon Jan 19, 2022
See rclone mount and mount2 soft-reboots OpenWrt - gotta test rclone cmount
ncw commentedon Jan 28, 2022
This issue also came up in #4984 - the solution
export GODEBUG=netdns=cgorequires a dynamically built rclone.