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/go: no need to link _cgo_.o when using gccgo #16650

Closed
mdempsky opened this issue Aug 9, 2016 · 4 comments
Closed

cmd/go: no need to link _cgo_.o when using gccgo #16650

mdempsky opened this issue Aug 9, 2016 · 4 comments
Milestone

Comments

@mdempsky
Copy link
Member

mdempsky commented Aug 9, 2016

See https://github.com/golang/go/blob/master/src/cmd/go/build.go#L3346

When cgo is used with gc, we link cgo.o, analyze it with cgo -dynimport, and then link _all.o. cgo.o does not appear to be used further, and it does not end up in the compiled package .a file.

When using cgo with gccgo, we still link cgo.o, but skip the other two steps. We also don't return cgo.o as an outObj or anything. It looks like it's been this way since the short-circuit for gccgo was added (https://codereview.appspot.com/5650066), and the review doesn't mention any rationale for this.

As far as I can tell, linking cgo.o is useless for gccgo, unless it's meant as an early warning against eventual linker errors.

/cc @ianlancetaylor

@mdempsky mdempsky added this to the Go1.8 milestone Aug 9, 2016
@mdempsky
Copy link
Member Author

mdempsky commented Aug 9, 2016

Relatedly, I think the nonGccObjs code near the end of that file is dead code too as cmd/cc is gone. By construction, even string in outObj already ends with ".o".

@bronze1man
Copy link
Contributor

I want to call c function in another cgo package, but this "early warning against eventual linker errors" stop me.
I tried to add -flat_namespace -Wl,-undefined,warning to the command line that compile _cgo_.o fix my problem.
I hope you guys can delete that _cgo_.o stuff,and support the use case of calling c function in another cgo package

@mdempsky
Copy link
Member Author

@bronze1man I suggest you open a new issue for that use case. My intent with this issue isn't to stop linking cgo.o entirely; only to stop linking it when we don't actually need it.

@gopherbot
Copy link

CL https://golang.org/cl/27270 mentions this issue.

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

3 participants