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/cgo: Crashing on Android Nougat due to value of PTHREAD_KEYS_MAX #19472

Closed
rayvbr opened this issue Mar 9, 2017 · 3 comments
Closed

Comments

@rayvbr
Copy link

rayvbr commented Mar 9, 2017

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.8 darwin/amd64

(Note that the actual crash occurs on Android 7.0 and higher)

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/rayvbr/Dropbox/Development/Go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/k7/jx2bs5q170z4lvdzbsdt426r0000gn/T/go-build687164964=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"

What did you do?

  • Create simple go file with main.go only including log.fmt("This is a log")
  • Compile with 'gomobile bind -target android -o test.aar'
  • Import resulting test.aart in Unity
  • Build project and run on Android 7.0 or higher

What did you expect to see?

"This is a log" being printed to console

On Android versions lower than 7.0 this works.
On Android 7.0 without using Unity, it works as well
It is only the combination of Unity and Android 7.0 and up that causes the issue below.

What did you see instead?

Crash with 'could not find pthread key'.

03-02 09:26:39.279 14186-14186/? A/DEBUG: Revision: '8'
03-02 09:26:39.279 14186-14186/? A/DEBUG: ABI: 'arm'
03-02 09:26:39.279 14186-14186/? A/DEBUG: pid: 14049, tid: 14185, name: Thread-18 >>> com.xxx.yyy <<<
03-02 09:26:39.279 14186-14186/? A/DEBUG: signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
03-02 09:26:39.289 14186-14186/? A/DEBUG: Abort message: 'could not find pthread key'
03-02 09:26:39.289 14186-14186/? A/DEBUG: r0 00000000 r1 00003769 r2 00000006 r3 00000008
03-02 09:26:39.289 14186-14186/? A/DEBUG: r4 b32fe978 r5 00000006 r6 b32fe920 r7 0000010c
03-02 09:26:39.289 14186-14186/? A/DEBUG: r8 b2ae47f0 r9 00000000 sl b2ae4280 fp b32fe82c
03-02 09:26:39.289 14186-14186/? A/DEBUG: ip 00000000 sp b32fe7a8 lr e72d9957 pc e72dc1c0 cpsr 600f0010
03-02 09:26:39.303 14186-14186/? A/DEBUG: backtrace:
03-02 09:26:39.303 14186-14186/? A/DEBUG: #00 pc 0004a1c0 /system/lib/libc.so (tgkill+12)
03-02 09:26:39.304 14186-14186/? A/DEBUG: #1 pc 00047953 /system/lib/libc.so (pthread_kill+34)
03-02 09:26:39.304 14186-14186/? A/DEBUG: #2 pc 0001d955 /system/lib/libc.so (raise+10)
03-02 09:26:39.304 14186-14186/? A/DEBUG: #3 pc 000194a1 /system/lib/libc.so (__libc_android_abort+34)
03-02 09:26:39.304 14186-14186/? A/DEBUG: #4 pc 000170e8 /system/lib/libc.so (abort+4)
03-02 09:26:39.304 14186-14186/? A/DEBUG: #5 pc 003f724c /data/app/com.xxx.yyy/lib/arm/libgojni.so (fatalf+212)
03-02 09:26:41.179 3245-3245/? E/audit: type=1701 audit(1488443201.174:997): auid=4294967295 uid=10260 gid=10260 ses=4294967295 subj=u:r:untrusted_app:s0:c512,c768 pid=14185 comm="Thread-18" exe="/system/bin/app_process32" sig=6`

Possible solution

Setting PTHREAD_KEYS_MAX in src/runtime/cgo/gcc_android_arm.c to 384 instead of 128 (and removing the surrounding #ifndef), seems to resolve the issue

@rayvbr rayvbr changed the title /runtime/cgo: Crashing on Android Nougat due PTHREAD_KEYS_MAX /runtime/cgo: Crashing on Android Nougat due to value of PTHREAD_KEYS_MAX Mar 9, 2017
@bradfitz bradfitz changed the title /runtime/cgo: Crashing on Android Nougat due to value of PTHREAD_KEYS_MAX runtime/cgo: Crashing on Android Nougat due to value of PTHREAD_KEYS_MAX Mar 9, 2017
@bradfitz bradfitz added this to the Go1.9 milestone Mar 9, 2017
@eliasnaur
Copy link
Contributor

Can you verify that https://go-review.googlesource.com/c/38636/ fixes your test case? If possible, please test both arm64 and arm.

@gopherbot
Copy link

CL https://golang.org/cl/38636 mentions this issue.

@rayvbr
Copy link
Author

rayvbr commented Mar 29, 2017

@eliasnaur I can confirm the new arm version is working. However, given that Unity only supports armv7, I haven't been able to test arm64

lparth pushed a commit to lparth/go that referenced this issue Apr 13, 2017
On Android, the thread local offset is found by looping through memory
starting at the TLS base address. The search is limited to
PTHREAD_KEYS_MAX, but issue 19472 made it clear that in some cases, the
slot is located further from the TLS base.

The limit is merely a sanity check in case our assumptions about the
thread-local storage layout are wrong, so this CL raises it to 384, which
is enough for the test case in issue 19472.

Fixes golang#19472

Change-Id: I89d1db3e9739d3a7fff5548ae487a7483c0a278a
Reviewed-on: https://go-review.googlesource.com/38636
Run-TryBot: Elias Naur <elias.naur@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
bytex64 pushed a commit to SpiderOak/go that referenced this issue Jul 12, 2017
On Android, the thread local offset is found by looping through memory
starting at the TLS base address. The search is limited to
PTHREAD_KEYS_MAX, but issue 19472 made it clear that in some cases, the
slot is located further from the TLS base.

The limit is merely a sanity check in case our assumptions about the
thread-local storage layout are wrong, so this CL raises it to 384, which
is enough for the test case in issue 19472.

Fixes golang#19472

Change-Id: I89d1db3e9739d3a7fff5548ae487a7483c0a278a
Reviewed-on: https://go-review.googlesource.com/38636
Run-TryBot: Elias Naur <elias.naur@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
@golang golang locked and limited conversation to collaborators Mar 29, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants