diff --git a/misc/cgo/testcarchive/test.bash b/misc/cgo/testcarchive/test.bash index f4b4a3079fe..f4e7c458ec6 100755 --- a/misc/cgo/testcarchive/test.bash +++ b/misc/cgo/testcarchive/test.bash @@ -85,4 +85,22 @@ if ! $bin; then fi rm -rf libgo4.a libgo4.h testp pkg +rm -f testar +cat >testar </dev/null; do + shift +done +echo "testar" > \$1 +echo "testar" > $(pwd)/testar.ran +EOF +chmod +x testar +rm -f testar.ran +GOPATH=$(pwd) go build -buildmode=c-archive -ldflags=-extar=$(pwd)/testar -o libgo4.a libgo4 +if ! test -f testar.ran; then + echo "FAIL test5" + status=1 +fi +rm -rf libgo4.a libgo4.h testar testar.ran pkg + exit $status diff --git a/src/cmd/link/doc.go b/src/cmd/link/doc.go index 69f9b578590..ffaead7ba0d 100644 --- a/src/cmd/link/doc.go +++ b/src/cmd/link/doc.go @@ -52,6 +52,9 @@ Flags: The dynamic header is on by default, even without any references to dynamic libraries, because many common system tools now assume the presence of the header. + -extar ar + Set the external archive program (default "ar"). + Used only for -buildmode=c-archive. -extld linker Set the external linker (default "clang" or "gcc"). -extldflags flags diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go index a23a437e3d0..bdfa0563c3d 100644 --- a/src/cmd/link/internal/ld/lib.go +++ b/src/cmd/link/internal/ld/lib.go @@ -207,6 +207,7 @@ var ( tmpdir string extld string extldflags string + extar string libgccfile string debug_s int // backup old value of debug['s'] Ctxt *Link @@ -1015,8 +1016,12 @@ func archive() { return } + if extar == "" { + extar = "ar" + } + mayberemoveoutfile() - argv := []string{"ar", "-q", "-c", "-s", outfile} + argv := []string{extar, "-q", "-c", "-s", outfile} argv = append(argv, fmt.Sprintf("%s/go.o", tmpdir)) argv = append(argv, hostobjCopy()...) diff --git a/src/cmd/link/internal/ld/pobj.go b/src/cmd/link/internal/ld/pobj.go index 319e8504670..808d377f8a0 100644 --- a/src/cmd/link/internal/ld/pobj.go +++ b/src/cmd/link/internal/ld/pobj.go @@ -89,6 +89,7 @@ func Ldmain() { flag.Var(&Buildmode, "buildmode", "set build `mode`") obj.Flagcount("c", "dump call graph", &Debug['c']) obj.Flagcount("d", "disable dynamic executable", &Debug['d']) + obj.Flagstr("extar", "archive program for buildmode=c-archive", &extar) obj.Flagstr("extld", "use `linker` when linking in external mode", &extld) obj.Flagstr("extldflags", "pass `flags` to external linker", &extldflags) obj.Flagcount("f", "ignore version mismatch", &Debug['f'])