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

x/mobile libc : SIGABRT crash on the Genymotion Android emulator #29249

Open
llgoer opened this issue Dec 14, 2018 · 16 comments

Comments

@llgoer
Copy link

commented Dec 14, 2018

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

$ go version
go version go1.11.2 darwin/amd64

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/llgoer/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/llgoer/Projects/Go"
GOPROXY=""
GORACE=""
GOROOT="/Users/llgoer/Documents/go"
GOTMPDIR=""
GOTOOLDIR="/Users/llgoer/Documents/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/z1/j2_yz_zx4p58d3s8r7p75brh0000gn/T/go-build299331708=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

https://github.com/golang/go/wiki/Mobile#building-and-deploying-to-android-1

$ gomobile bind -o app/hello.aar -target=android golang.org/x/mobile/example/bind/hello

What did you expect to see?

say hello.it run successfull on aarch64,but failed on x86.

What did you see instead?

12-13 21:26:00.868  4298  4402 F libc    : Fatal signal 6 (SIGABRT), code -6 in tid 4402 (mqt_native_modu)
12-13 21:26:00.972   262   262 F DEBUG   : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
12-13 21:26:00.972   262   262 F DEBUG   : Build fingerprint: 'Android/vbox86p/vbox86p:6.0/MRA58K/91:userdebug/test-keys'
12-13 21:26:00.972   262   262 F DEBUG   : Revision: '0'
12-13 21:26:00.972   262   262 F DEBUG   : ABI: 'x86'
12-13 21:26:00.972   262   262 F DEBUG   : pid: 4298, tid: 4402, name: mqt_native_modu  >>> com.myapp <<<
12-13 21:26:00.972   262   262 F DEBUG   : signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
12-13 21:26:00.980   262   262 F DEBUG   :     eax 00000000  ebx 000010ca  ecx 00001132  edx 00000006
12-13 21:26:00.980   262   262 F DEBUG   :     esi d844a980  edi 00000000
12-13 21:26:00.980   262   262 F DEBUG   :     xcs 00000023  xds 0000002b  xes 0000002b  xfs 000000cf  xss 0000002b
12-13 21:26:00.980   262   262 F DEBUG   :     eip f73c06c6  ebp 00001132  esp d844a520  flags 00200206
12-13 21:26:00.981   262   262 F DEBUG   : 
12-13 21:26:00.981   262   262 F DEBUG   : backtrace:
12-13 21:26:00.982   262   262 F DEBUG   :     #00 pc 000836c6  /system/lib/libc.so (tgkill+22)
12-13 21:26:00.982   262   262 F DEBUG   :     #01 pc 00081728  /system/lib/libc.so (pthread_kill+70)
12-13 21:26:00.982   262   262 F DEBUG   :     #02 pc 00027255  /system/lib/libc.so (raise+36)
12-13 21:26:00.983   262   262 F DEBUG   :     #03 pc 00020a34  /system/lib/libc.so (abort+80)
12-13 21:26:00.983   262   262 F DEBUG   :     #04 pc 001e3a69  /data/app/com.myapp-2/lib/x86/libgojni.so
12-13 21:26:00.984   262   262 F DEBUG   :     #05 pc 001e3f52  /data/app/com.myapp-2/lib/x86/libgojni.so (x_cgo_init+98)
12-13 21:26:00.984   262   262 F DEBUG   :     #06 pc 000a2941  /data/app/com.myapp-2/lib/x86/libgojni.so
12-13 21:26:00.985   262   262 F DEBUG   :     #07 pc 000fd84f  [stack:4402]
12-13 21:26:01.176   262   262 F DEBUG   : 
12-13 21:26:01.176   262   262 F DEBUG   : Tombstone written to: /data/tombstones/tombstone_04
12-13 21:26:01.176  1661  4407 W ActivityManager:   Force finishing activity com.myapp/.MainActivity
12-13 21:26:01.176   262   262 E DEBUG   : AM write failed: Broken pipe
12-13 21:26:01.177  1661  1678 I BootReceiver: Copying /data/tombstones/tombstone_04 to DropBox (SYSTEM_TOMBSTONE)
12-13 21:26:01.188  1661  4407 D         : HostConnection::get() New Host Connection established 0xdc957500, tid 4407
12-13 21:26:01.213  1661  1715 W InputDispatcher: channel 'f8991cc com.myapp/com.myapp.MainActivity (server)' ~ Consumer closed input channel or an error occurred.  events=0x9
12-13 21:26:01.214  1661  1715 E InputDispatcher: channel 'f8991cc com.myapp/com.myapp.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
12-13 21:26:01.215  1655  1655 I Zygote  : Process 4298 exited due to signal (6)
12-13 21:26:01.244  1661  2073 D GraphicsStats: Buffer count: 5

@gopherbot gopherbot added this to the Unreleased milestone Dec 14, 2018

@gopherbot gopherbot added the mobile label Dec 14, 2018

@agnivade

This comment has been minimized.

Copy link
Member

commented Dec 14, 2018

@eliasnaur

This comment has been minimized.

Copy link
Contributor

commented Dec 14, 2018

Which device is the crash from? Does gomobile bind -target android/amd64 ... work on the device?

@llgoer

This comment has been minimized.

Copy link
Author

commented Dec 17, 2018

@eliasnaur Genymotion Android Emulator

@eliasnaur eliasnaur changed the title x/mobile libc : Fatal signal 6 (SIGABRT), code -6 in tid 4402 (mqt_native_modu) x/mobile libc : SIGABRT crash on the Genymotion Android emulator Dec 17, 2018

@eliasnaur

This comment has been minimized.

Copy link
Contributor

commented Dec 17, 2018

I see. The problem is probably that the Genymotion emulator has a different setup for thread local variables (TLS) than the official emulator and Android devices. If so, the abort comes from

if(ntofree >= nelem(tofree)) {
fprintf(stderr, "runtime/cgo: could not obtain pthread_keys\n");
fprintf(stderr, "\ttried");
for(i=0; i<ntofree; i++)
fprintf(stderr, " %#x", (unsigned)tofree[i]);
fprintf(stderr, "\n");
abort();
}
. Did you see the accompanying message ("runtime/cgo: could not obtain pthread_keys")? If so, you could try to increase the constant 128 at the line
pthread_key_t tofree[128], k;
. Try 384; that's what Go does on arm64 and arm.

Go's use of TLS on Android is an awful hack and there are efforts underway to remedy the situation: https://groups.google.com/forum/#!topic/golang-dev/yVrkFnYrYPE.

@llgoer

This comment has been minimized.

Copy link
Author

commented Dec 20, 2018

will this error fix after go 1.12 released?

@eliasnaur

This comment has been minimized.

Copy link
Contributor

commented Dec 20, 2018

Not yet. I suggested a change you could try to apply and see if that fixes the crash.

@mandrigin

This comment has been minimized.

Copy link

commented Feb 12, 2019

@eliasnaur we have (as I expect) the same issue on Genymotion on Android 7.0 and 7.1

02-12 09:07:37.325  2447  2482 D StatusNativeLogs: runtime/cgo: pthread_key_create failed
02-12 09:07:37.325  2447  2500 F libc    : Fatal signal 6 (SIGABRT), code -6 in tid 2500 (mqt_native_modu)
02-12 09:07:37.325   123   123 W         : debuggerd: handling request: pid=2447 uid=10063 gid=10063 tid=2500
02-12 09:07:37.396  2501  2501 F DEBUG   : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
02-12 09:07:37.396  2501  2501 F DEBUG   : Build fingerprint: 'Android/vbox86p/vbox86p:7.0/NRD90M/91:userdebug/test-keys'
02-12 09:07:37.396  2501  2501 F DEBUG   : Revision: '0'
02-12 09:07:37.396  2501  2501 F DEBUG   : ABI: 'x86'
02-12 09:07:37.396  2501  2501 F DEBUG   : pid: 2447, tid: 2500, name: mqt_native_modu  >>> im.status.ethereum.debug <<<
02-12 09:07:37.396  2501  2501 F DEBUG   : signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
02-12 09:07:37.396  2501  2501 F DEBUG   :     eax 00000000  ebx 0000098f  ecx 000009c4  edx 00000006
02-12 09:07:37.396  2501  2501 F DEBUG   :     esi cc985978  edi cc985920
02-12 09:07:37.396  2501  2501 F DEBUG   :     xcs 00000023  xds 0000002b  xes 0000002b  xfs 0000006b  xss 0000002b
02-12 09:07:37.396  2501  2501 F DEBUG   :     eip f1df1bb9  ebp cc985538  esp cc9854dc  flags 00200292
02-12 09:07:37.397  2501  2501 F DEBUG   :
02-12 09:07:37.397  2501  2501 F DEBUG   : backtrace:
02-12 09:07:37.397  2501  2501 F DEBUG   :     #00 pc 00000bb9  [vdso:f1df1000] (__kernel_vsyscall+9)
02-12 09:07:37.397  2501  2501 F DEBUG   :     #01 pc 0007a2ec  /system/lib/libc.so (tgkill+28)
02-12 09:07:37.397  2501  2501 F DEBUG   :     #02 pc 00075b35  /system/lib/libc.so (pthread_kill+85)
02-12 09:07:37.397  2501  2501 F DEBUG   :     #03 pc 0002784a  /system/lib/libc.so (raise+42)
02-12 09:07:37.397  2501  2501 F DEBUG   :     #04 pc 0001ee26  /system/lib/libc.so (abort+86)
02-12 09:07:37.397  2501  2501 F DEBUG   :     #05 pc 00b4ad45  /data/app/im.status.ethereum.debug-1/lib/x86/libgojni.so
@mandrigin

This comment has been minimized.

Copy link

commented Feb 12, 2019

also, it is in gcc_android_386.c there, not 64 bits.

@mandrigin

This comment has been minimized.

Copy link

commented Feb 12, 2019

and it actually returns EAGAIN (11) if my logging is correct.

@eliasnaur

This comment has been minimized.

Copy link
Contributor

commented Feb 12, 2019

Did you try increasing the size to 384 as I suggested in #29249 (comment)?

The proper fix is probably the same as for #29674.

@mandrigin

This comment has been minimized.

Copy link

commented Feb 12, 2019

yep, still fails. I added some logs will rebuild everything and get back to you!

@mandrigin

This comment has been minimized.

Copy link

commented Feb 12, 2019

it always failes on 115th iteration for me: runtime/cgo: (iteration 114) (gcc_android_i386) pthread_key_create failed 11

@mandrigin

This comment has been minimized.

Copy link

commented Feb 12, 2019

PTHREAD_KEYS_MAX is defined as 128 on this particular platform. It looks like that limits the number of "tries" there.

@eliasnaur

This comment has been minimized.

Copy link
Contributor

commented Feb 12, 2019

That's too bad. I suppose the fix will have to wait for #29674.

@gopherbot

This comment has been minimized.

Copy link

commented Mar 28, 2019

Change https://golang.org/cl/169817 mentions this issue: cmd/link/ld,cmd/internal/obj,runtime: make the Android TLS offset dynamic

@eliasnaur

This comment has been minimized.

Copy link
Contributor

commented Mar 29, 2019

@llgoer @mandrigin if you can, please test CL 169817 above and see if it fixes the crash. If so, you can close this issue.

gopherbot pushed a commit that referenced this issue Mar 29, 2019
cmd/link/ld,cmd/internal/obj,runtime: make the Android TLS offset dyn…
…amic

We're going to need a different TLS offset for Android Q, so the static
offsets used for 386 and amd64 are no longer viable on Android.

Introduce runtime·tls_g and use that for indexing into TLS storage. As
an added benefit, we can then merge the TLS setup code for all android
GOARCHs.

While we're at it, remove a bunch of android special cases no longer
needed.

Updates #29674
Updates #29249 (perhaps fixes it)

Change-Id: I77c7385aec7de8f1f6a4da7c9c79999157e39572
Reviewed-on: https://go-review.googlesource.com/c/go/+/169817
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.