diff options
Diffstat (limited to 'src/cmd/cgo')
-rw-r--r-- | src/cmd/cgo/doc.go | 16 | ||||
-rw-r--r-- | src/cmd/cgo/gcc.go | 6 | ||||
-rw-r--r-- | src/cmd/cgo/main.go | 4 | ||||
-rw-r--r-- | src/cmd/cgo/out.go | 11 |
4 files changed, 24 insertions, 13 deletions
diff --git a/src/cmd/cgo/doc.go b/src/cmd/cgo/doc.go index 955b7c495..efbeae958 100644 --- a/src/cmd/cgo/doc.go +++ b/src/cmd/cgo/doc.go @@ -70,7 +70,7 @@ assignment context to retrieve both the return value (if any) and the C errno variable as an error (use _ to skip the result value if the function returns void). For example: - n, err := C.atoi("abc") + n, err := C.sqrt(-1) _, err := C.voidFunc() In C, a function argument written as a fixed size array @@ -484,16 +484,16 @@ The directives are: Example: #pragma cgo_dynamic_linker "/lib/ld-linux.so.2" -#pragma cgo_export <local> <remote> +#pragma cgo_export_dynamic <local> <remote> - In both internal and external linking modes, put the Go symbol + In internal linking mode, put the Go symbol named <local> into the program's exported symbol table as <remote>, so that C code can refer to it by that name. This mechanism makes it possible for C code to call back into Go or to share Go's data. For compatibility with current versions of SWIG, - #pragma dynexport is an alias for #pragma cgo_export. + #pragma dynexport is an alias for #pragma cgo_export_dynamic. #pragma cgo_import_static <local> @@ -505,6 +505,14 @@ The directives are: Example: #pragma cgo_import_static puts_wrapper +#pragma cgo_export_static <local> <remote> + + In external linking mode, put the Go symbol + named <local> into the program's exported symbol table as + <remote>, so that C code can refer to it by that name. This + mechanism makes it possible for C code to call back into Go or + to share Go's data. + #pragma cgo_ldflag "<arg>" In external linking mode, invoke the host linker (usually gcc) diff --git a/src/cmd/cgo/gcc.go b/src/cmd/cgo/gcc.go index 4b0a521a8..585f01477 100644 --- a/src/cmd/cgo/gcc.go +++ b/src/cmd/cgo/gcc.go @@ -139,11 +139,7 @@ NextLine: // addToFlag appends args to flag. All flags are later written out onto the // _cgo_flags file for the build system to use. func (p *Package) addToFlag(flag string, args []string) { - if oldv, ok := p.CgoFlags[flag]; ok { - p.CgoFlags[flag] = oldv + " " + strings.Join(args, " ") - } else { - p.CgoFlags[flag] = strings.Join(args, " ") - } + p.CgoFlags[flag] = append(p.CgoFlags[flag], args...) if flag == "CFLAGS" { // We'll also need these when preprocessing for dwarf information. p.GccOptions = append(p.GccOptions, args...) diff --git a/src/cmd/cgo/main.go b/src/cmd/cgo/main.go index 7adc795de..ca370ef3f 100644 --- a/src/cmd/cgo/main.go +++ b/src/cmd/cgo/main.go @@ -33,7 +33,7 @@ type Package struct { PtrSize int64 IntSize int64 GccOptions []string - CgoFlags map[string]string // #cgo flags (CFLAGS, LDFLAGS) + CgoFlags map[string][]string // #cgo flags (CFLAGS, LDFLAGS) Written map[string]bool Name map[string]*Name // accumulated Name from Files ExpFunc []*ExpFunc // accumulated ExpFunc from Files @@ -312,7 +312,7 @@ func newPackage(args []string) *Package { PtrSize: ptrSize, IntSize: intSize, GccOptions: gccOptions, - CgoFlags: make(map[string]string), + CgoFlags: make(map[string][]string), Written: make(map[string]bool), } return p diff --git a/src/cmd/cgo/out.go b/src/cmd/cgo/out.go index a126cf17f..ee1d89142 100644 --- a/src/cmd/cgo/out.go +++ b/src/cmd/cgo/out.go @@ -31,7 +31,12 @@ func (p *Package) writeDefs() { fflg := creat(*objDir + "_cgo_flags") for k, v := range p.CgoFlags { - fmt.Fprintf(fflg, "_CGO_%s=%s\n", k, v) + fmt.Fprintf(fflg, "_CGO_%s=%s\n", k, strings.Join(v, " ")) + if k == "LDFLAGS" { + for _, arg := range v { + fmt.Fprintf(fc, "#pragma cgo_ldflag %q\n", arg) + } + } } fflg.Close() @@ -100,6 +105,7 @@ func (p *Package) writeDefs() { fmt.Fprintf(fm, "extern char %s[];\n", n.C) fmt.Fprintf(fm, "void *_cgohack_%s = %s;\n\n", n.C, n.C) + fmt.Fprintf(fc, "#pragma cgo_import_static %s\n", n.C) fmt.Fprintf(fc, "extern byte *%s;\n", n.C) cVars[n.C] = true @@ -651,8 +657,9 @@ func (p *Package) writeExports(fgo2, fc, fm *os.File) { if fn.Recv != nil { goname = "_cgoexpwrap" + cPrefix + "_" + fn.Recv.List[0].Names[0].Name + "_" + goname } - fmt.Fprintf(fc, "#pragma cgo_export %s\n", goname) + fmt.Fprintf(fc, "#pragma cgo_export_dynamic %s\n", goname) fmt.Fprintf(fc, "extern void ยท%s();\n\n", goname) + fmt.Fprintf(fc, "#pragma cgo_export_static _cgoexp%s_%s\n", cPrefix, exp.ExpName) fmt.Fprintf(fc, "#pragma textflag 7\n") // no split stack, so no use of m or g fmt.Fprintf(fc, "void\n") fmt.Fprintf(fc, "_cgoexp%s_%s(void *a, int32 n)\n", cPrefix, exp.ExpName) |