"cmd/go/internal/imports"
"cmd/go/internal/par"
"cmd/go/internal/txtar"
+ "cmd/go/internal/work"
)
// TestScript runs the tests in testdata/script/*.txt.
//
var scriptCmds = map[string]func(*testScript, bool, []string){
"addcrlf": (*testScript).cmdAddcrlf,
+ "cc": (*testScript).cmdCc,
"cd": (*testScript).cmdCd,
"chmod": (*testScript).cmdChmod,
"cmp": (*testScript).cmdCmp,
}
}
+// cc runs the C compiler along with platform specific options.
+func (ts *testScript) cmdCc(neg bool, args []string) {
+ if len(args) < 1 || (len(args) == 1 && args[0] == "&") {
+ ts.fatalf("usage: cc args... [&]")
+ }
+
+ var b work.Builder
+ b.Init()
+ ts.cmdExec(neg, append(b.GccCmd(".", ""), args...))
+}
+
// cd changes to a different directory.
func (ts *testScript) cmdCd(neg bool, args []string) {
if neg {
The commands are:
+- [!] cc args... [&]
+ Run the C compiler, the platform specific flags (i.e. `go env GOGCCFLAGS`) will be
+ added automatically before args.
+
- cd dir
Change to the given directory for future commands.
--- /dev/null
+# This test tests that we can link in-package syso files that provides symbols
+# for cgo. See issue 29253.
+[!cgo] stop
+[!gc] stop
+cc -c -o pkg/o.syso ext.c
+go build main.go
+
+-- ext.c --
+// +build ignore
+
+int f() { return 42; }
+-- pkg/pkg.go --
+package pkg
+
+// extern int f(void);
+import "C"
+
+func init() {
+ if v := C.f(); v != 42 {
+ panic(v)
+ }
+}
+-- main.go --
+package main
+
+import _ "pkg"
+
+func main() {}
// Skip other special (non-object-file) sections that
// build tools may have added. Such sections must have
// short names so that the suffix is not truncated.
- if len(arhdr.name) < 16 && !strings.HasSuffix(arhdr.name, ".o") {
- continue
+ if len(arhdr.name) < 16 {
+ if ext := filepath.Ext(arhdr.name); ext != ".o" && ext != ".syso" {
+ continue
+ }
}
pname := fmt.Sprintf("%s(%s)", lib.File, arhdr.name)