Go 1.5.1 Android NDK cross compilation

388 views
Skip to first unread message

Péter Szilágyi

unread,
Sep 14, 2015, 6:00:34 AM9/14/15
to golang-nuts
Hey all,

  I've been playing around with cross compiling CGO enabled (and C dependent) programs to Android. Building for ARMv7 (i.e. CC=arm-linux-androideabi-gcc GOOS=android GOARCH=arm GOARM=7 CGO_ENABLED=1) works perfectly, dependencies and everything and I can successfully run the programs on my Nexus. However, when I wanted to extend cross compilation to Android x86 or MIPS, I'm getting peculiar errors.

  Building on x86 (i.e. CC=i686-linux-android-gcc GOOS=android GOARCH=386 CGO_ENABLED=1), I get a failure when Go is trying to build the runtime package:

# runtime
/usr/local/go/src/runtime/print1_write_android.go:101: undefined: sockaddr_un
/usr/local/go/src/runtime/print1_write_android.go:105: undefined: _AF_UNIX
/usr/local/go/src/runtime/print1_write_android.go:112: undefined: _AF_UNIX
/usr/local/go/src/runtime/print1_write_android.go:112: undefined: _SOCK_DGRAM
/usr/local/go/src/runtime/print1_write_android.go:119: invalid expression unsafe.Sizeof(logdAddr)

  Building on MIPS (i.e. CC=mipsel-linux-android-gcc GOOS=android GOARCH=mips CGO_ENABLED=1), I get a completely different issue, that I thought Go 1.5 resolved after switching to pure Go:

go build runtime: android/mips must be bootstrapped using make.bash

  I've yet to work my way towards the 64 bit platform, thought I'd throw this out if somebody has any ideas or pointers :)

Thanks,
  Peter

Péter Szilágyi

unread,
Sep 14, 2015, 6:56:36 AM9/14/15
to golang-nuts
Just for the reference, I'm getting the same undefined errors for android/arm64 and android/amd64 too. MIPS64 hits some undefined opcodes (most probably inline assemble) in my external dependencies, so that's an unrelated issue.

Hyang-Ah Hana Kim

unread,
Sep 14, 2015, 7:19:34 AM9/14/15
to Péter Szilágyi, golang-nuts
Go 1.5.X supports only android/arm. 

I worked on x86, targeting for 1.6. (https://github.com/golang/go/issues/9327
Need to rework as the toolchain is changing. 

Uber issue to support other architectures is 

Given that I don't see mips on build.golang.org
I don't know how much work is necessary for mpis or other architectures.

The undefined errors are easy to fix. Need to define some consts and types in runtime, 
and write functions to call related syscalls.


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
__

Péter Szilágyi

unread,
Sep 14, 2015, 7:24:21 AM9/14/15
to Hyang-Ah Hana Kim, golang-nuts
Yeah, I also found the "offending" commit. https://github.com/golang/go/commit/3a8713575499622dbe77d78e9871dbe2ae94b8bb only defines the reported types for linux-arm, but forgot to include it to arm64 and the other platforms, hence the compilation issue. I'll try fixing them and will open a CL if they indeed fix the issue.

I don't mind not supporting MIPS, I'm just adding android targets to my cross compiler and thought that if the NDK supports MIPS out of the box, I can also add it, but I don't mind dropping it.

Péter Szilágyi

unread,
Sep 14, 2015, 7:26:15 AM9/14/15
to Hyang-Ah Hana Kim, golang-nuts
Oh btw, I'm not using gomobile. Only the pure go build and my own cross compilation wrapper around it (https://github.com/karalabe/xgo), so if the core tools can build, I'm happy already ;)

Hyang-Ah Hana Kim

unread,
Sep 14, 2015, 7:39:51 AM9/14/15
to Péter Szilágyi, golang-nuts
no, the core tools cannot build. The issues are about the core tools.
--
__

Péter Szilágyi

unread,
Sep 14, 2015, 7:46:39 AM9/14/15
to Hyang-Ah Hana Kim, golang-nuts
Ah ok, thought the runtime was prepared generally for cross compilation, only a minor issue crept in (though after patching the undefined things I see the bigger issues in the assembly implementations). Then I'll probably just watch from the background for now. I doubt I'd be able to contribute to the runtime itself. Will watch the progress keenly though. :)

Hyang-Ah Hana Kim

unread,
Sep 14, 2015, 7:52:52 AM9/14/15
to Péter Szilágyi, golang-nuts
If you have CLs for those missing types and symbols, feel free to send cls. I have one for x86, but I couldn't test it yet - because it doesn't build :-) - so I was waiting. For other architectures, who knows.. I even didn't try.
--
__
Reply all
Reply to author
Forward
0 new messages