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: Crash on package init with fatal error: bad pointer in write barrier #15831

Closed
balboah opened this issue May 25, 2016 · 6 comments

Comments

Projects
None yet
4 participants
@balboah
Copy link

commented May 25, 2016

  1. What version of Go are you using (go version)?
    1.6.2
  2. What operating system and processor architecture are you using (go env)?
    Was built for android arm using go 1.6.2 and gomobile githash c435d0b.
  3. What did you do?

When java loads the go library, it caused a crash:

                          Go  E  runtime: writebarrierptr *0x67a39d4c = 0x68686868
05-11 09:51:19.314   8537     8606                               Go  E  fatal error: bad pointer in write barrier
05-11 09:51:19.324   8537     8606                               Go  E  runtime stack:
05-11 09:51:19.324   8537     8606                               Go  E  runtime.throw(0x571ac710, 0x1c)
05-11 09:51:19.324   8537     8606                               Go  E  /usr/local/Cellar/go/1.6.2/libexec/src/runtime/panic.go:547 +0x80
05-11 09:51:19.324   8537     8606                               Go  E  runtime.writebarrierptr.func1()
05-11 09:51:19.324   8537     8606                               Go  E  /usr/local/Cellar/go/1.6.2/libexec/src/runtime/mbarrier.go:140 +0xb4
05-11 09:51:19.324   8537     8606                               Go  E  runtime.systemstack(0x57373800)
05-11 09:51:19.324   8537     8606                               Go  E  /usr/local/Cellar/go/1.6.2/libexec/src/runtime/asm_arm.s:247 +0x8c
05-11 09:51:19.324   8537     8606                               Go  E  runtime.mstart()
05-11 09:51:19.324   8537     8606                               Go  E  /usr/local/Cellar/go/1.6.2/libexec/src/runtime/proc.go:1051
05-11 09:51:19.324   8537     8606                               Go  E  goroutine 1 [running, locked to thread]:
05-11 09:51:19.324   8537     8606                               Go  E  runtime.systemstack_switch()
05-11 09:51:19.324   8537     8606                               Go  E  /usr/local/Cellar/go/1.6.2/libexec/src/runtime/asm_arm.s:192 +0x4 fp=0x67a39c54 sp=0x67a39c50
05-11 09:51:19.324   8537     8606                               Go  E  runtime.writebarrierptr(0x67a39d4c, 0x68686868)
05-11 09:51:19.324   8537     8606                               Go  E  /usr/local/Cellar/go/1.6.2/libexec/src/runtime/mbarrier.go:141 +0xa4 fp=0x67a39c6c sp=0x67a39c54
05-11 09:51:19.324   8537     8606                               Go  E  github.com/google/gopacket/layers.init.1()
05-11 09:51:19.324   8537     8606                               Go  E  /Users/kargs/code/go/src/github.com/google/gopacket/layers/enums.go:381 +0x4dc fp=0x67a39e70 sp=0x67a39c6c
05-11 09:51:19.324   8537     8606                               Go  E  github.com/google/gopacket/layers.init()
05-11 09:51:19.324   8537     8606                               Go  E  /Users/kargs/code/go/src/github.com/google/gopacket/layers/usb.go:308 +0x74c8 fp=0x67a39f4c sp=0x67a39e70
05-11 09:51:19.324   8537     8606                               Go  E  github.com/thisisnotourname/android-lib/go/router.init()
05-11 09:51:19.324   8537     8606                               Go  E  /Users/kargs/code/go/src/github.com/thisisnotourname/android-lib/go/router/table.go:540 +0x74 fp=0x67a39f84 sp=0x67a39f4c
05-11 09:51:19.324   8537     8606                               Go  E  github.com/thisisnotourname/android-lib/go/control.init()
05-11 09:51:19.324   8537     8606                               Go  E  /Users/kargs/code/go/src/github.com/thisisnotourname/android-lib/go/control/time.go:10 +0xd0 fp=0x67a39f98 sp=0x67a39f84
05-11 09:51:19.324   8537     8606                               Go  E  github.com/thisisnotourname/android-lib/go/api.init()
05-11 09:51:19.324   8537     8606                               Go  E  /Users/kargs/code/go/src/github.com/thisisnotourname/android-lib/go/api/jsonagents.go:82 +0x64 fp=0x67a39f9c sp=0x67a39f98
05-11 09:51:19.324   8537     8606                               Go  E  _/var/folders/yn/q2mv635j31n0xrzmymdzgcjr0000gn/T/gomobile-work-814562066/gomobile_bind.init()
05-11 09:51:19.324   8537     8606                               Go  E  _/var/folders/yn/q2mv635j31n0xrzmymdzgcjr0000gn/T/gomobile-work-814562066/gomobile_bind/_obj/_cgo_import.go:1 +0x5c fp=0x67a39fa0 sp=0x67a39f9c
05-11 09:51:19.324   8537     8606                               Go  E  main.init()
05-11 09:51:19.324   8537     8606                               Go  E  /var/folders/yn/q2mv635j31n0xrzmymdzgcjr0000gn/T/gomobile-work-814562066/androidlib/main.go:9 +0x5c fp=0x67a39fa4 sp=0x67a39fa0
05-11 09:51:19.324   8537     8606                               Go  E  runtime.main()
05-11 09:51:19.324   8537     8606                               Go  E  /usr/local/Cellar/go/1.6.2/libexec/src/runtime/proc.go:177 +0x2dc fp=0x67a39fcc sp=0x67a39fa4
05-11 09:51:19.324   8537     8606                               Go  E  runtime.goexit()
05-11 09:51:19.324   8537     8606                               Go  E  /usr/local/Cellar/go/1.6.2/libexec/src/runtime/asm_arm.s:990 +0x4 fp=0x67a39fcc sp=0x67a39fcc
05-11 09:51:19.324   8537     8606                               Go  E  goroutine 17 [chan receive, locked to thread]:
05-11 09:51:19.324   8537     8606                               Go  E  runtime.gopark(0x571f39cc, 0x67a5a070, 0x5717ffb0, 0xc, 0x17, 0x3)
05-11 09:51:19.324   8537     8606                               Go  E  /usr/local/Cellar/go/1.6.2/libexec/src/runtime/proc.go:262 +0x15c
05-11 09:51:19.324   8537     8606                               Go  E  runtime.goparkunlock(0x67a5a070, 0x5717ffb0, 0xc, 0x17, 0x3)
05-11 09:51:19.324   8537     8606                               Go  E  /usr/local/Cellar/go/1.6.2/libexec/src/runtime/proc.go:268 +0x48
05-11 09:51:19.324   8537     8606                               Go  E  runtime.chanrecv(0x57069e40, 0x67a5a040, 0x0, 0x1, 0x56c00000)
05-11 09:51:19.324   8537     8606                               Go  E  /usr/local/Cellar/go/1.6.2/libexec/src/runtime/chan.go:470 +0x538
05-11 09:51:19.324   8537     8606                               Go  E  runtime.chanrecv1(0x57069e40, 0x67a5a040, 0x0)
05-11 09:51:19.324   8537     8606                               Go  E  /usr/local/Cellar/go/1.6.2/libexec/src/runtime/chan.go:355 +0x28
05-11 09:51:19.324   8537     8606                               Go  E  runtime.cgocallbackg1()
05-11 09:51:19.324   8537     8606                               Go  E  /usr/local/Cellar/go/1.6.2/libexec/src/runtime/cgocall.go:199 +0x88
05-11 09:51:19.324   8537     8606                               Go  E  runtime.cgocallbackg()
05-11 09:51:19.324   8537     8606                               Go  E  /usr/local/Cellar/go/1.6.2/libexec/src/runtime/cgocall.go:180 +0xb0
05-11 09:51:19.324   8537     8606                               Go  E  runtime.cgocallback_gofunc(0x0, 0x0, 0x0)
05-11 09:51:19.324   8537     8606                               Go  E  /usr/local/Cellar/go/1.6.2/libexec/src/runtime/asm_arm.s:621 +0x58
05-11 09:51:19.324   8537     8606                               Go  E  runtime.goexit()
05-11 09:51:19.324   8537     8606                               Go  E  /usr/local/Cellar/go/1.6.2/libexec/src/runtime/asm_arm.s:990 +0x4
05-11 09:51:19.324   8537     8606                               Go  E  goroutine 18 [syscall, locked to thread]:
05-11 09:51:19.324   8537     8606                               Go  E  runtime.goexit()
05-11 09:51:19.324   8537     8606                               Go  E  /usr/local/Cellar/go/1.6.2/libexec/src/runtime/asm_arm.s:990 +0x4
05-11 09:51:19.324   8537     8606                               Go  E  goroutine 5 [syscall]:
05-11 09:51:19.324   8537     8606                               Go  E  syscall.Syscall(0x3, 0x56, 0x67a88000, 0x400, 0x0, 0x0, 0x0)
05-11 09:51:19.324   8537     8606                               Go  E  /usr/local/Cellar/go/1.6.2/libexec/src/syscall/asm_linux_arm.s:17 +0x8
05-11 09:51:19.324   8537     8606                               Go  E  syscall.read(0x56, 0x67a88000, 0x400, 0x400, 0x0, 0x0, 0x0)
05-11 09:51:19.324   8537     8606                               Go  E  /usr/local/Cellar/go/1.6.2/libexec/src/syscall/zsyscall_linux_arm.go:783 +0x78
05-11 09:51:19.324   8537     8606                               Go  E  syscall.Read(0x56, 0x67a88000, 0x400, 0x400, 0x0, 0x0, 0x0)
05-11 09:51:19.324   8537     8606                               Go  E  /usr/local/Cellar/go/1.6.2/libexec/src/syscall/syscall_unix.go:161 +0x4c
05-11 09:51:19.324   8537     8606                               Go  E  os.(*File).read(0x67a20160, 0x67a88000, 0x400, 0x400, 0x0, 0x0, 0x0)
05-11 09:51:19.324   8537     8606                               Go  E  /usr/local/Cellar/go/1.6.2/libexec/src/os/file_unix.go:228 +0x54
05-11 09:51:19.324   8537     8606                               Go  E  os.(*File).Read(0x67a20160, 0x67a88000, 0x400, 0x400, 0x67a88000, 0x0, 0x0)
05-11 09:51:19.324   8537     8606                               Go  E  /usr/local/Cellar/go/1.6.2/libexec/src/os/file.go:95 +0x84
05-11 09:51:19.324   8537     8606                               Go  E  bufio.(*Reader).fill(0x67a29f7c)
05-11 09:51:19.324   8537     8606                               Go  E  /usr/local/Cellar/go/1.6.2/libexec/src/bufio/bufio.go:97 +0x1cc
05-11 09:51:19.324   8537     8606                               Go  E  bufio.(*Reader).ReadSlice(0x67a29f7c, 0x56c14a0a, 0x0, 0x0, 0x0, 0x0, 0x0)
05-11 09:51:19.324   8537     8606                               Go  E  /usr/local/Cellar/go/1.6.2/libexec/src/bufio/bufio.go:328 +0x26c
05-11 09:51:19.324   8537     8606                               Go  E  bufio.(*Reader).ReadLine(0x67a29f7c, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
05-11 09:51:19.324   8537     8606                               Go  E  /usr/local/Cellar/go/1.6.2/libexec/src/bufio/bufio.go:357 +0x60
05-11 09:51:19.324   8537     8606                               Go  E  golang.org/x/mobile/internal/mobileinit.lineLog(0x67a20160, 0x6)
05-11 09:51:19.324   8537     8606                               Go  E  /Users/kargs/code/go/src/golang.org/x/mobile/internal/mobileinit/mobileinit_android.go:50 +0xf4
05-11 09:51:19.324   8537     8606                               Go  E  created by golang.org/x/mobile/internal/mobileinit.init.1
05-11 09:51:19.324   8537     8606                               Go  E  /Users/kargs/code/go/src/golang.org/x/mobile/internal/mobileinit/mobileinit_android.go:74 +0x11c
05-11 09:51:19.324   8537     8606                               Go  E  goroutine 6 [syscall]:
05-11 09:51:19.324   8537     8606                               Go  E  syscall.Syscall(0x3, 0x61, 0x67a88400, 0x400, 0x0, 0x0, 0x0)
05-11 09:51:19.324   8537     8606                               Go  E  /usr/local/Cellar/go/1.6.2/libexec/src/syscall/asm_linux_arm.s:17 +0x8
05-11 09:51:19.324   8537     8606                               Go  E  syscall.read(0x61, 0x67a88400, 0x400, 0x400, 0x0, 0x0, 0x0)
05-11 09:51:19.324   8537     8606                               Go  E  /usr/local/Cellar/go/1.6.2/libexec/src/syscall/zsyscall_linux_arm.go:783 +0x78
05-11 09:51:19.324   8537     8606                               Go  E  syscall.Read(0x61, 0x67a88400, 0x400, 0x400, 0x0, 0x0, 0x0)
05-11 09:51:19.324   8537     8606                               Go  E  /usr/local/Cellar/go/1.6.2/libexec/src/syscall/syscall_unix.go:161 +0x4c
05-11 09:51:19.324   8537     8606                               Go  E  os.(*File).read(0x67a20170, 0x67a88400, 0x400, 0x400, 0x0, 0x0, 0x0)
05-11 09:51:19.324   8537     8606                               Go  E  /usr/local/Cellar/go/1.6.2/libexec/src/os/file_unix.go:228 +0x54
05-11 09:51:19.324   8537     8606                               Go  E  os.(*File).Read(0x67a20170, 0x67a88400, 0x400, 0x400, 0x67a88400, 0x0, 0x0)
05-11 09:51:19.324   8537     8606                               Go  E  /usr/local/Cellar/go/1.6.2/libexec/src/os/file.go:95 +0x84
05-11 09:51:19.324   8537     8606                               Go  E  bufio.(*Reader).fill(0x67a2a77c)
05-11 09:51:19.324   8537     8606                               Go  E  /usr/local/Cellar/go/1.6.2/libexec/src/bufio/bufio.go:97 +0x1cc
05-11 09:51:19.324   8537     8606                               Go  E  bufio.(*Reader).ReadSlice(0x67a2a77c, 0x56c14a0a, 0x0, 0x0, 0x0, 0x0, 0x0)
05-11 09:51:19.324   8537     8606                               Go  E  /usr/local/Cellar/go/1.6.2/libexec/src/bufio/bufio.go:328 +0x26c
05-11 09:51:19.324   8537     8606                               Go  E  bufio.(*Reader).ReadLine(0x67a2a77c, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
05-11 09:51:19.324   8537     8606                               Go  E  /usr/local/Cellar/go/1.6.2/libexec/src/bufio/bufio.go:357 +0x60
05-11 09:51:19.324   8537     8606                               Go  E  golang.org/x/mobile/internal/mobileinit.lineLog(0x67a20170, 0x4)
05-11 09:51:19.324   8537     8606                               Go  E  /Users/kargs/code/go/src/golang.org/x/mobile/internal/mobileinit/mobileinit_android.go:50 +0xf4
05-11 09:51:19.324   8537     8606                               Go  E  created by golang.org/x/mobile/internal/mobileinit.init.1
05-11 09:51:19.324   8537     8606                               Go  E  /Users/kargs/code/go/src/golang.org/x/mobile/internal/mobileinit/mobileinit_android.go:81 +0x1b8

The only init() that actually seem to do something is gopacket enums

Unfortunately it has only happened occasionally and I don't know how to reproduce it.
The specific android device in question that it happened on is SM-G355H

I believe this is related to #11689

@balboah balboah changed the title Gomobile: Crash on package init with fatal error: bad pointer in write barrier mobile: Crash on package init with fatal error: bad pointer in write barrier Jun 1, 2016

@quentinmit

This comment has been minimized.

Copy link
Contributor

commented Jun 17, 2016

/cc @aclements @rsc

Write barriers sound like your territory :)

@balboah Can you try 1.7 (either from master or from the latest beta/rc) and see if the crash occurs again? I know there have been some changes here in 1.7

@quentinmit quentinmit added this to the Go1.8 milestone Jun 17, 2016

@mikioh mikioh changed the title mobile: Crash on package init with fatal error: bad pointer in write barrier runtime: Crash on package init with fatal error: bad pointer in write barrier Jun 17, 2016

@balboah

This comment has been minimized.

Copy link
Author

commented Jun 17, 2016

@quentinmit I have only seen this crash once, and I don't know how to reproduce it. But I will use 1.7 once its released :)

@aclements

This comment has been minimized.

Copy link
Member

commented Jun 17, 2016

/cc @RLH, since this is also his territory, and I'll be out of town next week.

@balboah, which revision of github.com/google/gopacket are you at? (Specifically, I need to know what github.com/google/gopacket/layers/enums.go:381 refers to, since that line at HEAD clearly doesn't have any write barriers.)

It might also be relevant what revision of github.com/thisisnotourname/android-lib you're at.

@balboah

This comment has been minimized.

Copy link
Author

commented Jun 17, 2016

@aclements I believe I linked to the actual hash path on github, my Godep says 1b0b789. The android-lib is private unfortunately but there are no magic init going on that I could see

@aclements

This comment has been minimized.

Copy link
Member

commented Jun 17, 2016

Thanks, that revision does have a write barrier on line 381 (for my future reference: this line), which happens when writing the value part from the interface returned by convT2E for the i argument to fmt.Sprintf into the argument slice for fmt.Sprintf. (Which is a little weird since the slice is on the stack, but I guess we lost track of that.) Hence the bad 0x68686868 pointer presumably came from convT2E. How that happened, I'm not sure. The convT2E call is, roughly, convT2E(type.int, i, nil), so the value should have been allocated via newobject.

What do you mean by there being no "magic init" in android-lib?

@aclements

This comment has been minimized.

Copy link
Member

commented Jun 17, 2016

Oh! 0x68686868 is a very specific "bad" pointer. That's the poisonStack value on 32-bit. I bet you just got unlucky and genuinely allocated something at that address. As far as I can tell, there's nothing preventing that from happening.

We haven't actually used poisonStack since April 2015, when we switched to 1-bit bitmaps for the stack (and lost the information we would need to poison the stack). I'm not sure if something used to prevent us from legitimately allocating at that address.

We should probably just remove poisonStack and the checks against that pointer.

@aclements aclements modified the milestones: Go1.7, Go1.8 Jun 17, 2016

@gopherbot gopherbot closed this in 9e8fa1e Jun 17, 2016

@golang golang locked and limited conversation to collaborators Jun 17, 2017

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