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

cmd/cgo: SIGSEGV using C++ files in package on Darwin #5629

Closed
sbinet opened this issue Jun 4, 2013 · 12 comments

Comments

@sbinet
Copy link
Member

commented Jun 4, 2013

hi,

I tried the new C++ support of CGo from https://golang.org/cl/8248043/

unfortunately, there are a few shortcomings:
on linux (archlinux kernel-3.9.2, gcc-4.8.1), one has to explicitly add -lstdc++ to:
//#cgo LDFLAGS: -lstdc++

and, on darwin, the following compiles:
//#cgo LDFLAGS: -static-libstdc++

but segfaults at runtime:
SIGSEGV: segmentation violation
PC=0x7fff8147568a
signal arrived during cgo execution

ttt._Cfunc_MyPrint(0xc0bc0)
    ttt/_obj/_cgo_defun.c:44 +0x2f
ttt.T()
    ttt/_obj/ttt.cgo1.go:15 +0x45
main.main()
    /Users/binet/dev/hg-go/gopath/src/ttt/ttt-run/run.go:10 +0x18

$ gdb ttt-run
(gdb) run
Starting program: /Users/binet/dev/hg-go/gopath/bin/ttt-run 
Reading symbols for shared libraries ++. done
foo

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0xffffffffffffffe8
0x00007fff8147568a in std::ostream::sentry::sentry ()
(gdb) bt
#0  0x00007fff8147568a in std::ostream::sentry::sentry ()
#1  0x00007fff81475b0d in std::__ostream_insert<char, std::char_traits<char>
> ()
Die: DW_TAG_unspecified_type (abbrev = 10, offset = 144)
    has children: FALSE
    attributes:
        DW_AT_name (DW_FORM_string) string: "<unspecified>"
Dwarf Error: Cannot find type of die [in module
/Users/binet/dev/hg-go/gopath/bin/ttt-run]

to reproduce:

mkdir -p $GOPATH/src/ttt
cd $GOPATH/src/ttt
cat >| ttt.go << EOF
package ttt

// #include "ttt.h"
// #cgo LDFLAGS: -static-libstdc++
import "C"

import "fmt"

func T() {
 fmt.Printf("foo\n")
 C.MyPrint()
}
EOF

cat >| ttt.h << EOF
#ifndef TTT_TTT_H
#define TTT_TTT_H 1

#ifdef __cplusplus
extern "C" {
#endif

void MyPrint(void);

#ifdef __cplusplus
}
#endif

#endif /* !TTT_TTT_H */
EOF

cat >| ttt.cxx << EOF
#include "ttt.h"
#include <iostream>

extern "C" {
void MyPrint() {
  std::cout << "hello from c++" << std::endl;
}
}
EOF

and finally, a simple go-executable:
cat >| run.go << EOF
package main

import "ttt"

func main() {
 ttt.T()
}
EOF

The expected outcome of running that executable should be:
$ go run run.go
foo
hello from c++

===
$ go version
go version devel +103cf9db59e1 Mon Jun 03 11:52:36 2013 +1000 darwin/amd64

parting notes:
I suppose the code in cmd/go/build.go should also detect libstdc++.a (on linux; on
darwin that's spelled libstdc++-static.a IIRC) in the same fashion than for libgcc.a.

the attached tar-ball contains the code snippets above (but sans the -static-libstdc++
bits)

hth,
-s

Attachments:

  1. ttt.tar.gz (563 bytes)
@rsc

This comment has been minimized.

Copy link
Contributor

commented Jun 14, 2013

Comment 1:

Labels changed: added priority-later, go1.2, removed priority-triage.

Status changed to Accepted.

@lukescott

This comment has been minimized.

Copy link

commented Aug 16, 2013

Comment 2:

This doesn't work for me on Darwin (Mac):
// #cgo LDFLAGS: -static-libstdc++
But this does:
// #cgo LDFLAGS: -lstdc++
When I run the program it runs fine. I don't get a segfault. I'm running:
go version devel +49d897ab8e2f Fri Aug 16 22:42:54 2013 +0400 darwin/amd64
@sbinet

This comment has been minimized.

Copy link
Member Author

commented Aug 19, 2013

Comment 3:

hi,
actually, now, on my mac development machine:
$ uname -a
Darwin macpro4.somewhere.net 10.6.0 Darwin Kernel Version 10.6.0: Wed Nov 10 18:13:17
PST 2010; root:xnu-1504.9.26~3/RELEASE_I386 i386
with tip:
$ go version
go version devel +8bf13ae02c8e Mon Aug 19 16:22:33 2013 +1000 darwin/amd64
and with gcc-apple:
$ g++ --version
i686-apple-darwin10-g++-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5646) (dot 1)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
none of the solutions work.
ie: with -lstdc++, or with -static-libstdc++ I get the SEGV from the original report.
-s
@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Sep 4, 2013

Comment 4:

On GNU/Linux (Ubuntu Precise) this test case works when use -lstdc++, whether or not I
use -static-libstdc++.  Note that -static-libstdc++ does nothing by itself, it just
means that if libstdc++ is linked in, it will be linked in statically.
Your crash on Darwin suggests that the global constructors were not run.  What happens
if you do
    go run -ldflags "-extld g++" run.go
?
@sbinet

This comment has been minimized.

Copy link
Member Author

commented Sep 4, 2013

Comment 5:

Ian,
with tip:
$ go version
go version devel +a71616f65cb1 Tue Sep 03 21:23:52 2013 -0700 darwin/amd64
I still get:
$ ./doit
WORK=/var/folders/-Y/-YM5iRWlGwud5f9CdH77Ck+++TM/-Tmp-/go-build130503768
ttt
mkdir -p $WORK/ttt/_obj/
mkdir -p $WORK/
cd /Users/binet/tmp/go-tip/code/src/ttt
/Users/binet/tmp/go-tip/go/pkg/tool/darwin_amd64/cgo -objdir $WORK/ttt/_obj/ -- -I
$WORK/ttt/_obj/ ttt.go
/Users/binet/tmp/go-tip/go/pkg/tool/darwin_amd64/6c -F -V -w -I $WORK/ttt/_obj/ -I
/Users/binet/tmp/go-tip/go/pkg/darwin_amd64 -o $WORK/ttt/_obj/_cgo_defun.6 -D
GOOS_darwin -D GOARCH_amd64 $WORK/ttt/_obj/_cgo_defun.c
gcc -I . -g -O2 -fPIC -m64 -pthread -fno-common -print-libgcc-file-name
gcc -I . -g -O2 -fPIC -m64 -pthread -fno-common -I $WORK/ttt/_obj/ -o
$WORK/ttt/_obj/_cgo_main.o -c $WORK/ttt/_obj/_cgo_main.c
gcc -I . -g -O2 -fPIC -m64 -pthread -fno-common -I $WORK/ttt/_obj/ -o
$WORK/ttt/_obj/_cgo_export.o -c $WORK/ttt/_obj/_cgo_export.c
gcc -I . -g -O2 -fPIC -m64 -pthread -fno-common -I $WORK/ttt/_obj/ -o
$WORK/ttt/_obj/ttt.cgo2.o -c $WORK/ttt/_obj/ttt.cgo2.c
g++ -I . -g -O2 -fPIC -m64 -pthread -fno-common -I $WORK/ttt/_obj/ -o
$WORK/ttt/_obj/ttt.cxx.o -c ./ttt.cxx
g++ -I . -g -O2 -fPIC -m64 -pthread -fno-common -o $WORK/ttt/_obj/_cgo_.o
$WORK/ttt/_obj/_cgo_main.o $WORK/ttt/_obj/_cgo_export.o $WORK/ttt/_obj/ttt.cgo2.o
$WORK/ttt/_obj/ttt.cxx.o -lstdc++
/Users/binet/tmp/go-tip/go/pkg/tool/darwin_amd64/cgo -objdir $WORK/ttt/_obj/ -dynimport
$WORK/ttt/_obj/_cgo_.o -dynout $WORK/ttt/_obj/_cgo_import.c
/Users/binet/tmp/go-tip/go/pkg/tool/darwin_amd64/6c -F -V -w -I $WORK/ttt/_obj/ -I
/Users/binet/tmp/go-tip/go/pkg/darwin_amd64 -o $WORK/ttt/_obj/_cgo_import.6 -D
GOOS_darwin -D GOARCH_amd64 $WORK/ttt/_obj/_cgo_import.c
g++ -I . -g -O2 -fPIC -m64 -pthread -fno-common -o $WORK/ttt/_obj/_all.o
$WORK/ttt/_obj/_cgo_export.o $WORK/ttt/_obj/ttt.cgo2.o $WORK/ttt/_obj/ttt.cxx.o -Wl,-r
-nostdlib /usr/lib/gcc/i686-apple-darwin10/4.2.1/x86_64/libgcc.a
/Users/binet/tmp/go-tip/go/pkg/tool/darwin_amd64/6g -o $WORK/ttt/_obj/_go_.6 -p ttt -D
_/Users/binet/tmp/go-tip/code/src/ttt -I $WORK $WORK/ttt/_obj/_cgo_gotypes.go
$WORK/ttt/_obj/ttt.cgo1.go
/Users/binet/tmp/go-tip/go/pkg/tool/darwin_amd64/pack grcP $WORK $WORK/ttt.a
$WORK/ttt/_obj/_go_.6 $WORK/ttt/_obj/_cgo_import.6 $WORK/ttt/_obj/_cgo_defun.6
$WORK/ttt/_obj/_all.o
mkdir -p /Users/binet/tmp/go-tip/code/pkg/darwin_amd64/
cp $WORK/ttt.a /Users/binet/tmp/go-tip/code/pkg/darwin_amd64/ttt.a
ttt/ttt-run
mkdir -p $WORK/ttt/ttt-run/_obj/
mkdir -p $WORK/ttt/ttt-run/_obj/exe/
cd /Users/binet/tmp/go-tip/code/src/ttt/ttt-run
/Users/binet/tmp/go-tip/go/pkg/tool/darwin_amd64/6g -o $WORK/ttt/ttt-run/_obj/_go_.6 -p
ttt/ttt-run -complete -D _/Users/binet/tmp/go-tip/code/src/ttt/ttt-run -I $WORK -I
/Users/binet/tmp/go-tip/code/pkg/darwin_amd64 ./run.go
/Users/binet/tmp/go-tip/go/pkg/tool/darwin_amd64/pack grcP $WORK $WORK/ttt/ttt-run.a
$WORK/ttt/ttt-run/_obj/_go_.6
cd .
/Users/binet/tmp/go-tip/go/pkg/tool/darwin_amd64/6l -o $WORK/ttt/ttt-run/_obj/exe/a.out
-L $WORK -L /Users/binet/tmp/go-tip/code/pkg/darwin_amd64 -extld g++ $WORK/ttt/ttt-run.a
mkdir -p /Users/binet/tmp/go-tip/code/bin/
cp $WORK/ttt/ttt-run/_obj/exe/a.out /Users/binet/tmp/go-tip/code/bin/ttt-run
foo
SIGSEGV: segmentation violation
PC=0x7fff87c0468a
signal arrived during cgo execution
ttt._Cfunc_MyPrint(0xae220)
    ttt/_obj/_cgo_defun.c:46 +0x2f
ttt.Ttt()
    ttt/_obj/ttt.cgo1.go:17 +0x45
main.main()
    /Users/binet/dev/go/gocode/src/ttt/ttt-run/run.go:8 +0x18
goroutine 2 [syscall]:
goroutine 3 [runnable]:
rax     0x0
rbx     0x7fff70cf5b00
rcx     0x1d4f40
rdx     0x7fff70cf5b00
rdi     0x7fff5fbff4e0
rsi     0x7fff70cf5b00
rbp     0x7fff5fbff4c0
rsp     0x7fff5fbff4b0
r8      0x2
r9      0x823c0
r10     0x9c990
r11     0x93ce8
r12     0x7fff5fbff4e0
r13     0xe
r14     0x1320c1a1a6573400
r15     0xc5e28
rip     0x7fff87c0468a
rflags  0x10202
cs      0x27
fs      0x0
gs      0x0
zsh: exit 2     ./doit
which, with gdb:
(gdb) r
Starting program: /Users/binet/dev/go/gocode/bin/ttt-run 
Reading symbols for shared libraries ++. done
foo
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0xffffffffffffffe8
0x00007fff87c0468a in std::ostream::sentry::sentry ()
(gdb) bt
#0  0x00007fff87c0468a in std::ostream::sentry::sentry ()
#1  0x00007fff87c04b0d in std::__ostream_insert<char, std::char_traits<char>
> ()
Die: DW_TAG_unspecified_type (abbrev = 10, offset = 141)
    has children: FALSE
    attributes:
        DW_AT_name (DW_FORM_string) string: "<unspecified>"
Die: DW_TAG_unspecified_type (abbrev = 10, offset = 141)
    has children: FALSE
    attributes:
        DW_AT_name (DW_FORM_string) string: "<unspecified>"
Die: DW_TAG_unspecified_type (abbrev = 10, offset = 141)
    has children: FALSE
    attributes:
        DW_AT_name (DW_FORM_string) string: "<unspecified>"
Dwarf Error: Cannot find type of die [in module /Users/binet/dev/go/gocode/bin/ttt-run]
@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Sep 4, 2013

Comment 6:

Thanks for trying.  As far as I can see std::cout is not getting initialized.  This is
going to need investigation by somebody who knows more C++ on Darwin.
Although I don't see any evidence of this in the GCC source code, it's possible that
your g++ only works correctly if the main function is compiled by g++.  One way to test
this would be to add a call to __main() in your MyPrint function before referring to
std::cout.  (If that fails to link with an undefined reference to __main, then that is
not the problem, but I have no other idea what the problem might be.)

Labels changed: added os-macosx.

Status changed to HelpWanted.

@sbinet

This comment has been minimized.

Copy link
Member Author

commented Sep 4, 2013

Comment 7:

ok, I tried to apply this patch to the ttt.cxx file:
--- ttt.cxx.orig    2013-09-04 20:29:15.000000000 +0200
+++ ttt.cxx 2013-09-04 20:27:52.000000000 +0200
@@ -3,7 +3,9 @@
 #include <iostream>
 
 extern "C" {
+  void __main();
   void MyPrint() {
+   __main();
     std::cout << "hello from c++" << std::endl;
   }
 }
and indeed, got a failure at link time:
$ ./doit        
WORK=/var/folders/-Y/-YM5iRWlGwud5f9CdH77Ck+++TM/-Tmp-/go-build256475887
ttt
mkdir -p $WORK/ttt/_obj/
mkdir -p $WORK/
cd /Users/binet/tmp/go-tip/code/src/ttt
/Users/binet/tmp/go-tip/go/pkg/tool/darwin_amd64/cgo -objdir $WORK/ttt/_obj/ -- -I
$WORK/ttt/_obj/ ttt.go
/Users/binet/tmp/go-tip/go/pkg/tool/darwin_amd64/6c -F -V -w -I $WORK/ttt/_obj/ -I
/Users/binet/tmp/go-tip/go/pkg/darwin_amd64 -o $WORK/ttt/_obj/_cgo_defun.6 -D
GOOS_darwin -D GOARCH_amd64 $WORK/ttt/_obj/_cgo_defun.c
gcc -I . -g -O2 -fPIC -m64 -pthread -fno-common -print-libgcc-file-name
gcc -I . -g -O2 -fPIC -m64 -pthread -fno-common -I $WORK/ttt/_obj/ -o
$WORK/ttt/_obj/_cgo_main.o -c $WORK/ttt/_obj/_cgo_main.c
gcc -I . -g -O2 -fPIC -m64 -pthread -fno-common -I $WORK/ttt/_obj/ -o
$WORK/ttt/_obj/_cgo_export.o -c $WORK/ttt/_obj/_cgo_export.c
gcc -I . -g -O2 -fPIC -m64 -pthread -fno-common -I $WORK/ttt/_obj/ -o
$WORK/ttt/_obj/ttt.cgo2.o -c $WORK/ttt/_obj/ttt.cgo2.c
g++ -I . -g -O2 -fPIC -m64 -pthread -fno-common -I $WORK/ttt/_obj/ -o
$WORK/ttt/_obj/ttt.cxx.o -c ./ttt.cxx
g++ -I . -g -O2 -fPIC -m64 -pthread -fno-common -o $WORK/ttt/_obj/_cgo_.o
$WORK/ttt/_obj/_cgo_main.o $WORK/ttt/_obj/_cgo_export.o $WORK/ttt/_obj/ttt.cgo2.o
$WORK/ttt/_obj/ttt.cxx.o -lstdc++
# ttt
Undefined symbols:
  "___main", referenced from:
      _MyPrint in ttt.cxx.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Sep 9, 2013

Comment 8:

This issue was updated by revision f0ff63e.

R=golang-dev, minux.ma, rsc
CC=golang-dev
https://golang.org/cl/13394045
@sbinet

This comment has been minimized.

Copy link
Member Author

commented Sep 9, 2013

Comment 9:

hi,
same basic outcome (even though one can clearly see -extld=g++ being automatically
inserted):
$ go version
go version devel +ca80c16cf523 Mon Sep 09 12:50:49 2013 -0700 darwin/amd64
$ ./doit
WORK=/var/folders/-Y/-YM5iRWlGwud5f9CdH77Ck+++TM/-Tmp-/go-build217132290
ttt
mkdir -p $WORK/ttt/_obj/
mkdir -p $WORK/
cd /Users/binet/tmp/go-tip/code/src/ttt
/Users/binet/tmp/go-tip/go/pkg/tool/darwin_amd64/cgo -objdir $WORK/ttt/_obj/ -- -I
$WORK/ttt/_obj/ ttt.go
/Users/binet/tmp/go-tip/go/pkg/tool/darwin_amd64/6c -F -V -w -I $WORK/ttt/_obj/ -I
/Users/binet/tmp/go-tip/go/pkg/darwin_amd64 -o $WORK/ttt/_obj/_cgo_defun.6 -D
GOOS_darwin -D GOARCH_amd64 $WORK/ttt/_obj/_cgo_defun.c
gcc -I . -g -O2 -fPIC -m64 -pthread -fno-common -print-libgcc-file-name
gcc -I . -g -O2 -fPIC -m64 -pthread -fno-common -I $WORK/ttt/_obj/ -o
$WORK/ttt/_obj/_cgo_main.o -c $WORK/ttt/_obj/_cgo_main.c
gcc -I . -g -O2 -fPIC -m64 -pthread -fno-common -I $WORK/ttt/_obj/ -o
$WORK/ttt/_obj/_cgo_export.o -c $WORK/ttt/_obj/_cgo_export.c
gcc -I . -g -O2 -fPIC -m64 -pthread -fno-common -I $WORK/ttt/_obj/ -o
$WORK/ttt/_obj/ttt.cgo2.o -c $WORK/ttt/_obj/ttt.cgo2.c
g++ -I . -g -O2 -fPIC -m64 -pthread -fno-common -I $WORK/ttt/_obj/ -o
$WORK/ttt/_obj/ttt.cxx.o -c ./ttt.cxx
g++ -I . -g -O2 -fPIC -m64 -pthread -fno-common -o $WORK/ttt/_obj/_cgo_.o
$WORK/ttt/_obj/_cgo_main.o $WORK/ttt/_obj/_cgo_export.o $WORK/ttt/_obj/ttt.cgo2.o
$WORK/ttt/_obj/ttt.cxx.o
/Users/binet/tmp/go-tip/go/pkg/tool/darwin_amd64/cgo -objdir $WORK/ttt/_obj/ -dynimport
$WORK/ttt/_obj/_cgo_.o -dynout $WORK/ttt/_obj/_cgo_import.c
/Users/binet/tmp/go-tip/go/pkg/tool/darwin_amd64/6c -F -V -w -I $WORK/ttt/_obj/ -I
/Users/binet/tmp/go-tip/go/pkg/darwin_amd64 -o $WORK/ttt/_obj/_cgo_import.6 -D
GOOS_darwin -D GOARCH_amd64 $WORK/ttt/_obj/_cgo_import.c
g++ -I . -g -O2 -fPIC -m64 -pthread -fno-common -o $WORK/ttt/_obj/_all.o
$WORK/ttt/_obj/_cgo_export.o $WORK/ttt/_obj/ttt.cgo2.o $WORK/ttt/_obj/ttt.cxx.o -Wl,-r
-nostdlib /usr/lib/gcc/i686-apple-darwin10/4.2.1/x86_64/libgcc.a
/Users/binet/tmp/go-tip/go/pkg/tool/darwin_amd64/6g -o $WORK/ttt/_obj/_go_.6 -p ttt -D
_/Users/binet/tmp/go-tip/code/src/ttt -I $WORK $WORK/ttt/_obj/_cgo_gotypes.go
$WORK/ttt/_obj/ttt.cgo1.go
/Users/binet/tmp/go-tip/go/pkg/tool/darwin_amd64/pack grcP $WORK $WORK/ttt.a
$WORK/ttt/_obj/_go_.6 $WORK/ttt/_obj/_cgo_import.6 $WORK/ttt/_obj/_cgo_defun.6
$WORK/ttt/_obj/_all.o
mkdir -p /Users/binet/tmp/go-tip/code/pkg/darwin_amd64/
cp $WORK/ttt.a /Users/binet/tmp/go-tip/code/pkg/darwin_amd64/ttt.a
ttt/ttt-run
mkdir -p $WORK/ttt/ttt-run/_obj/
mkdir -p $WORK/ttt/ttt-run/_obj/exe/
cd /Users/binet/tmp/go-tip/code/src/ttt/ttt-run
/Users/binet/tmp/go-tip/go/pkg/tool/darwin_amd64/cgo -objdir $WORK/ttt/ttt-run/_obj/ --
-I $WORK/ttt/ttt-run/_obj/ run.go
/Users/binet/tmp/go-tip/go/pkg/tool/darwin_amd64/6c -F -V -w -I $WORK/ttt/ttt-run/_obj/
-I /Users/binet/tmp/go-tip/go/pkg/darwin_amd64 -o $WORK/ttt/ttt-run/_obj/_cgo_defun.6 -D
GOOS_darwin -D GOARCH_amd64 $WORK/ttt/ttt-run/_obj/_cgo_defun.c
gcc -I . -g -O2 -fPIC -m64 -pthread -fno-common -I $WORK/ttt/ttt-run/_obj/ -o
$WORK/ttt/ttt-run/_obj/_cgo_main.o -c $WORK/ttt/ttt-run/_obj/_cgo_main.c
gcc -I . -g -O2 -fPIC -m64 -pthread -fno-common -I $WORK/ttt/ttt-run/_obj/ -o
$WORK/ttt/ttt-run/_obj/_cgo_export.o -c $WORK/ttt/ttt-run/_obj/_cgo_export.c
gcc -I . -g -O2 -fPIC -m64 -pthread -fno-common -I $WORK/ttt/ttt-run/_obj/ -o
$WORK/ttt/ttt-run/_obj/run.cgo2.o -c $WORK/ttt/ttt-run/_obj/run.cgo2.c
gcc -I . -g -O2 -fPIC -m64 -pthread -fno-common -o $WORK/ttt/ttt-run/_obj/_cgo_.o
$WORK/ttt/ttt-run/_obj/_cgo_main.o $WORK/ttt/ttt-run/_obj/_cgo_export.o
$WORK/ttt/ttt-run/_obj/run.cgo2.o
/Users/binet/tmp/go-tip/go/pkg/tool/darwin_amd64/cgo -objdir $WORK/ttt/ttt-run/_obj/
-dynimport $WORK/ttt/ttt-run/_obj/_cgo_.o -dynout $WORK/ttt/ttt-run/_obj/_cgo_import.c
/Users/binet/tmp/go-tip/go/pkg/tool/darwin_amd64/6c -F -V -w -I $WORK/ttt/ttt-run/_obj/
-I /Users/binet/tmp/go-tip/go/pkg/darwin_amd64 -o $WORK/ttt/ttt-run/_obj/_cgo_import.6
-D GOOS_darwin -D GOARCH_amd64 $WORK/ttt/ttt-run/_obj/_cgo_import.c
gcc -I . -g -O2 -fPIC -m64 -pthread -fno-common -o $WORK/ttt/ttt-run/_obj/_all.o
$WORK/ttt/ttt-run/_obj/_cgo_export.o $WORK/ttt/ttt-run/_obj/run.cgo2.o -Wl,-r -nostdlib
/usr/lib/gcc/i686-apple-darwin10/4.2.1/x86_64/libgcc.a
/Users/binet/tmp/go-tip/go/pkg/tool/darwin_amd64/6g -o $WORK/ttt/ttt-run/_obj/_go_.6 -p
ttt/ttt-run -D _/Users/binet/tmp/go-tip/code/src/ttt/ttt-run -I $WORK -I
/Users/binet/tmp/go-tip/code/pkg/darwin_amd64 $WORK/ttt/ttt-run/_obj/_cgo_gotypes.go
$WORK/ttt/ttt-run/_obj/run.cgo1.go
/Users/binet/tmp/go-tip/go/pkg/tool/darwin_amd64/pack grcP $WORK $WORK/ttt/ttt-run.a
$WORK/ttt/ttt-run/_obj/_go_.6 $WORK/ttt/ttt-run/_obj/_cgo_import.6
$WORK/ttt/ttt-run/_obj/_cgo_defun.6 $WORK/ttt/ttt-run/_obj/_all.o
cd .
/Users/binet/tmp/go-tip/go/pkg/tool/darwin_amd64/6l -o $WORK/ttt/ttt-run/_obj/exe/a.out
-L $WORK -L /Users/binet/tmp/go-tip/code/pkg/darwin_amd64 -extld=g++ $WORK/ttt/ttt-run.a
mkdir -p /Users/binet/tmp/go-tip/code/bin/
cp $WORK/ttt/ttt-run/_obj/exe/a.out /Users/binet/tmp/go-tip/code/bin/ttt-run
foo
SIGSEGV: segmentation violation
PC=0x7fff87c0468a
signal arrived during cgo execution
runtime.cgocall(0x78b04, 0x350ef8)
    /Users/binet/tmp/go-tip/go/src/pkg/runtime/cgocall.c:149 +0x11b fp=0x350ee0
ttt._Cfunc_MyPrint(0xb7180)
    ttt/_obj/_cgo_defun.c:43 +0x31 fp=0x350ef8
ttt.T()
    /Users/binet/tmp/go-tip/code/src/ttt/ttt.go:10 +0x47 fp=0x350f40
main.main()
    /Users/binet/tmp/go-tip/code/src/ttt/ttt-run/run.go:10 +0x1a fp=0x350f48
runtime.main()
    /Users/binet/tmp/go-tip/go/src/pkg/runtime/proc.c:212 +0x11f fp=0x350fa0
runtime.goexit()
    /Users/binet/tmp/go-tip/go/src/pkg/runtime/proc.c:1386 fp=0x350fa8
goroutine 3 [syscall]:
runtime.goexit()
    /Users/binet/tmp/go-tip/go/src/pkg/runtime/proc.c:1386
rax     0x0
rbx     0x7fff70cf5b00
rcx     0x350ef8
rdx     0x7fff70cf5b00
rdi     0x7fff5fbff4a0
rsi     0x7fff70cf5b00
rbp     0x7fff5fbff480
rsp     0x7fff5fbff470
r8      0xc210001120
r9      0x350e90
r10     0x2dadb395ca70
r11     0x607b7a00
r12     0x7fff5fbff4a0
r13     0xe
r14     0x13225530194c1200
r15     0xde630
rip     0x7fff87c0468a
rflags  0x10202
cs      0x27
fs      0x0
gs      0x0
zsh: exit 2     ./doit
@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Sep 9, 2013

Comment 10:

My guess is that the global constructors are not being run, but I have no idea why that
would be happening.  Somebody on a Darwin system will have to investigate.
@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Sep 9, 2013

Comment 11:

My guess is that the global constructors are not being run, but I have no idea why that
would be happening.  Somebody on a Darwin system will have to investigate.
@rsc

This comment has been minimized.

Copy link
Contributor

commented Sep 11, 2013

Comment 12:

I ran the script given in the original report and it produces a binary that works just
fine.
I suspect this was fixed by Ian's change yesterday that uses g++ as the external linker
when C++ is involved.
changeset:   17997:eeb4127a4d00
user:        Ian Lance Taylor <iant@golang.org>
date:        Thu Sep 05 12:55:21 2013 -0700
summary:     cmd/ld: emit relocations for .debug_frame in external link mode

Status changed to Fixed.

@sbinet sbinet added fixed labels Sep 11, 2013

@rsc rsc added this to the Go1.2 milestone Apr 14, 2015

@rsc rsc removed the go1.2 label Apr 14, 2015

@golang golang locked and limited conversation to collaborators Jun 24, 2016

This issue was closed.

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