mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/go, cmd/cgo: support -buildmode=c-archive for gccgo
This extends the cgo changes in http://golang.org/cl/8094 to gccgo. It also adds support for setting runtime_iscgo correctly for gccgo; the gc runtime bases the variable on the runtime/cgo package, but gccgo has no equivalent to that package. The go tool supports -buildmode=c-archive for gccgo by linking all the Go objects together using -r. For convenience this object is then put into an archive file. The go tool now passes -fsplit-stack when building C code for gccgo on 386 and amd64. This is required for using -r and will also cut down on unnecessary stack splits. The go tool no longer applies standard package cgo LDFLAGS when using gccgo. This is mainly to avoid getting confused by the LDFLAGS in the runtime/cgo package that gccgo does not use. Change-Id: I1d0865b2a362818a033ca9e9e901d0ce250784e7 Reviewed-on: https://go-review.googlesource.com/9511 Reviewed-by: David Crawshaw <crawshaw@golang.org>
This commit is contained in:
parent
f4e3e5eaf0
commit
42bb59a372
2 changed files with 117 additions and 21 deletions
|
|
@ -840,6 +840,8 @@ func (p *Package) writeGccgoExports(fgo2, fm io.Writer) {
|
|||
fmt.Fprintf(fgcc, "/* Created by cgo - DO NOT EDIT. */\n")
|
||||
fmt.Fprintf(fgcc, "#include \"_cgo_export.h\"\n")
|
||||
|
||||
fmt.Fprintf(fgcc, "%s\n", gccgoExportFileProlog)
|
||||
|
||||
for _, exp := range p.ExpFunc {
|
||||
fn := exp.Func
|
||||
fntype := fn.Type
|
||||
|
|
@ -908,6 +910,8 @@ func (p *Package) writeGccgoExports(fgo2, fm io.Writer) {
|
|||
|
||||
fmt.Fprint(fgcc, "\n")
|
||||
fmt.Fprintf(fgcc, "%s %s %s {\n", cRet, exp.ExpName, cParams)
|
||||
fmt.Fprintf(fgcc, "\tif(_cgo_wait_runtime_init_done)\n")
|
||||
fmt.Fprintf(fgcc, "\t\t_cgo_wait_runtime_init_done();\n")
|
||||
fmt.Fprint(fgcc, "\t")
|
||||
if resultCount > 0 {
|
||||
fmt.Fprint(fgcc, "return ")
|
||||
|
|
@ -1324,3 +1328,19 @@ typedef void *GoChan;
|
|||
typedef struct { void *t; void *v; } GoInterface;
|
||||
typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;
|
||||
`
|
||||
|
||||
// gccgoExportFileProlog is written to the _cgo_export.c file when
|
||||
// using gccgo.
|
||||
// We use weak declarations, and test the addresses, so that this code
|
||||
// works with older versions of gccgo.
|
||||
const gccgoExportFileProlog = `
|
||||
extern _Bool runtime_iscgo __attribute__ ((weak));
|
||||
|
||||
static void GoInit(void) __attribute__ ((constructor));
|
||||
static void GoInit(void) {
|
||||
if(&runtime_iscgo)
|
||||
runtime_iscgo = 1;
|
||||
}
|
||||
|
||||
extern void _cgo_wait_runtime_init_done() __attribute__ ((weak));
|
||||
`
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue