You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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".
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
@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.
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
The text was updated successfully, but these errors were encountered: