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: specifying -g1 fails compilation #26144

Closed
benesch opened this Issue Jun 29, 2018 · 1 comment

Comments

Projects
None yet
3 participants
@benesch
Contributor

benesch commented Jun 29, 2018

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version devel +cbce223 Fri Jun 29 17:44:10 2018 +0000 linux/amd64

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

linux/amd64

What did you do?

I attempted to compile the following toy program

# t.go
package main

// void foo(void) {}
import "C"

func main() {
	C.foo();
}

with this command:

$ CGO_CFLAGS=-g1 go build

What did you expect to see?

A working program with minimal debug information.

What did you see instead?

A compilation failure:

# github.com/benesch/t
./t.go:7:2: call of non-function C.foo

Seems like cgo really needs debug information to be available. The problem changes with -g0:

$ CGO_CFLAGS=-g0 go build
# github.com/benesch/t
cannot load DWARF output from $WORK/b001//_cgo_.o: decoding dwarf section info at offset 0x0: too short

I don't particularly care if cgo silently upgrades the amount of debugging where necessary—or outright rejects -g0 and -g1. I just accidentally stumbled across this while trying to plumb some flags for msan through CockroachDB's C/C++ dependencies and it took a while to figure out what had gone wrong.

/cc @ianlancetaylor

@ianlancetaylor ianlancetaylor added this to the Go1.12 milestone Jun 29, 2018

@gopherbot

This comment has been minimized.

gopherbot commented Dec 4, 2018

Change https://golang.org/cl/152165 mentions this issue: cmd/cgo: don't pass CGO_CFLAGS -g options to debug info generation

@gopherbot gopherbot closed this in 8c5976f Dec 10, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment