Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net: "cgoAvailable redeclared in this block" when using "-tags:netgo", Windows and go 1.21rc2 #61153

Closed
neclepsio opened this issue Jul 3, 2023 · 6 comments
Assignees
Labels
NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Milestone

Comments

@neclepsio
Copy link

What version of Go are you using (go version)?

$ go version
go version go1.21rc2 windows/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
set GO111MODULE=on
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\---\AppData\Local\go-build
set GOENV=C:\Users\---\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=c:\---\Go-Modules\pkg\mod
set GONOPROXY=neclepsio.example/*
set GONOSUMDB=neclepsio.example/*
set GOOS=windows
set GOPATH=c:\Ignazio\Personale\Go-Modules
set GOPRIVATE=neclepsio.example/*
set GOPROXY=direct
set GOROOT=c:\Ignazio\Lavoro\IgnPack\Go\go1.21rc2
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=c:\---\go1.21rc2\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.21rc2
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=---
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=-Wno-stringop-overflow
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\---\AppData\Local\Temp\go-build2402352097=/tmp/go-build -gno-record-gcc-switches

What did you do?

package main

import (
	"fmt"
	"net"
)

func main() {
	fmt.Println(net.FlagUp)
}

Compiled with:

go build -tags netgo

What did you expect to see?

No error.

What did you see instead?

c:\---\go1.21rc2\src\net\lookup_windows.go:20:7: cgoAvailable redeclared in this block
        c:\---\go1.21rc2\src\net\cgo_stub.go:19:7: other declaration of cgoAvailable
@neclepsio neclepsio changed the title go/build: "cgoAvailable redeclared in this block" when using -tags:netgo ang go 1.21rc2 go/build: "cgoAvailable redeclared in this block" when using "-tags:netgo", Windows and go 1.21rc2 Jul 3, 2023
@neclepsio neclepsio changed the title go/build: "cgoAvailable redeclared in this block" when using "-tags:netgo", Windows and go 1.21rc2 net: "cgoAvailable redeclared in this block" when using "-tags:netgo", Windows and go 1.21rc2 Jul 3, 2023
@mateusz834
Copy link
Member

Thanks for the report, there is a issue with build tags after CL 487196

@mateusz834
Copy link
Member

This issue also applies to plan9:

[mateusz@arch src (net-restrict-cgo-stub-to-unix)]$ GOOS=plan9 go test net -tags netgo
# net [net.test]
net/lookup_plan9.go:19:7: cgoAvailable redeclared in this block
        net/cgo_stub.go:20:7: other declaration of cgoAvailable
FAIL    net [build failed]
FAIL

@gopherbot
Copy link

Change https://go.dev/cl/507636 mentions this issue: net: restrict cgo_stubs.go netgo with unix build tag

@ianlancetaylor ianlancetaylor added this to the Go1.21 milestone Jul 3, 2023
@ianlancetaylor ianlancetaylor added NeedsFix The path to resolution is known, but the work has not been done. release-blocker labels Jul 3, 2023
@gopherbot
Copy link

Change https://go.dev/cl/507655 mentions this issue: net: only build cgo_stub.go on unix or wasip1

@shenwei356
Copy link

I just also met this issue on Linux, doing cross-compile with

CGO_ENABLED=0 gox -os="windows darwin linux" -arch="386 amd64 arm64" -tags netgo -ldflags '-w -s' -asmflags '-trimpath'

Error:

--> windows/386 error: exit status 1
Stderr: # net
/usr/local/go/src/net/lookup_windows.go:20:7: cgoAvailable redeclared in this block
        /usr/local/go/src/net/cgo_stub.go:19:7: other declaration of cgoAvailable

--> windows/amd64 error: exit status 1
Stderr: # net
/usr/local/go/src/net/lookup_windows.go:20:7: cgoAvailable redeclared in this block
        /usr/local/go/src/net/cgo_stub.go:19:7: other declaration of cgoAvailable

@mateusz834
Copy link
Member

@shenwei356 it is already fixed on gotip

bradfitz pushed a commit to tailscale/go that referenced this issue Jul 15, 2023
We were building it for Windows, although Windows code never calls
any of these functions. When using -tags netgo that cause a multiple
definition of cgoAvailable.

Fixes golang#61153

Change-Id: Ib9e1de7720a8c0dacd6f12002917bf305dfa5405
Reviewed-on: https://go-review.googlesource.com/c/go/+/507655
Reviewed-by: Damien Neil <dneil@google.com>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants