bazel-contrib / bazel-contrib/rules_go
android_386_cgo causes a linker error
- Dominant language
- Go
- Stars
- 1.5k
- Forks
- 760
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 12
Description
### What version of rules_go are you using?
v0.21.2 (latest)
### What version of gazelle are you using?
None
### What version of Bazel are you using?
2.1.0 (latest)
### Does this issue reproduce with the latest releases of all the above?
Yes
### What operating system and processor architecture are you using?
Vagrant ubuntu/xenial64 (Linux ubuntu-xenial 4.4.0-145-generic #171-Ubuntu SMP Tue Mar 26 12:43:40 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux)
### Any other potentially useful information about your toolchain?
See the [bug repository](https://github.com/ekuiter/bazel-go-android-issue) for reproduction with Vagrant.
### What did you do?
Clone [this repository](https://github.com/ekuiter/bazel-go-android-issue), run `vagrant up` and `vagrant ssh`, cd into `/vagrant/example` and run `./build.sh`.
This should compile a very basic Go example for Android, but does not work.
(Background: I want to compile some Go code (https://github.com/scionproto/scion) for Android. In the end, I will need to allow for some C code, so I have to use the "@io_bazel_rules_go//go/toolchain:android_*_cgo" family of platforms.)
### What did you expect to see?
Compilation success when running:
```
bazel build //example --crosstool_top=@androidndk//:default_crosstool --host_crosstool_top=@bazel_tools//tools/cpp:toolchain --cpu=x86 --platforms=@io_bazel_rules_go//go/toolchain:android_386_cgo
```
### What did you see instead?
A linker error:
```
internal/cpu.processOptions: relocation target __x86.get_pc_thunk.dx not defined
internal/cpu.processOptions: relocation target __x86.get_pc_thunk.ax not defined
internal/cpu.doinit: relocation target __x86.get_pc_thunk.ax not defined
internal/cpu.doinit: relocation target __x86.get_pc_thunk.si not defined
internal/cpu.doinit: relocation target __x86.get_pc_thunk.cx not defined
internal/cpu.doinit: relocation target __x86.get_pc_thunk.bx not defined
internal/cpu.doinit: relocation target __x86.get_pc_thunk.bp not defined
internal/cpu.doinit: relocation target __x86.get_pc_thunk.dx not defined
internal/cpu.doinit: relocation target __x86.get_pc_thunk.di not defined
cmpbody: relocation target __x86.get_pc_thunk.cx not defined
memeqbody: relocation target __x86.get_pc_thunk.cx not defined
runtime.f32hash: relocation target __x86.get_pc_thunk.ax not defined
runtime.f64hash: relocation target __x86.get_pc_thunk.ax not defined
runtime.interhash: relocation target __x86.get_pc_thunk.dx not defined
runtime.interhash: relocation target __x86.get_pc_thunk.ax not defined
runtime.nilinterhash: relocation target __x86.get_pc_thunk.dx not defined
runtime.nilinterhash: relocation target __x86.get_pc_thunk.ax not defined
runtime.efaceeq: relocation target __x86.get_pc_thunk.dx not defined
runtime.efaceeq: relocation target __x86.get_pc_thunk.ax not defined
runtime.ifaceeq: relocation target __x86.get_pc_thunk.dx not defined
runtime.ifaceeq: relocation target __x86.get_pc_thunk.ax not defined
external/go_sdk/pkg/tool/linux_amd64/link: too many errors
```
For the other architectures supported by Android, see the README file in the linked repository.
I have tried several version combinations for Bazel, rules_go, Android NDK, and Go. Nothing seems to work. The only way I can manage to compile the minimal example (as well as the actual code I want to compile, https://github.com/scionproto/scion) for Android is like this:
```
bazel build //example --platforms=@io_bazel_rules_go//go/toolchain:linux_386
```
However, this way no C code can be included with the application at all. Is it really impossible to compile a Go application with C bindings for Android, or am I missing something obvious?
Contributor guide
Research direction
Clone the linked bug repository, run `vagrant up`, enter the example directory with `vagrant ssh`, and reproduce the failure with `./build.sh` and the documented Bazel command. Compare the Android cgo toolchain behavior with the working linux_386 build and the linker output. Done means the minimal Go example builds successfully for Android with cgo enabled.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, go
- Domain
- build-system, mobile-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100