-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
cmd/cgo: malloc/free - deadlock on ARM #5227
Labels
Milestone
Comments
> Please add to the gdb output the back trace of the segfault (ideas and registers are > extra, backtrace is really the first thing to have). > also, its better if the code is made available somewhere. > Needs the Raspberry Pi hardware. > https://github.com/capnm/go_rpi $ git clone git://github.com/capnm/go_rpi.git && cd go_rpi $ go install -v circle $ bin/circle The back trace was not really helpful: Program received signal SIGSEGV, Segmentation fault. fast_loop () at memcpy.S:144 144 memcpy.S: No such file or directory. (gdb) bt #0 fast_loop () at memcpy.S:144 #1 0x000b5ea8 in init () #2 0xbefff5e0 in ?? () Cannot access memory at address 0x39fffff8 |
back traces from all threads: https://github.com/capnm/go_rpi/wiki/OpenVG-bindigs-or-cgo-bug |
Extracted a minimal code, it seems to be ARM specific. The first bad commit is https://code.google.com/p/go/source/detail?name=95c3a7bdfb03&r=97cbf15abc2c18b2616349d1f936cd6e7a584b76 git clone git://github.com/capnm/go_rpi.git && cd go_rpi go install issue5227 bin/issue5227 > fatal error: malloc/free - deadlock ... $cat main.go package main //#include "init.h" import "C" func main() { C.init() } func selectfont() C.Fontinfo { return C.SansTypeface } $cat init.h typedef struct { int Count; } Fontinfo; Fontinfo SansTypeface; extern void init(); cat init.c #include "init.h" Fontinfo loadfont() { Fontinfo f; return f; } void init() { SansTypeface = loadfont(); } |
single file reproducer: http://play.golang.org/p/2s-lb2fA8Q Labels changed: added priority-soon, go1.1, cgo, arch-arm, removed priority-triage. Status changed to Accepted. |
fix?: diff --git a/src/cmd/ld/go.c b/src/cmd/ld/go.c index fa2ec4e..38084ca 100644 --- a/src/cmd/ld/go.c +++ b/src/cmd/ld/go.c @@ -476,10 +476,12 @@ loadcgo(char *file, char *pkg, char *p, int n) if(strcmp(f[0], "cgo_import_static") == 0) { if(nf != 2) goto err; - local = f[1]; - s = lookup(local, 0); - s->type = SHOSTOBJ; - s->size = 0; + if(linkmode == LinkExternal) { + local = f[1]; + s = lookup(local, 0); + s->type = SHOSTOBJ; + s->size = 0; + } continue; } |
No this does not look like the correct fix, because it would break linkmode=auto. iant: I can find two possible ways of fixing: Either this: --- a/src/cmd/ld/ldelf.c Tue Apr 09 12:41:58 2013 +0900 +++ b/src/cmd/ld/ldelf.c Tue Apr 09 07:40:40 2013 +0200 @@ -571,7 +571,7 @@ s = sym.sym; if(s->size < sym.size) s->size = sym.size; - if(s->type == 0 || s->type == SXREF) + if(s->type == 0 || s->type == SXREF || s->type == SHOSTOBJ) s->type = SBSS; continue; } Or this: diff -r c40f15e9e5ca src/cmd/ld/lib.c --- a/src/cmd/ld/lib.c Tue Apr 09 12:41:58 2013 +0900 +++ b/src/cmd/ld/lib.c Tue Apr 09 07:40:40 2013 +0200 @@ -311,13 +311,14 @@ // Switch to internal. if(linkmode == LinkAuto) { linkmode = LinkInternal; - // Drop all the cgo_import_static declarations. - // Turns out we won't be needing them. - for(s = allsym; s != S; s = s->allsym) - if(s->type == SHOSTOBJ) - s->type = 0; } - + + // Drop all the cgo_import_static declarations. + // Turns out we won't be needing them. + for(s = allsym; s != S; s = s->allsym) + if(s->type == SHOSTOBJ) + s->type = 0; + // Now that we know the link mode, trim the dynexp list. x = CgoExportDynamic; if(linkmode == LinkExternal) Which one do you think is better (if any is OK at all). |
issue #5223 is the same? |
(again) issue #5233 is the same? |
issue #5233 is a memory issue, this one is a linker bug. |
There is also a cosmetic issue: the following crashy program package main /* int *foo = (int*)0; void crash() { *foo = 0; } */ import "C" func main() { defer func() { x := recover() println(x) }() C.crash() } On amd64 prints: SIGSEGV: segmentation violation PC=0x41c9aa signal arrived during cgo execution main._Cfunc_crash(0x40fd02) command-line-arguments/_obj/_cgo_defun.c:43 +0x2f main.main() command-line-arguments/_obj/main.cgo1.go:14 +0x2b goroutine 2 [syscall]: goroutine 3 [runnable]: rax 0x0 [...] On arm prints a confusing message: fatal error: malloc/free - deadlock [signal 0xb code=0x1 addr=0x2f0 pc=0x28fcc] goroutine 1 [syscall]: [fp=0xb6964f80] return() /storage/remy/go/src/pkg/runtime/asm_arm.s:275 [fp=0xb6964fa8] runtime.cgocall(0x2e1f4, 0xb6964fb8) /storage/remy/go/src/pkg/runtime/cgocall.c:162 +0xec [fp=0xb6964fb4] main._Cfunc_crash(0x22b1c) command-line-arguments/_obj/_cgo_defun.c:43 +0x30 [fp=0xb6964fb8] main.main() command-line-arguments/_obj/main.cgo1.go:14 +0x48 [fp=0xb6964fd0] runtime.main() /storage/remy/go/src/pkg/runtime/proc.c:182 +0x78 [fp=0xb6964fd4] runtime.goexit() /storage/remy/go/src/pkg/runtime/proc.c:1223 goroutine 2 [syscall]: exit status 2 |
https://golang.org/cl/8602044/ fixes issue #5114 which I believe is a duplicate of this issue. |
This issue was closed by revision 0e76a94. Status changed to Fixed. |
I'm seeing this on my amd64 ubuntu system with 58f8a30f5b78 while running all.bash: # _/home/kamil/go/misc/cgo/test issue5227.go: In function 'loadfont': issue5227.go:21:9: error: 'f.Count' is used uninitialized in this function [-Werror=uninitialized] cc1: all warnings being treated as errors FAIL _/home/kamil/go/misc/cgo/test [build failed] # _/home/kamil/go/misc/cgo/test issue5227.go: In function 'loadfont': issue5227.go:21:9: error: 'f.Count' is used uninitialized in this function [-Werror=uninitialized] cc1: all warnings being treated as errors FAIL _/home/kamil/go/misc/cgo/test [build failed] # _/home/kamil/go/misc/cgo/test issue5227.go: In function 'loadfont': issue5227.go:21:9: error: 'f.Count' is used uninitialized in this function [-Werror=uninitialized] cc1: all warnings being treated as errors FAIL _/home/kamil/go/misc/cgo/test [build failed] is this expected? |
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
by capnm9:
The text was updated successfully, but these errors were encountered: