Skip to content

runtime: TestCgoExternalThreadPanic fails on ppc64 #10410

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

Closed
davecheney opened this issue Apr 10, 2015 · 12 comments
Closed

runtime: TestCgoExternalThreadPanic fails on ppc64 #10410

davecheney opened this issue Apr 10, 2015 · 12 comments

Comments

@davecheney
Copy link
Contributor

Inadvertently broken in e8694c8

--- FAIL: TestCgoExternalThreadPanic (0.66s)
    crash_cgo_test.go:50: want failure containing "panic: BOOM". output:
        fatal error: unexpected signal during runtime execution
        [signal 0xb code=0x1 addr=0x8 pc=0x3fffae653ad0]

        runtime stack:
        runtime.throw(0xa8870, 0x2a)
            /home/ubuntu/workspace/linux-ppc64le-canonical-4b21be46701c/go/src/runtime/panic.go:543 +0x8c
        runtime.sigpanic()
            /home/ubuntu/workspace/linux-ppc64le-canonical-4b21be46701c/go/src/runtime/sigpanic_unix.go:12 +0x64

        goroutine 17 [syscall, locked to thread]:
        runtime.goexit()
            /home/ubuntu/workspace/linux-ppc64le-canonical-4b21be46701c/go/src/runtime/asm_ppc64x.s:1132 +0x4 fp=0xc208038fe0 sp=0xc208038fe0

        goroutine 1 [select (no cases)]:
        main.main()
            /tmp/go-build916459717/main.go:9 +0x28

        goroutine 18 [syscall, locked to thread]:
        runtime.goexit()
            /home/ubuntu/workspace/linux-ppc64le-canonical-4b21be46701c/go/src/runtime/asm_ppc64x.s:1132 +0x4

FAIL
FAIL    runtime 29.467s
@davecheney
Copy link
Contributor Author

/cc @spetrovic77

@davecheney davecheney added this to the Go1.5 milestone Apr 10, 2015
@spetrovic77
Copy link
Contributor

Looking at this...

@spetrovic77
Copy link
Contributor

https://go-review.googlesource.com/#/c/8766/1 will fix this test.

Dave, this seems to be a linking problem on PPC64le, please look at the CL description and tell me if you know what's going on.

@aclements
Copy link
Member

@aclements

@davecheney
Copy link
Contributor Author

I wish I knew what was going on. I agree linking is involved as there are
other tests in that file which are excluded on ppc64 due to a lack of
external linking.

On Sat, Apr 11, 2015 at 10:35 AM, Srdjan Petrovic notifications@github.com
wrote:

https://go-review.googlesource.com/#/c/8766/1 will fix this test.

Dave, this seems to be a linking problem on PPC64le, please look at the CL
description and tell me if you know what's going on.


Reply to this email directly or view it on GitHub
#10410 (comment).

crawshaw pushed a commit that referenced this issue Apr 13, 2015
Related to issue #10410

For some reason, any non-trivial code in _cgo_wait_runtime_init_done
(even fprintf()) will crash that call.

If anybody has any guess why this is happening, please let me know!

For now, I'm clearing the functions for ppc64, as it's currently not used.

Change-Id: I1b11383aaf4f9f9a16f1fd6606842cfeedc9f0b3
Reviewed-on: https://go-review.googlesource.com/8766
Reviewed-by: David Crawshaw <crawshaw@golang.org>
Run-TryBot: Srdjan Petrovic <spetrovic@google.com>
@spetrovic77
Copy link
Contributor

The build failure is fixed, but the question on why the test has failed still remains. Here is the simplest code that demonstrates the failure (before CL 8766).

package main

// void gopanic(void);
//
// static void start(void) {
// gopanic();
// }
import "C"

//export gopanic
func gopanic() {
panic("BOOM")
}

func main() {
C.start()
}

The failure occurs when start() invokes gopanic(), in the _cgo_wait_runtime_init_done() call. If _cgo_wait_runtime_init_done() is non-empty (say, fprintf is added to it), it will fail.

@ianlancetaylor
Copy link
Member

The PPC ELF v2 ABI requires that every function start with a small prologue that computes the TOC pointer in r2 from the function address in r12. This computation is two instructions; in normal PPC assembler it looks like this:

0: addis 2,12,.TOC.-0b@ha
addi 2,2,.TOC.-0b@l

The symbol .TOC. is not defined in an object file, and is magically defined by the linker. The linker must arrange that every function in the same module (shared library or executable) compute the same value for r2.

The problem here is that 9l is using a different value for .TOC. for functions defined in different object files. I haven't sorted it all out, but 9l seems to use a different .TOC. symbol for each object file, and to give them different values. This may be correct for the ELF v1 ABI; I'm not sure. It's not correct for the ELF v2 ABI used on PPC64le.

The different TOC value causes some calls to pthread_mutex_lock to load the wrong value from the GOT and branch to the wrong function, leading to a crash.

I hope somebody else can take it from here.

@rsc rsc modified the milestones: Go1.6Early, Go1.5 Jul 21, 2015
@mwhudson
Copy link
Contributor

Ah, I recently found the same cmd/link (nee 9l) behaviour around using a different .TOC. for each object file that Ian refers to and was very confused by it. Glad to hear Ian thinks it's wrong too :-)

External linking will fix this though.

@rsc
Copy link
Contributor

rsc commented Dec 5, 2015

We're not going to make it to Go 1.6 for ppc64 external linking.

@rsc rsc modified the milestones: Unplanned, Go1.6Early Dec 5, 2015
@ianlancetaylor
Copy link
Member

Has this problem been fixed by the use of external linking? If we drop runtime/cgo/gcc_libint_linux_ppc64x.c and simply use runtime/cgo/gcc_libint.c on linux-ppc64 and linux-ppc64le, do all the tests pass?

CC @spetrovic77 @laboger

@laboger
Copy link
Contributor

laboger commented Apr 22, 2016

This testcase worked for me on master latest on an Ubuntu system and RHEL 7.2 ppc64le.
The intent of this issue is not ppc64 BE, is it? The title says ppc64 but the first stack trace posted shows ppc64le.

./runtime.test -test.run=TestCgoExternalThreadPanic -test.v
=== RUN TestCgoExternalThreadPanic
--- PASS: TestCgoExternalThreadPanic (1.15s)
PASS

go version devel +1492e7d Fri Apr 22 10:08:05 2016 +0000 linux/ppc64le

@ianlancetaylor
Copy link
Member

I think this issue was ppc64le specific, because it was due to ELF ABI v2. I sent a CL.

@golang golang locked and limited conversation to collaborators Apr 22, 2017
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

8 participants