Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/link: support buildmode=pie with internal linking (on Android) #31343

Closed
eliasnaur opened this issue Apr 8, 2019 · 3 comments
Closed

cmd/link: support buildmode=pie with internal linking (on Android) #31343

eliasnaur opened this issue Apr 8, 2019 · 3 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@eliasnaur
Copy link
Contributor

eliasnaur commented Apr 8, 2019

With Termux it's now within reach to run all.bash directly an Android device without a host. Termux is an Android app that includes a complete Linux environment, including the NDK C toolchain.

However, I'm stopped by an unfortunate chain of constraints:

  1. Android only run PIE binaries, so buildmode=pie must be set in cmd/dist (https://go-review.googlesource.com/c/go/+/170943).
  2. Buildmode=pie forces external linking (cmd/go: buildmode=pie broken with -linkmode=internal and cgo #18968)
  3. External linking requires that the g register is allocated to TLS storage.
  4. Android doesn't support native ELF TLS storage (yet), so runtime/cgo is needed for setting up the g register storage at initialization using the pthread API.
  5. cmd/dist doesn't know how to build runtime/cgo.

Of the above conditions, 1, 3 and 4 are outside our control and I don't think we want to fix 5.

This issue is about relaxing 2, so buildmode=pie no longer requires external linking.

@cherrymui
Copy link
Member

cherrymui commented Apr 8, 2019

I'm not sure about Android, but on Linux, on AMD64 internal linking PIE should work. It is not the default, but -buildmode=pie -ldflags=-linkmode=internal would do. On ARM64, it is ongoing work on https://golang.org/cl/163579. (I'm not sure about 386 and ARM32.)

@gopherbot
Copy link
Contributor

Change https://golang.org/cl/170955 mentions this issue: runtime,runtime/cgo: set up TLS storage for Android Q without cgo

gopherbot pushed a commit that referenced this issue Apr 8, 2019
Android Q frees a static TLS slot for us to use. Use the offset of
that slot as the default for our TLS offset.

As a result, runtime/cgo is no more a requirement for Android Q and
newer.

Updates #31343
Updates #29674

Change-Id: I759049b2e2865bd3d4fdc05a8cfc6db8b0da1f5d
Reviewed-on: https://go-review.googlesource.com/c/go/+/170955
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Cherry Zhang <[email protected]>
@ALTree ALTree added the NeedsFix The path to resolution is known, but the work has not been done. label Apr 9, 2019
@ALTree ALTree added this to the Unplanned milestone Apr 9, 2019
@gopherbot
Copy link
Contributor

Change https://golang.org/cl/207299 mentions this issue: cmd/link: bootstrap android/arm64 in internal linking mode

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants