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

bad MACH cpu subtype with cgo #6481

Closed
lukescott opened this issue Sep 25, 2013 · 13 comments
Closed

bad MACH cpu subtype with cgo #6481

lukescott opened this issue Sep 25, 2013 · 13 comments

Comments

@lukescott
Copy link

I'm trying to profile a cgo package. See the attached test case.

When running with clang "top" looks like this:

Total: 526 samples
      66  12.5%  12.5%       66  12.5% 000000000402483b
      57  10.8%  23.4%       57  10.8% 0000000004024761
      25   4.8%  28.1%       25   4.8% 0000000004018c22
      18   3.4%  31.6%       18   3.4% 0000000004017bf7
      11   2.1%  33.7%       11   2.1% 0000000004018c55
       8   1.5%  35.2%        8   1.5% 0000000004017b64
       8   1.5%  36.7%        8   1.5% 0000000004017c88
       8   1.5%  38.2%        8   1.5% 0000000004018c60
       7   1.3%  39.5%        7   1.3% 0000000004017b86
       7   1.3%  40.9%        7   1.3% 0000000004018c45

When running with gcc 4.8 "top" looks like this:

Total: 531 samples
     531 100.0% 100.0%      531 100.0% 000000000402567b
       0   0.0% 100.0%      531 100.0% 0000000004018e60

In both cases I'm getting addresses instead of names. With gcc all the samples are
appearing as a single address. This happens with C or C++ code. C++ is attached. Rename
.cc to .c and comment out #ifdef in .h file to make C.

I'm running:

CX=g++-4.8 gotip test -c
./cgotest.test -test.cpuprofile=prof.out -test.bench=. -test.benchtime=3s -test.v
gotip tool pprof cgotest.test prof.out

Which compiler are you using (5g, 6g, 8g, gccgo)?

default w/ clang++
default w/ GNU g++ 4.8
default w/ clang
default w/ GNU gcc 4.8

Which operating system are you using?

Max OS X 10.8.5

Which version are you using?  (run 'go version')

go version devel +d744da8c8cbf Wed Sep 25 16:18:33 2013 -0400 darwin/amd64

Please provide any additional information below.

gcc 4.8 is installed with `brew install gcc48`

Attachments:

  1. cgotest.zip (695505 bytes)
@rsc
Copy link
Contributor

rsc commented Oct 18, 2013

Comment 1:

g% ./cgotest.test -test.cpuprofile=prof.out -test.bench=. -test.benchtime=3s -test.v
testing: warning: no tests to run
PASS
BenchmarkMe 100000000           63.8 ns/op
g% go tool pprof cgotest.test prof.out
Welcome to pprof!  For help, type 'help'.
(pprof) top10
Total: 590 samples
     590 100.0% 100.0%      590 100.0% runtime.mach_semaphore_wait
       0   0.0% 100.0%      590 100.0% System
(pprof)

Status changed to Duplicate.

Merged into issue #6197.

@rsc
Copy link
Contributor

rsc commented Oct 18, 2013

Comment 2:

Unmerging but if this isn't fix I need more information.
Why does the subject say "bad MACH cpu subtype" when the report does not mention that
text?

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

Status changed to Accepted.

@lukescott
Copy link
Author

Comment 3:

There were some errors in my original report, sorry. I left some things out. That's the
warning I get when I run: go tool pprof cgotest.test prof.out I think I also got the
output from g++ and clang++ backwards.
This is the result from g++4.8:
$ CXX=g++-4.8 go test -c
$ ./cgotest.test -test.cpuprofile=prof.out -test.bench=. -test.benchtime=3s -test.v
.. benchmark output ...
$ go tool pprof cgotest.test prof.out
addr2line: crackhdr: bad MACH cpu subtype - not amd64
Welcome to pprof!  For help, type 'help'.
(pprof) top
Total: 527 samples
      61  11.6%  11.6%       61  11.6% 00000000040247e1
      57  10.8%  22.4%       57  10.8% 00000000040248bb
      20   3.8%  26.2%       20   3.8% 0000000004018ca2
      15   2.8%  29.0%       15   2.8% 0000000004017e1c
      11   2.1%  31.1%       11   2.1% 0000000004018cd5
      10   1.9%  33.0%       10   1.9% 0000000004017c77
      10   1.9%  34.9%       10   1.9% 0000000004018d35
       9   1.7%  36.6%        9   1.7% 0000000004004b09
       8   1.5%  38.1%        8   1.5% 0000000004004b57
       7   1.3%  39.5%        7   1.3% 0000000004017ce9
This is what I get from clang++:
$ CXX=clang++ go test -c
$ ./cgotest.test -test.cpuprofile=prof.out -test.bench=. -test.benchtime=3s -test.v
.. benchmark output ...
$ go tool pprof cgotest.test prof.out
addr2line: crackhdr: bad MACH cpu subtype - not amd64
Welcome to pprof!  For help, type 'help'.
(pprof) top
Total: 516 samples
     516 100.0% 100.0%      516 100.0% 000000000402567b
       0   0.0% 100.0%      516 100.0% 0000000004018e60
This is using:
go version devel +d744da8c8cbf Wed Sep 25 16:18:33 2013 -0400 darwin/amd64

@rsc
Copy link
Contributor

rsc commented Oct 18, 2013

Comment 4:

This really really looks like the same bug. And using clang++ works fine
for me. (I don't have g++-4.8 to try.)
Please try CL https://golang.org/cl/15080046 and see what extra
information you get in the failure.
If you don't get any extra information then I think somehow pprof is
finding a stale addr2line binary.
Russ

@rsc
Copy link
Contributor

rsc commented Oct 18, 2013

Comment 5:

pprof runs 'go tool addr2line'.  It sounds like you have 'go' installed as
1.1 but 'gotip' installed as tip.

@lukescott
Copy link
Author

Comment 6:

Yes, I think that may be the problem. I have both installed on my system, and gotip is
an alias to my tip installation. Is there any way to get tip to run the correct version
of go?

@lukescott
Copy link
Author

Comment 7:

Yes, I think that may be the problem. I have both installed on my system, and gotip is
an alias to my tip installation. Is there any way to get pprof to run the correct
version of go?

@rsc
Copy link
Contributor

rsc commented Oct 18, 2013

Comment 8:

just cp $(gotip tool -n addr2line) $(go tool -n addr2line).
eventually pprof will be written in go.

@davecheney
Copy link
Contributor

Comment 9:

@like, assuming that you have not set $GOROOT then the different go binaries should
already be configured to locate their respective tools automatically. 
Compare the output of go even between the versions and if GOTOOLDIR overlaps, you have
found the problem.

@lukescott
Copy link
Author

Comment 10:

That would change my 1.1 installation, wouldn't it? I may be better off just using a
tool to change my PATH when I need to change versions instead of using an alias.
Surprising that the go tool doesn't give pprof an absolute path to itself.

@lukescott
Copy link
Author

Comment 11:

I do not have $GOROOT set at all, just $GOPATH. Here are my env results for both
versions:
1.1:
$ go env
GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/lukescott/Projects/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
CC="gcc"
GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread -fno-common"
CGO_ENABLED="1"
Tip:
$ gotip env
GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/lukescott/Projects/go"
GORACE=""
GOROOT="/Users/lukescott/gotip"
GOTOOLDIR="/Users/lukescott/gotip/pkg/tool/darwin_amd64"
TERM="dumb"
CC="gcc-4.8"
GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread -fno-common"
CXX="g++-4.8"
CGO_ENABLED="1"
As you can see GOTOOLDIR is different on both versions.

@rsc
Copy link
Contributor

rsc commented Oct 23, 2013

Comment 12:

pprof assumes that the 'go' command refers to the correct version of go. it
does not in this case.
the fix will be to stop using perl, and then pprof will not need to invoke
the go command.

@rsc
Copy link
Contributor

rsc commented Oct 23, 2013

Comment 13:

Status changed to Duplicate.

Merged into issue #6197.

@golang golang locked and limited conversation to collaborators Jun 25, 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
Development

No branches or pull requests

4 participants