android versus linux for GOOS

286 views
Skip to first unread message

jonathan...@gmail.com

unread,
May 18, 2016, 4:02:30 PM5/18/16
to golang-nuts
If statically compiling all the way down, is there any reason to use GOOS as android and not linux?

Frits van Bommel

unread,
May 19, 2016, 1:47:35 AM5/19/16
to golang-nuts, jonathan...@gmail.com
In the Go 1.6.1 tree:

$ find -name '*_android.go'
./runtime/write_err_android.go
./runtime/stubs_android.go
./runtime/internal/sys/zgoos_android.go
./runtime/os_android.go
./net/cgo_android.go
$ egrep '\+build.*\bandroid\b' -rn .
./os/user/lookup_unix.go:5:// +build darwin dragonfly freebsd !android,linux netbsd openbsd solaris
./os/user/lookup_stubs.go:5:// +build !cgo,!windows,!plan9 android
./runtime/write_err.go:5:// +build !android
./runtime/cgo/gcc_fatalf.c:7:// +build !android,linux
./runtime/internal/sys/zgoos_linux.go:3:// +build !android
./runtime/internal/sys/gengoos.go:50:            fmt.Fprintf(&buf, "// +build !android\n\n") // must explicitly exclude android for linux
./net/cgo_socknew.go:6:// +build android linux solaris
./net/cgo_resnew.go:6:// +build darwin linux,!android netbsd solaris
./net/cgo_resold.go:6:// +build android freebsd dragonfly openbsd
./net/cgo_linux.go:5:// +build !android,cgo,!netgo
$ egrep '//build.*\bandroid\b|runtime\.GOOS == "android"' -rn .
./os/os_test.go:589:    if runtime.GOOS == "android" {
./os/file_unix.go:349:        if runtime.GOOS == "android" {
./os/exec/exec_test.go:251:    if runtime.GOOS == "android" {
./runtime/pprof/pprof_test.go:261:    if runtime.GOOS == "android" {

Dave Cheney

unread,
May 19, 2016, 2:58:43 AM5/19/16
to golang-nuts
It depends on what you want to do. The differences between Linux and android are mainly to do with libc vs bionic and the different ways of handling tls and threading on those platforms.

What is the problem you are trying to solve?

jonathan...@gmail.com

unread,
May 19, 2016, 1:05:31 PM5/19/16
to golang-nuts
Just wanted to know where to expect issues in terms of compatibility, whether the two are actual compatible or not when fully statically linked. Initial test showed some kind of dns lookup issue when using GOOS linux instead of android which points inline with Frits reply? I remember hearing something of some compile flag that uses a golang dns bit?

jonathan...@gmail.com

unread,
May 26, 2016, 3:32:37 PM5/26/16
to golang-nuts, jonathan...@gmail.com
Even when using netgo build tag I still get:

dial tcp: lookup XXX on [::1]:53: read udp [::1]:53137-\u003e[::1]:53: read: connection refused

We have a fair amount of linux C dependencies we want to use, some not supporting android so was hoping a full static binary built for linux would still function, appears not?

Dave Cheney

unread,
May 26, 2016, 6:16:59 PM5/26/16
to golang-nuts, jonathan...@gmail.com
I doubt that will just work (tm). Android is not Linux when it comes to C code because the latter uses libc where Android uses its own implementation called bionic. In Go, we can mostly gloss over the details, but if it's honest to god C code, it'll trip over them straight away. 

jonathan...@gmail.com

unread,
May 26, 2016, 9:36:59 PM5/26/16
to golang-nuts, jonathan...@gmail.com
That is involved if static linking all the way?

Dave Cheney

unread,
May 26, 2016, 11:03:40 PM5/26/16
to golang-nuts, jonathan...@gmail.com
Yes, if you statically link a libc binary and run it on a platform that expects bionic, or vice versa, it's unlikely that will work.
Reply all
Reply to author
Forward
0 new messages