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

runtime: sigaction is calling getg before TLS is set up on Android #31476

Closed
eliasnaur opened this Issue Apr 15, 2019 · 2 comments

Comments

Projects
None yet
3 participants
@eliasnaur
Copy link
Contributor

commented Apr 15, 2019

The following crash has started to appear when running Android apps with Go tip:

04-15 20:49:36.875  4033  4033 F DEBUG   :     #00 pc 00000000000a978c  /data/app/com.example.BindTest.test-iyBWQdBs046wze2Z_WqATA==/lib/x86_64/libgojni.so (runtime.sigaction+108)
04-15 20:49:36.875  4033  4033 F DEBUG   :     #01 pc 00000000000e4432  /data/app/com.example.BindTest.test-iyBWQdBs046wze2Z_WqATA==/lib/x86_64/libgojni.so (runtime.initsig+146)
04-15 20:49:36.875  4033  4033 F DEBUG   :     #02 pc 00000000000ced96  /data/app/com.example.BindTest.test-iyBWQdBs046wze2Z_WqATA==/lib/x86_64/libgojni.so (runtime.libpreinit+22)
04-15 20:49:36.875  4033  4033 F DEBUG   :     #03 pc 00000000000fb32a  /data/app/com.example.BindTest.test-iyBWQdBs046wze2Z_WqATA==/lib/x86_64/libgojni.so (_rt0_amd64_lib+74)
04-15 20:49:36.875  4033  4033 F DEBUG   :     #04 pc 0000000000025b4f  /system/bin/linker64 (__dl__ZL10call_arrayIPFviPPcS1_EEvPKcPT_mbS5_+255)
04-15 20:49:36.875  4033  4033 F DEBUG   :     #05 pc 0000000000000000  <unknown>

I believe the crash is caused by an invalid g returned from getg, called from sigaction. At the time libpreinit is called, TLS hasn't been set up yet (it is set up later in rt0_go).

This started to appear after my fixes for #29674 but I believe it's been a latent bug for a long time. We've just been lucky that the static TLS slot previously used for accessing g on android/amd64 and android/386 always contained 0.

The cause is clear but the fix isn't obvious to me. Please advice, @cherrymui @ianlancetaylor .

@eliasnaur eliasnaur added this to the Go1.13 milestone Apr 15, 2019

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Apr 15, 2019

I assume that the problem is the call to getg in the version of sigaction in runtime/cgo_sigaction.go? I think the fix would be something like

    var g *g
    if mainStarted {
        g = getg()
    }
@gopherbot

This comment has been minimized.

Copy link

commented Apr 16, 2019

Change https://golang.org/cl/172158 mentions this issue: runtime: avoid getg in preinit on Android

@gopherbot gopherbot closed this in ae85ae5 Apr 16, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.