-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Description
What version of Go are you using (go version
)?
$ go version go version go1.16.2 darwin/amd64
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (go env
)?
go env
Output
$ go env GO111MODULE="on" GOARCH="amd64" GOBIN="" GOCACHE="/Users/sinlov/Library/Caches/go-build" GOENV="/Users/sinlov/Library/Application Support/go/env" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="darwin" GOINSECURE="" GOMODCACHE="/Users/sinlov/go/pkg/mod" GONOPROXY="*.gitlab.com,*.gitea.com" GONOSUMDB="*.gitlab.com,*.gitea.com" GOOS="darwin" GOPATH="/Users/sinlov/go" GOPRIVATE="*.gitlab.com,*.gitea.com" GOPROXY="https://goproxy.cn,direct" GOROOT="/usr/local/opt/go/libexec" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/local/opt/go/libexec/pkg/tool/darwin_amd64" GOVCS="" GOVERSION="go1.16.2" GCCGO="gccgo" AR="ar" CC="clang" CXX="clang++" CGO_ENABLED="1" GOMOD="/Users/sinlov/go/src/github.com/sinlov/cgo-compile-test/go.mod" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/tm/2y07gxzj72x_nc91rxq7w9_80000gn/T/go-build766165709=/tmp/go-build -gno-record-gcc-switches -fno-common"
What did you do?
compile simpleness cgo with mode -buildmode=c-archive
go build args
CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 go build -ldflags "-w" -x -v -buildmode=c-archive
code at https://github.com/sinlov/cgo-compile-test
What did you expect to see?
$ make
...
file test.a
test.a: current ar archive random library
What did you see instead?
$ make
...
file test.a
test.a: current ar archive
go build
Output
$ make CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 \ go build -ldflags "-w" -x -v -buildmode=c-archive \ -o test.a WORK=/var/folders/tm/2y07gxzj72x_nc91rxq7w9_80000gn/T/go-build1896598438 runtime/cgo mkdir -p $WORK/b003/ cd /usr/local/opt/go/libexec/src/runtime/cgo TERM='dumb' CGO_LDFLAGS='"-g" "-O2" "-lpthread"' /usr/local/opt/go/libexec/pkg/tool/darwin_amd64/cgo -objdir $WORK/b003/ -importpath runtime/cgo -import_runtime_cgo=false -import_syscall=false -exportheader=$WORK/b003/_cgo_install.h -- -I $WORK/b003/ -g -O2 -Wno-nullability-completeness -Wall -Werror ./cgo.go cd $WORK clang -fno-caret-diagnostics -c -x c - -o /dev/null || true clang -Qunused-arguments -c -x c - -o /dev/null || true clang -fdebug-prefix-map=a=b -c -x c - -o /dev/null || true clang -gno-record-gcc-switches -c -x c - -o /dev/null || true cd $WORK/b003 TERM='dumb' clang -I /usr/local/opt/go/libexec/src/runtime/cgo -fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=$WORK/b003=/tmp/go-build -gno-record-gcc-switches -fno-common -I ./ -g -O2 -Wno-nullability-completeness -Wall -Werror -o ./_x001.o -c _cgo_export.c TERM='dumb' clang -I /usr/local/opt/go/libexec/src/runtime/cgo -fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=$WORK/b003=/tmp/go-build -gno-record-gcc-switches -fno-common -I ./ -g -O2 -Wno-nullability-completeness -Wall -Werror -o ./_x002.o -c cgo.cgo2.c cd /usr/local/opt/go/libexec/src/runtime/cgo TERM='dumb' clang -I . -fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=$WORK/b003=/tmp/go-build -gno-record-gcc-switches -fno-common -I $WORK/b003/ -g -O2 -Wno-nullability-completeness -Wall -Werror -o $WORK/b003/_x003.o -c gcc_context.c TERM='dumb' clang -I . -fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=$WORK/b003=/tmp/go-build -gno-record-gcc-switches -fno-common -I $WORK/b003/ -g -O2 -Wno-nullability-completeness -Wall -Werror -o $WORK/b003/_x004.o -c gcc_darwin_amd64.c TERM='dumb' clang -I . -fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=$WORK/b003=/tmp/go-build -gno-record-gcc-switches -fno-common -I $WORK/b003/ -g -O2 -Wno-nullability-completeness -Wall -Werror -o $WORK/b003/_x005.o -c gcc_libinit.c TERM='dumb' clang -I . -fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=$WORK/b003=/tmp/go-build -gno-record-gcc-switches -fno-common -I $WORK/b003/ -g -O2 -Wno-nullability-completeness -Wall -Werror -o $WORK/b003/_x006.o -c gcc_setenv.c TERM='dumb' clang -I . -fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=$WORK/b003=/tmp/go-build -gno-record-gcc-switches -fno-common -I $WORK/b003/ -g -O2 -Wno-nullability-completeness -Wall -Werror -o $WORK/b003/_x007.o -c gcc_traceback.c TERM='dumb' clang -I . -fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=$WORK/b003=/tmp/go-build -gno-record-gcc-switches -fno-common -I $WORK/b003/ -g -O2 -Wno-nullability-completeness -Wall -Werror -o $WORK/b003/_x008.o -c gcc_util.c TERM='dumb' clang -I . -fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=$WORK/b003=/tmp/go-build -gno-record-gcc-switches -fno-common -I $WORK/b003/ -g -O2 -Wno-nullability-completeness -Wall -Werror -o $WORK/b003/_x009.o -c gcc_amd64.S cd $WORK/b003 TERM='dumb' clang -I /usr/local/opt/go/libexec/src/runtime/cgo -fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=$WORK/b003=/tmp/go-build -gno-record-gcc-switches -fno-common -I ./ -g -O2 -Wno-nullability-completeness -Wall -Werror -o ./_cgo_main.o -c _cgo_main.c cd /Users/sinlov/go/src/github.com/sinlov/cgo-compile-test TERM='dumb' clang -I /usr/local/opt/go/libexec/src/runtime/cgo -fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=$WORK/b003=/tmp/go-build -gno-record-gcc-switches -fno-common -o $WORK/b003/_cgo_.o $WORK/b003/_cgo_main.o $WORK/b003/_x001.o $WORK/b003/_x002.o $WORK/b003/_x003.o $WORK/b003/_x004.o $WORK/b003/_x005.o $WORK/b003/_x006.o $WORK/b003/_x007.o $WORK/b003/_x008.o $WORK/b003/_x009.o -g -O2 -lpthread TERM='dumb' /usr/local/opt/go/libexec/pkg/tool/darwin_amd64/cgo -dynpackage cgo -dynimport $WORK/b003/_cgo_.o -dynout $WORK/b003/_cgo_import.go -dynlinker github.com/sinlov/cgo-compile-test mkdir -p $WORK/b001/ TERM='dumb' CGO_LDFLAGS='"-g" "-O2"' /usr/local/opt/go/libexec/pkg/tool/darwin_amd64/cgo -objdir $WORK/b001/ -importpath github.com/sinlov/cgo-compile-test -exportheader=$WORK/b001/_cgo_install.h -- -I $WORK/b001/ -g -O2 ./test.go cd $WORK/b001 TERM='dumb' clang -I /Users/sinlov/go/src/github.com/sinlov/cgo-compile-test -fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=$WORK/b001=/tmp/go-build -gno-record-gcc-switches -fno-common -I ./ -g -O2 -o ./_x001.o -c _cgo_export.c TERM='dumb' clang -I /Users/sinlov/go/src/github.com/sinlov/cgo-compile-test -fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=$WORK/b001=/tmp/go-build -gno-record-gcc-switches -fno-common -I ./ -g -O2 -o ./_x002.o -c test.cgo2.c cd /Users/sinlov/go/src/github.com/sinlov/cgo-compile-test TERM='dumb' clang -I . -fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=$WORK/b001=/tmp/go-build -gno-record-gcc-switches -fno-common -I $WORK/b001/ -g -O2 -o $WORK/b001/_x003.o -c test.c cd $WORK/b001 TERM='dumb' clang -I /Users/sinlov/go/src/github.com/sinlov/cgo-compile-test -fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=$WORK/b001=/tmp/go-build -gno-record-gcc-switches -fno-common -I ./ -g -O2 -o ./_cgo_main.o -c _cgo_main.c cd /Users/sinlov/go/src/github.com/sinlov/cgo-compile-test TERM='dumb' clang -I . -fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=$WORK/b001=/tmp/go-build -gno-record-gcc-switches -fno-common -o $WORK/b001/_cgo_.o $WORK/b001/_cgo_main.o $WORK/b001/_x001.o $WORK/b001/_x002.o $WORK/b001/_x003.o -g -O2 TERM='dumb' /usr/local/opt/go/libexec/pkg/tool/darwin_amd64/cgo -dynpackage main -dynimport $WORK/b001/_cgo_.o -dynout $WORK/b001/_cgo_import.go cat >$WORK/b001/importcfg.link << 'EOF' # internal packagefile github.com/sinlov/cgo-compile-test=/Users/sinlov/Library/Caches/go-build/b2/b2db1fef79f3c9f737d7f56e4495b56bf47a6f77696afeada7c3520e9f7bc673-d packagefile runtime/cgo=/usr/local/opt/go/libexec/pkg/darwin_amd64/runtime/cgo.a packagefile syscall=/usr/local/opt/go/libexec/pkg/darwin_amd64/syscall.a packagefile runtime=/usr/local/opt/go/libexec/pkg/darwin_amd64/runtime.a packagefile errors=/usr/local/opt/go/libexec/pkg/darwin_amd64/errors.a packagefile internal/bytealg=/usr/local/opt/go/libexec/pkg/darwin_amd64/internal/bytealg.a packagefile internal/oserror=/usr/local/opt/go/libexec/pkg/darwin_amd64/internal/oserror.a packagefile internal/race=/usr/local/opt/go/libexec/pkg/darwin_amd64/internal/race.a packagefile internal/unsafeheader=/usr/local/opt/go/libexec/pkg/darwin_amd64/internal/unsafeheader.a packagefile sync=/usr/local/opt/go/libexec/pkg/darwin_amd64/sync.a packagefile internal/cpu=/usr/local/opt/go/libexec/pkg/darwin_amd64/internal/cpu.a packagefile runtime/internal/atomic=/usr/local/opt/go/libexec/pkg/darwin_amd64/runtime/internal/atomic.a packagefile runtime/internal/math=/usr/local/opt/go/libexec/pkg/darwin_amd64/runtime/internal/math.a packagefile runtime/internal/sys=/usr/local/opt/go/libexec/pkg/darwin_amd64/runtime/internal/sys.a packagefile internal/reflectlite=/usr/local/opt/go/libexec/pkg/darwin_amd64/internal/reflectlite.a packagefile sync/atomic=/usr/local/opt/go/libexec/pkg/darwin_amd64/sync/atomic.a EOF mkdir -p $WORK/b001/exe/ cd . /usr/local/opt/go/libexec/pkg/tool/darwin_amd64/link -o $WORK/b001/exe/a.out.a -importcfg $WORK/b001/importcfg.link -buildmode=c-archive -buildid=GQgLEw2NNKSfGEpQ0X-r/VQDz2ODp5rNZWw3EAb92/1Koj8_yhn6nSb56-DPwb/GQgLEw2NNKSfGEpQ0X-r -w -extld=clang /Users/sinlov/Library/Caches/go-build/b2/b2db1fef79f3c9f737d7f56e4495b56bf47a6f77696afeada7c3520e9f7bc673-d /usr/local/opt/go/libexec/pkg/tool/darwin_amd64/buildid -w $WORK/b001/exe/a.out.a # internal # $WORK/b001/_cgo_install.h not created mv $WORK/b001/exe/a.out.a test.a rm -r $WORK/b001/file test.a
test.a: current ar archive
objdump -a test.a
In archive test.a:go.o: file format mach-o-x86-64
rw-r--r-- 0/0 1058800 Jan 1 08:00 1970 go.o000000.o: file format mach-o-x86-64
rw-r--r-- 0/0 680 Jan 1 08:00 1970 000000.o000001.o: file format mach-o-x86-64
rw-r--r-- 0/0 2420 Jan 1 08:00 1970 000001.o000002.o: file format mach-o-x86-64
rw-r--r-- 0/0 2084 Jan 1 08:00 1970 000002.o000003.o: file format mach-o-x86-64
rw-r--r-- 0/0 680 Jan 1 08:00 1970 000003.o000004.o: file format mach-o-x86-64
rw-r--r-- 0/0 680 Jan 1 08:00 1970 000004.o000005.o: file format mach-o-x86-64
rw-r--r-- 0/0 2864 Jan 1 08:00 1970 000005.o000006.o: file format mach-o-x86-64
rw-r--r-- 0/0 7776 Jan 1 08:00 1970 000006.o000007.o: file format mach-o-x86-64
rw-r--r-- 0/0 10168 Jan 1 08:00 1970 000007.o000008.o: file format mach-o-x86-64
rw-r--r-- 0/0 2852 Jan 1 08:00 1970 000008.o000009.o: file format mach-o-x86-64
rw-r--r-- 0/0 3200 Jan 1 08:00 1970 000009.o000010.o: file format mach-o-x86-64
rw-r--r-- 0/0 3820 Jan 1 08:00 1970 000010.o000011.o: file format mach-o-x86-64
rw-r--r-- 0/0 1080 Jan 1 08:00 1970 000011.o