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

cmd/link: build error with cgo in Windows, redefinition of go.map.zero #47185

Closed
xhit opened this issue Jul 14, 2021 · 15 comments
Closed

cmd/link: build error with cgo in Windows, redefinition of go.map.zero #47185

xhit opened this issue Jul 14, 2021 · 15 comments

Comments

@xhit
Copy link
Contributor

@xhit xhit commented Jul 14, 2021

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

$ go version
go version go1.16.6 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=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\santiago\AppData\Local\go-build
set GOENV=C:\Users\santiago\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\santiago\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\santiago\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Users\santiago\sdk\go1.16.6
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Users\santiago\sdk\go1.16.6\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.16.6
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\Users\santiago\Desktop\projects\dixer\go.mod
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\santiago\AppData\Local\Temp\go-build2382778749=/tmp/go-build -gno-record-gcc-switches

What did you do?

First, sorry for bad english. I'm still learning.

I'm trying to build Dixer ETL with go1.16.6 with SQLite3 driver github.com/mattn/go-sqlite3 (also with Godror github.com/godror/godror and DB2 driver github.com/ibmdb/go_ibm_db one by one) and get this error:

# sdi
C:\Users\santiago\sdk\go1.16.6\pkg\tool\windows_amd64\link.exe: running gcc failed: exit status 1
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\santiago\AppData\Local\Temp\go-link-302307315\go.o:(.rdata+0x522468): multiple definition of `go.map.zero'; C:\Users\santiago\AppData\Local\Temp\go-link-302307315\go.o:(.rdata+0x527e70): first defined here
collect2.exe: error: ld returned

I'm trying to get a sample code but I can't replicate it yet, but I can reproduce it in the project easily.

I'm using Windows 10 with gcc in MSYS2. Same project can build without problems with go1.16.5

To get the build error, I only need to catch the error from a function, sample code:

var dbConnection ConnDB

	var err error

	dbConnection.DBConfig.Type = dbType

	if dbType == cid.SQLITE3 {
		dbConnection.DBConfig.Database, err = exprfunc.GetStringVarValue(c.DatabaseVar, c.Database)
		if err != nil {
			return nil, err
		}
	}

The GetStringVarValue function in exprfunc package reduced to get the error is:

func GetStringVarValue(varName string, valueIfEmpty string) (string, error) {
	return valueIfEmpty, nil
}

The success build is when I ignore the error. Using first code block is possible build with this:

	var dbConnection ConnDB

	// var err error

	dbConnection.DBConfig.Type = dbType

	if dbType == cid.SQLITE3 {
		dbConnection.DBConfig.Database, _ = exprfunc.GetStringVarValue(c.DatabaseVar, c.Database)
		// if err != nil {
		// 	return nil, err
		// }
	}

I reduced to minimal the project but I only catch the error in main project. So the success build I can only get ignoring the error. I can share the code reduced to minimal to provide the project struct if needed despite build is success.

The build error only happens when I load a package that require CGO enabled and only happens in Windows amd64. I can build successfully in Linux amd64, arm64 and macOS amd64.

A simple go build trigger the error.

I though the building machine have problems, so I reinstall in another virtual machine and a laptop. Same error.

What did you expect to see?

Build success.

What did you see instead?

# sdi
C:\Users\santiago\sdk\go1.16.6\pkg\tool\windows_amd64\link.exe: running gcc failed: exit status 1
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\santiago\AppData\Local\Temp\go-link-302307315\go.o:(.rdata+0x522468): multiple definition of `go.map.zero'; C:\Users\santiago\AppData\Local\Temp\go-link-302307315\go.o:(.rdata+0x527e70): first defined here
collect2.exe: error: ld returned
@cherrymui
Copy link
Contributor

@cherrymui cherrymui commented Jul 14, 2021

Thanks for report. Could you paste the build command you run and the output of go build -x -ldflags=-v? Thanks.

Loading

@xhit
Copy link
Contributor Author

@xhit xhit commented Jul 14, 2021

go build -x -ldflags=-v Output
$ go build -x -ldflags=-v
WORK=C:\Users\SDELAC~1\AppData\Local\Temp\go-build1667433969
mkdir -p $WORK\b001\
cat >$WORK\b001\importcfg.link << 'EOF' # internal
packagefile sdi=C:\Users\sdelacruz\AppData\Local\go-build\49\49f46e16d4965c3e64ba02596abd1594b8d836880b6dde3761a48a6c33244755-d
packagefile bufio=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\bufio.a
packagefile bytes=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\bytes.a
packagefile database/sql=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\database\sql.a
packagefile encoding/base64=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\encoding\base64.a
packagefile encoding/json=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\encoding\json.a
packagefile errors=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\errors.a
packagefile fmt=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\fmt.a
packagefile github.com/360EntSecGroup-Skylar/excelize/v2=C:\Users\sdelacruz\AppData\Local\go-build\cf\cfd873cae485c8b99cea7c851de00190a4a3da28459ef6ed171ff202b1f5aab8-d
packagefile github.com/SAP/go-hdb/driver=C:\Users\sdelacruz\AppData\Local\go-build\f2\f2c6fbdbdb6f9d1ab0985f4babbdadaae5a1467e7b8d442b24e59002812343af-d
packagefile github.com/antonmedv/expr/vm=C:\Users\sdelacruz\AppData\Local\go-build\aa\aa924bfb787a7782ab91ab6be450e1c4f8eaa47b05a32fe86b95ae69e2a29ee8-d
packagefile github.com/joho/godotenv=C:\Users\sdelacruz\AppData\Local\go-build\0b\0b6cc237aeef15b2fb54439f891f39d23f2093b0ad7a2f3256b828a77d799bd8-d
packagefile github.com/pelletier/go-toml=C:\Users\sdelacruz\AppData\Local\go-build\da\da4c3614945a0511592a9811562147c359a4fee14935407a535007820aa85bf8-d
packagefile github.com/shopspring/decimal=C:\Users\sdelacruz\AppData\Local\go-build\bc\bcd524ae9f49424318000ff47a00f1d2615f09f7fe0884c55a479363207546ff-d
packagefile github.com/tamerh/jsparser=C:\Users\sdelacruz\AppData\Local\go-build\a9\a934ac24299e3ef110009778c27f9f73ed775731db66b6d5de6aa332d903753a-d
packagefile github.com/tamerh/xml-stream-parser=C:\Users\sdelacruz\AppData\Local\go-build\f4\f40c85d8bb135f430393800c47395e2012bee1aecf9f90010b572110e373075a-d
packagefile github.com/xhit/go-mssqldb=C:\Users\sdelacruz\AppData\Local\go-build\5c\5c00dd680c2806d28012cc1ac3d2ccfe6a7ff449d1fcb459218fe3200c31dd94-d
packagefile github.com/xhit/pq=C:\Users\sdelacruz\AppData\Local\go-build\a6\a6b83e9078c4b6f05b3e3cb6aa1cc6be04abf314eb43e4ac16440e54ff633dbc-d
packagefile gopkg.in/yaml.v2=C:\Users\sdelacruz\AppData\Local\go-build\3a\3a76e9769fa5db45e462d950bb5245816a0edea94810ca02545ada55585623ff-d
packagefile html=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\html.a
packagefile io=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\io.a
packagefile math/big=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\math\big.a
packagefile os=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\os.a
packagefile reflect=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\reflect.a
packagefile regexp=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\regexp.a
packagefile runtime=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\runtime.a
packagefile runtime/debug=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\runtime\debug.a
packagefile sdi/connection=C:\Users\sdelacruz\AppData\Local\go-build\8a\8aba53d12785512417cd763ab8ebc11fd9e9dac7cecc36aa7473faf809d821d8-d
packagefile sdi/connection/cid=C:\Users\sdelacruz\AppData\Local\go-build\09\09db94650a1c5d6fc4d377f0c8af08a8239806c4b7353e428223c5610e6ac8cf-d
packagefile sdi/db=C:\Users\sdelacruz\AppData\Local\go-build\27\27b971fa6f10960e2432480874fc6d7b7089898923f93ede9d0a1403d80af434-d
packagefile sdi/dbimport=C:\Users\sdelacruz\AppData\Local\go-build\83\837b24eb2fc54f5d80fe64f16a0d97496bbe16b2a6dd09445da8a1b12b0c0711-d
packagefile sdi/destdt=C:\Users\sdelacruz\AppData\Local\go-build\b7\b7aac5c302ab249567750050b2343b2c35c7ba051d868c731f316ff8056e8f96-d
packagefile sdi/encoding=C:\Users\sdelacruz\AppData\Local\go-build\64\64fe50baf06b6aa8a908706651bd2e4a4d140b645c8b1b5d10bcbba346e694bc-d
packagefile sdi/encoding/csv=C:\Users\sdelacruz\AppData\Local\go-build\89\89f4c72c81f24e1944c38b35548fc651cfdf53e32d2b11007bf3c184803aab80-d
packagefile sdi/encryption=C:\Users\sdelacruz\AppData\Local\go-build\f4\f4d6c6d86eec02a0ed000d1098d1dd238f34ff9fec4f9f5212f765bba7ebeb8c-d
packagefile sdi/errorcode=C:\Users\sdelacruz\AppData\Local\go-build\9b\9b583d6ee9a13812b9db59bb5e949015f80705535504187f1cfae5f8f56f0640-d
packagefile sdi/exprfunc=C:\Users\sdelacruz\AppData\Local\go-build\26\26b81b704035fcd8edb9cfa1ccc2e96b295c43b90b9f0f7938455787a8b32137-d
packagefile sdi/fieldparse=C:\Users\sdelacruz\AppData\Local\go-build\e3\e346c58c5cdecbcd162904d6888c8b2e7f6caea57bcd70ce9d5ca243e612b41d-d
packagefile sdi/logger=C:\Users\sdelacruz\AppData\Local\go-build\c4\c4e6d9e2789dad58571abfcfa617e57e88e02a6285eba5eb12364d75cc389a48-d
packagefile sdi/util=C:\Users\sdelacruz\AppData\Local\go-build\27\27a17c13407ccacba9d5d751dd9e0b8c6d80643b446ac80af2190ba0fcb919e0-d
packagefile strconv=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\strconv.a
packagefile strings=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\strings.a
packagefile time=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\time.a
packagefile unicode/utf8=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\unicode\utf8.a
packagefile internal/bytealg=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\internal\bytealg.a
packagefile unicode=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\unicode.a
packagefile context=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\context.a
packagefile database/sql/driver=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\database\sql\driver.a
packagefile sort=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\sort.a
packagefile sync=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\sync.a
packagefile sync/atomic=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\sync\atomic.a
packagefile encoding/binary=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\encoding\binary.a
packagefile encoding=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\encoding.a
packagefile math=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\math.a
packagefile unicode/utf16=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\unicode\utf16.a
packagefile internal/reflectlite=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\internal\reflectlite.a
packagefile internal/fmtsort=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\internal\fmtsort.a
packagefile archive/zip=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\archive\zip.a
packagefile container/list=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\container\list.a
packagefile crypto/aes=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\crypto\aes.a
packagefile crypto/cipher=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\crypto\cipher.a
packagefile crypto/hmac=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\crypto\hmac.a
packagefile crypto/md5=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\crypto\md5.a
packagefile crypto/sha1=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\crypto\sha1.a
packagefile crypto/sha256=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\crypto\sha256.a
packagefile crypto/sha512=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\crypto\sha512.a
packagefile encoding/xml=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\encoding\xml.a
packagefile github.com/mohae/deepcopy=C:\Users\sdelacruz\AppData\Local\go-build\ae\ae28f30659d7ae54e26d9b3c52d609bc8fa4fa83b9b7145f502d9c9052861ed1-d
packagefile github.com/richardlehane/mscfb=C:\Users\sdelacruz\AppData\Local\go-build\19\196e8e5d6390f267b9ed9d0fc79cb877b0149e0c744ffb0e560423a2325d38fe-d
packagefile github.com/xuri/efp=C:\Users\sdelacruz\AppData\Local\go-build\83\8312059cb03cb94432027af4731803dff75c527d49c98ce8aa1ffcdf62643c4b-d
packagefile golang.org/x/crypto/md4=C:\Users\sdelacruz\AppData\Local\go-build\c0\c081801181e788be23e649c398aad33926f46c8270cab6631a2924ca06ca8d90-d
packagefile golang.org/x/crypto/ripemd160=C:\Users\sdelacruz\AppData\Local\go-build\77\774649f5c9b80e9edd0f5a2b0b0aa18adf9c54faa7bb5ad5f74a2bd700ce7785-d
packagefile golang.org/x/net/html/charset=C:\Users\sdelacruz\AppData\Local\go-build\26\26befe454063dbcabfb5e8afb34c718a966322680d8864f33bf4217be51367df-d
packagefile golang.org/x/text/encoding/unicode=C:\Users\sdelacruz\AppData\Local\go-build\ac\ac6990ac6ddf68791b8aed7a9f29e909d87bbc28435f6149ced66a066052c29b-d
packagefile golang.org/x/text/language=C:\Users\sdelacruz\AppData\Local\go-build\d6\d6db57f19f2fd16d7ffbe36ee104f7f83564ce95b2b87209a51c1fd17c98a92d-d
packagefile golang.org/x/text/message=C:\Users\sdelacruz\AppData\Local\go-build\1a\1a3c5ae5c259d921614114066944d0ad169229f4cb2bc4ba0f536d54089f2f88-d
packagefile hash=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\hash.a
packagefile image=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\image.a
packagefile image/color=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\image\color.a
packagefile io/ioutil=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\io\ioutil.a
packagefile log=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\log.a
packagefile math/cmplx=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\math\cmplx.a
packagefile math/rand=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\math\rand.a
packagefile net/url=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\net\url.a
packagefile path=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\path.a
packagefile path/filepath=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\path\filepath.a
packagefile crypto/tls=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\crypto\tls.a
packagefile crypto/x509=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\crypto\x509.a
packagefile github.com/SAP/go-hdb/driver/dial=C:\Users\sdelacruz\AppData\Local\go-build\f3\f3aa5dc58ab35624c7e65ab5b376084b321e06672027e1d8d48ed63828455a05-d
packagefile github.com/SAP/go-hdb/driver/hdb=C:\Users\sdelacruz\AppData\Local\go-build\05\053da36e436502fc1ff2ba437ec76da8cd000fcc07f58627835d5bf98f8bb7f8-d
packagefile github.com/SAP/go-hdb/driver/internal/container/vermap=C:\Users\sdelacruz\AppData\Local\go-build\18\18ddcb39f2859914b5da3c95308930cdeda7572bf94358bbc1e194dd424c17b2-d
packagefile github.com/SAP/go-hdb/driver/internal/protocol=C:\Users\sdelacruz\AppData\Local\go-build\8f\8fb96e6cf631857b8c2db1fbff5d5712de63ea73bfb5ba72ecb66495ff32d773-d
packagefile github.com/SAP/go-hdb/driver/internal/protocol/scanner=C:\Users\sdelacruz\AppData\Local\go-build\b1\b1c55d06e5d3ed74a5c60141247c35f58f074a58a5ebbe56f1276aff0c1f6818-d
packagefile github.com/SAP/go-hdb/driver/internal/rand=C:\Users\sdelacruz\AppData\Local\go-build\39\39e83f429317dd8b7778c17954128b7377c1a2573aa0b86877fbfc4c4c1cef05-d
packagefile github.com/SAP/go-hdb/driver/sqltrace=C:\Users\sdelacruz\AppData\Local\go-build\2b\2b71cb0708a70c8d508cd406c5c9fa7cdc6c76a42793ed0beba72193fc2f4829-d
packagefile github.com/SAP/go-hdb/driver/unicode/cesu8=C:\Users\sdelacruz\AppData\Local\go-build\38\384cf53462ed018253fec7878fcb4b488045336c79cbee05a3f026f80b6a5671-d
packagefile golang.org/x/text/transform=C:\Users\sdelacruz\AppData\Local\go-build\f5\f5320a4a6f3336ac603967b42af3c46de48d632e00e204a8a13ba782ea752c84-d
packagefile net=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\net.a
packagefile github.com/antonmedv/expr/file=C:\Users\sdelacruz\AppData\Local\go-build\3a\3a84e51c611f20ef7140878d3c9c9f39269a16797e9fc969b54fccea3ccc6142-d
packagefile os/exec=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\os\exec.a
packagefile github.com/tamerh/xpath=C:\Users\sdelacruz\AppData\Local\go-build\b8\b807a2a02a37a0a25f4530275cc457103de2378486e3f7b035b57e22cf400c05-d
packagefile encoding/hex=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\encoding\hex.a
packagefile github.com/golang-sql/civil=C:\Users\sdelacruz\AppData\Local\go-build\61\61712163951c265edb4695a42d414b11de72adbc0a1c09928d9c369148a22a81-d
packagefile github.com/xhit/go-mssqldb/internal/cp=C:\Users\sdelacruz\AppData\Local\go-build\98\9834f67d546bd3f75a22a39c1baa7d30765ddf3e3e8b391c9875e7cb61f156c9-d
packagefile github.com/xhit/go-mssqldb/internal/decimal=C:\Users\sdelacruz\AppData\Local\go-build\73\73d19af2760c9ba0d6f318439f269e773376fd511afe22ac4b13079344e411fa-d
packagefile github.com/xhit/go-mssqldb/internal/querytext=C:\Users\sdelacruz\AppData\Local\go-build\82\823342f47bf082c58a5d6d7f012abd17a70415e854a6e0b1ba7383eb4e7f7a0a-d
packagefile github.com/xhit/go-mssqldb/msdsn=C:\Users\sdelacruz\AppData\Local\go-build\03\0391e7c837243b84c176d6590c04547eae9f82ef9933c7f3a0ec9aa07a60f652-d
packagefile syscall=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\syscall.a
packagefile github.com/xhit/pq/oid=C:\Users\sdelacruz\AppData\Local\go-build\d5\d534963aaf94b8632d3cb975ae9abc4d890cbe6e218ad63e11d4edd2f24f1e79-d
packagefile github.com/xhit/pq/scram=C:\Users\sdelacruz\AppData\Local\go-build\cb\cb610482dac9ecdad0d4120e3643f8fc3e740b0b87ff7149422a1fc1712a4079-d
packagefile os/user=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\os\user.a
packagefile internal/cpu=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\internal\cpu.a
packagefile math/bits=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\math\bits.a
packagefile internal/oserror=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\internal\oserror.a
packagefile internal/poll=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\internal\poll.a
packagefile internal/syscall/execenv=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\internal\syscall\execenv.a
packagefile internal/syscall/windows=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\internal\syscall\windows.a
packagefile internal/testlog=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\internal\testlog.a
packagefile io/fs=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\io\fs.a
packagefile internal/unsafeheader=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\internal\unsafeheader.a
packagefile regexp/syntax=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\regexp\syntax.a
packagefile runtime/internal/atomic=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\runtime\internal\atomic.a
packagefile runtime/internal/math=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\runtime\internal\math.a
packagefile runtime/internal/sys=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\runtime\internal\sys.a
packagefile github.com/xhit/go-simple-mail/v2=C:\Users\sdelacruz\AppData\Local\go-build\a5\a57299d840c52473e781ea66c41d53f2626f7600b878fff535be149fd49889ba-d
packagefile hash/fnv=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\hash\fnv.a
packagefile github.com/mattn/go-sqlite3=C:\Users\sdelacruz\AppData\Local\go-build\1e\1e1075c1d08aae93c282472d6a164fc198b2c47beb57b53896ea3b34f414c190-d
packagefile github.com/xhit/text/encoding/charmap=C:\Users\sdelacruz\AppData\Local\go-build\cd\cd005511fd01b345dba98abb666553b770272ae95c24319a77eb5c9428c86b26-d
packagefile github.com/xhit/text/encoding/unicode=C:\Users\sdelacruz\AppData\Local\go-build\e1\e112ad923f2861c1362070ed1d17089e7243cdfdfff3bdbbd478f6d38c3407da-d
packagefile github.com/xhit/text/transform=C:\Users\sdelacruz\AppData\Local\go-build\fe\fede248fc39c3193a91be18f9a5a4cc670cc1d5ef091f76dfdf2a6cb90341dcc-d
packagefile crypto/rand=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\crypto\rand.a
packagefile github.com/antonmedv/expr=C:\Users\sdelacruz\AppData\Local\go-build\c0\c0cc73c1723295c0555a82c845fb47b884d32edbb93d377a30fe3816577b358d-d
packagefile github.com/fatih/color=C:\Users\sdelacruz\AppData\Local\go-build\97\974d20cba755c32a709a7e87d45477a176def34d24b81937b96786fa71a34852-d
packagefile golang.org/x/term=C:\Users\sdelacruz\AppData\Local\go-build\65\65ae702eb20d4d09b1995bbcf8d1ff6f1c2b490842e91f9e591a4f1e7894f907-d
packagefile internal/syscall/windows/registry=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\internal\syscall\windows\registry.a
packagefile internal/race=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\internal\race.a
packagefile compress/flate=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\compress\flate.a
packagefile hash/crc32=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\hash\crc32.a
packagefile crypto/internal/subtle=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\crypto\internal\subtle.a
packagefile crypto/subtle=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\crypto\subtle.a
packagefile crypto=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\crypto.a
packagefile github.com/richardlehane/msoleps/types=C:\Users\sdelacruz\AppData\Local\go-build\f6\f6ee1294128aa8e034dac02843adcdf30d3d5d2e741d69e7e594e072825f4dd3-d
packagefile golang.org/x/net/html=C:\Users\sdelacruz\AppData\Local\go-build\89\8974445bcd26b7a7cb911344161e9798b041606260989c92ceef755a054fc0be-d
packagefile golang.org/x/text/encoding=C:\Users\sdelacruz\AppData\Local\go-build\bd\bd9789b831f1651378a2788f7cda42eeb5cbc7b5ae46d7bd565536b5c996118c-d
packagefile golang.org/x/text/encoding/charmap=C:\Users\sdelacruz\AppData\Local\go-build\12\12f0c980f9d1a698ac0b1b650ce33b3f6d7bacaba33f88890b6e9356e27f22b6-d
packagefile golang.org/x/text/encoding/htmlindex=C:\Users\sdelacruz\AppData\Local\go-build\bb\bb30245a3cc651d2a7f32f325676e3bae12001f7185a47dc677eafedf98a7c67-d
packagefile mime=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\mime.a
packagefile golang.org/x/text/encoding/internal=C:\Users\sdelacruz\AppData\Local\go-build\8f\8f90da1cda69d0d25883a81e225e717d644b8901c07598a01cb0608b3f759966-d
packagefile golang.org/x/text/encoding/internal/identifier=C:\Users\sdelacruz\AppData\Local\go-build\43\439d6fd264d2f14052311cf38ec3a6eef1a9eddf0f6d5d5058a4868fc57668b6-d
packagefile golang.org/x/text/internal/utf8internal=C:\Users\sdelacruz\AppData\Local\go-build\a6\a6b240279d02a7ed22f35dff328c6f07c6aadb15c790c37348df4af52d8567a2-d
packagefile golang.org/x/text/runes=C:\Users\sdelacruz\AppData\Local\go-build\3f\3f7e2ef314573335cd4791800a9859b17e7a45b8a74a5b9d10d235d2d2cf7256-d
packagefile golang.org/x/text/internal/language=C:\Users\sdelacruz\AppData\Local\go-build\4f\4f24f9575c229b70853c7ec2c3c1928e99bae8836802544ca3ea69fba6327375-d
packagefile golang.org/x/text/internal/language/compact=C:\Users\sdelacruz\AppData\Local\go-build\1c\1c0c55c498d55824c8a1d1513c0c08d4f0dd82623bbd905d055333b9f33e56fb-d
packagefile golang.org/x/text/feature/plural=C:\Users\sdelacruz\AppData\Local\go-build\36\36b9bd053181ebf915de165591de356ae10ba784ab4abb07a684d3373465a7d5-d
packagefile golang.org/x/text/internal/format=C:\Users\sdelacruz\AppData\Local\go-build\c5\c56267d7968ba92934d62ba6bc6030c869075bc774c4cc2851aec74fac01165c-d
packagefile golang.org/x/text/internal/number=C:\Users\sdelacruz\AppData\Local\go-build\af\af9ea7fb9e9c78097a0f58566b8e61c99576b6ca6a1b8aeec5eba68cd1b1c495-d
packagefile golang.org/x/text/message/catalog=C:\Users\sdelacruz\AppData\Local\go-build\4e\4ef6a5e807aa78fc2cb1ed75da3864c8614b0b4ee80b0a119b164f7ce5a59ea4-d
packagefile crypto/des=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\crypto\des.a
packagefile crypto/ecdsa=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\crypto\ecdsa.a
packagefile crypto/ed25519=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\crypto\ed25519.a
packagefile crypto/elliptic=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\crypto\elliptic.a
packagefile crypto/rc4=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\crypto\rc4.a
packagefile crypto/rsa=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\crypto\rsa.a
packagefile encoding/pem=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\encoding\pem.a
packagefile vendor/golang.org/x/crypto/chacha20poly1305=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\vendor\golang.org\x\crypto\chacha20poly1305.a
packagefile vendor/golang.org/x/crypto/cryptobyte=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\vendor\golang.org\x\crypto\cryptobyte.a
packagefile vendor/golang.org/x/crypto/curve25519=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\vendor\golang.org\x\crypto\curve25519.a
packagefile vendor/golang.org/x/crypto/hkdf=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\vendor\golang.org\x\crypto\hkdf.a
packagefile crypto/dsa=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\crypto\dsa.a
packagefile crypto/x509/pkix=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\crypto\x509\pkix.a
packagefile encoding/asn1=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\encoding\asn1.a
packagefile vendor/golang.org/x/crypto/cryptobyte/asn1=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\vendor\golang.org\x\crypto\cryptobyte\asn1.a
packagefile flag=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\flag.a
packagefile github.com/SAP/go-hdb/driver/internal/protocol/encoding=C:\Users\sdelacruz\AppData\Local\go-build\24\241845cf539150082b4199dce2d2f25d551c43d3b035183c4753ec2e7ff89787-d
packagefile golang.org/x/crypto/pbkdf2=C:\Users\sdelacruz\AppData\Local\go-build\d8\d891dbbedf3e2c89563bddbe90d1710e41ed24bf461af22521941a712a3b592d-d
packagefile vendor/golang.org/x/net/dns/dnsmessage=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\vendor\golang.org\x\net\dns\dnsmessage.a
packagefile internal/nettrace=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\internal\nettrace.a
packagefile internal/singleflight=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\internal\singleflight.a
packagefile internal/syscall/windows/sysdll=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\internal\syscall\windows\sysdll.a
packagefile mime/multipart=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\mime\multipart.a
packagefile mime/quotedprintable=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\mime\quotedprintable.a
packagefile net/mail=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\net\mail.a
packagefile net/textproto=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\net\textproto.a
packagefile runtime/cgo=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\runtime\cgo.a
packagefile github.com/xhit/text/encoding=C:\Users\sdelacruz\AppData\Local\go-build\5c\5cc53534bca1d5f9c3d90ba22ff00bd6f9994e575682abe0c16458d8885e2e7d-d
packagefile github.com/xhit/text/encoding/internal=C:\Users\sdelacruz\AppData\Local\go-build\9f\9fa158bcc97a49d9a785ea1f43813696a36a0aaa24bb7380ddacf95c9f71f68d-d
packagefile github.com/xhit/text/encoding/internal/identifier=C:\Users\sdelacruz\AppData\Local\go-build\a8\a88f6c4f09597707cbbdf1606eb113ade9c6c45d85a5a27a91034f529664477d-d
packagefile github.com/xhit/text/internal/utf8internal=C:\Users\sdelacruz\AppData\Local\go-build\33\3389ea36353c1c624b3aaedd54564bf3eb1018313feabd4934f7acd07674d1ac-d
packagefile github.com/xhit/text/runes=C:\Users\sdelacruz\AppData\Local\go-build\33\33af81793b836b36c5d8d6ff4225c16725af131dfbe8e0fbef8f084d6b1b6d7a-d
packagefile github.com/antonmedv/expr/ast=C:\Users\sdelacruz\AppData\Local\go-build\c9\c9dd1033b06950a149054a13116d8489c973514542d18851bff616595bb9669e-d
packagefile github.com/antonmedv/expr/checker=C:\Users\sdelacruz\AppData\Local\go-build\23\235972291542707af942bb1d4e509c1b035e97403580787516de4a22f02188f1-d
packagefile github.com/antonmedv/expr/compiler=C:\Users\sdelacruz\AppData\Local\go-build\b5\b57d8d0bda7b3b1c103f3b8faaa98c866179b1f7936babe76f8b792925b7e2e7-d
packagefile github.com/antonmedv/expr/conf=C:\Users\sdelacruz\AppData\Local\go-build\f3\f3713cb04ae4d439619a79bb3b0b22cfcbc9c006149d3d7a5bdf4200957b9259-d
packagefile github.com/antonmedv/expr/optimizer=C:\Users\sdelacruz\AppData\Local\go-build\95\95c9d1935ddcd30c8ab35bd6426f4431fab3810937e73e455ea561412ca19d7a-d
packagefile github.com/antonmedv/expr/parser=C:\Users\sdelacruz\AppData\Local\go-build\0c\0c763e33df742aa6288fd7c70e7b7ca1b37d3d24ebafabf2144333df0d272e18-d
packagefile github.com/mattn/go-colorable=C:\Users\sdelacruz\AppData\Local\go-build\23\23b6faf5e8089980971a4cf8dcf22c38caf571f69fc48b382484963c4c936da7-d
packagefile github.com/mattn/go-isatty=C:\Users\sdelacruz\AppData\Local\go-build\ee\eeb48d07bec77469870188e04fb2b93c92a6e80b1033f7b2e01bb0fa5112eb89-d
packagefile golang.org/x/sys/windows=C:\Users\sdelacruz\AppData\Local\go-build\a2\a21f8fea9b2e88aa98aaa3bb3d551e211937183cbeb98c6832cda261ced1f697-d
packagefile golang.org/x/net/html/atom=C:\Users\sdelacruz\AppData\Local\go-build\3b\3b7bffa0f70f6b541be234165f34edd75fae335f4fcaf6946d85f4fa3f737f5f-d
packagefile golang.org/x/text/encoding/japanese=C:\Users\sdelacruz\AppData\Local\go-build\33\33a7bcf0e15840715ffdb5a2340b007e8679a170aed6b5210184f3a3bb7dff6a-d
packagefile golang.org/x/text/encoding/korean=C:\Users\sdelacruz\AppData\Local\go-build\2b\2bd009399092fad8c00b0c0af3e9c1d42d18392f800ad8c255654a53ca46d192-d
packagefile golang.org/x/text/encoding/simplifiedchinese=C:\Users\sdelacruz\AppData\Local\go-build\c8\c88c6d799d91d94c90134380110c0d6220ab3e2fe625cb9195d86ea5ad51ea88-d
packagefile golang.org/x/text/encoding/traditionalchinese=C:\Users\sdelacruz\AppData\Local\go-build\ff\ff460b37b619b88dd5430627897ed7a02fdcedf88e09daaf5d459997a89c36dc-d
packagefile golang.org/x/text/internal/tag=C:\Users\sdelacruz\AppData\Local\go-build\44\44ffcb5104a73c57bdda1bf6d2f40049361df7856c4afb083f239ad674781f10-d
packagefile golang.org/x/text/internal/catmsg=C:\Users\sdelacruz\AppData\Local\go-build\40\4021dd6b514bc70eed6ebb63ea1a7d4747650cca1863d5068fd0025146ca794a-d
packagefile golang.org/x/text/internal/stringset=C:\Users\sdelacruz\AppData\Local\go-build\7e\7ead4cae0f3500a59ee7ee5d08a1acc64ed08073eab55bb4302cd45d89f3f398-d
packagefile golang.org/x/text/internal=C:\Users\sdelacruz\AppData\Local\go-build\f0\f00965e621d8689421f6a1d017ccbb6d37560a09df8208da3048a37eef0e8246-d
packagefile crypto/internal/randutil=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\crypto\internal\randutil.a
packagefile crypto/ed25519/internal/edwards25519=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\crypto\ed25519\internal\edwards25519.a
packagefile vendor/golang.org/x/crypto/chacha20=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\vendor\golang.org\x\crypto\chacha20.a
packagefile vendor/golang.org/x/crypto/internal/subtle=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\vendor\golang.org\x\crypto\internal\subtle.a
packagefile vendor/golang.org/x/crypto/poly1305=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\vendor\golang.org\x\crypto\poly1305.a
packagefile vendor/golang.org/x/sys/cpu=C:\Users\sdelacruz\sdk\go1.16.6\pkg\windows_amd64\vendor\golang.org\x\sys\cpu.a
packagefile github.com/antonmedv/expr/parser/lexer=C:\Users\sdelacruz\AppData\Local\go-build\00\001807c2f2f5c1cb5b18170471e4c9b824452db4ab29a6d2218924600d4b6b5b-d
packagefile golang.org/x/sys/internal/unsafeheader=C:\Users\sdelacruz\AppData\Local\go-build\9b\9bc13006254e5f26d78254f7c7266710e082d85028f04d1d87d35a89e06ca06e-d
EOF
mkdir -p $WORK\b001\exe\
cd .
"C:\\Users\\sdelacruz\\sdk\\go1.16.6\\pkg\\tool\\windows_amd64\\link.exe" -o "$WORK\\b001\\exe\\a.out.exe" -importcfg "$WORK\\b001\\importcfg.link" -buildmode=pie -buildid=BHtShqBFjPvN8OCZY8LD/3s_pB2N0H-No4GwbyQM7/JrfyyQ5Pxm4T9wJx0ffX/BHtShqBFjPvN8OCZY8LD -v -extld=gcc "C:\\Users\\sdelacruz\\AppData\\Local\\go-build\\49\\49f46e16d4965c3e64ba02596abd1594b8d836880b6dde3761a48a6c33244755-d"
# sdi
HEADER = -H10 -T0xffffffffffffffff -R0xffffffff
host link: "gcc" "-m64" "-mconsole" "-Wl,--tsaware" "-Wl,--nxcompat" "-Wl,--major-os-version=6" "-Wl,--minor-os-version=1" "-Wl,--major-subsystem-version=6" "-Wl,--minor-subsystem-version=1" "-Wl,--dynamicbase" "-Wl,--high-entropy-va" "-o" "C:\\Users\\SDELAC~1\\AppData\\Local\\Temp\\go-build1667433969\\b001\\exe\\a.out.exe" "C:\\Users\\SDELAC~1\\AppData\\Local\\Temp\\go-link-869185431\\go.o" "C:\\Users\\SDELAC~1\\AppData\\Local\\Temp\\go-link-869185431\\000000.o" "C:\\Users\\SDELAC~1\\AppData\\Local\\Temp\\go-link-869185431\\000001.o" "C:\\Users\\SDELAC~1\\AppData\\Local\\Temp\\go-link-869185431\\000002.o" "C:\\Users\\SDELAC~1\\AppData\\Local\\Temp\\go-link-869185431\\000003.o" "C:\\Users\\SDELAC~1\\AppData\\Local\\Temp\\go-link-869185431\\000004.o" "C:\\Users\\SDELAC~1\\AppData\\Local\\Temp\\go-link-869185431\\000005.o" "C:\\Users\\SDELAC~1\\AppData\\Local\\Temp\\go-link-869185431\\000006.o" "C:\\Users\\SDELAC~1\\AppData\\Local\\Temp\\go-link-869185431\\000007.o" "C:\\Users\\SDELAC~1\\AppData\\Local\\Temp\\go-link-869185431\\000008.o" "C:\\Users\\SDELAC~1\\AppData\\Local\\Temp\\go-link-869185431\\000009.o" "C:\\Users\\SDELAC~1\\AppData\\Local\\Temp\\go-link-869185431\\000010.o" "C:\\Users\\SDELAC~1\\AppData\\Local\\Temp\\go-link-869185431\\000011.o" "C:\\Users\\SDELAC~1\\AppData\\Local\\Temp\\go-link-869185431\\000012.o" "C:\\Users\\SDELAC~1\\AppData\\Local\\Temp\\go-link-869185431\\000013.o" "C:\\Users\\SDELAC~1\\AppData\\Local\\Temp\\go-link-869185431\\000014.o" "C:\\Users\\SDELAC~1\\AppData\\Local\\Temp\\go-link-869185431\\000015.o" "C:\\Users\\SDELAC~1\\AppData\\Local\\Temp\\go-link-869185431\\000016.o" "C:\\Users\\SDELAC~1\\AppData\\Local\\Temp\\go-link-869185431\\000017.o" "C:\\Users\\SDELAC~1\\AppData\\Local\\Temp\\go-link-869185431\\000018.o" "C:\\Users\\SDELAC~1\\AppData\\Local\\Temp\\go-link-869185431\\000019.o" "-g" "-O2" "-lmingwex" "-lmingw32" "-g" "-O2" "-Wl,-T,C:\\Users\\SDELAC~1\\AppData\\Local\\Temp\\go-link-869185431\\fix_debug_gdb_scripts.ld" "-Wl,--start-group" "-lmingwex" "-lmingw32" "-Wl,--end-group" "-lkernel32"
C:\Users\sdelacruz\sdk\go1.16.6\pkg\tool\windows_amd64\link.exe: running gcc failed: exit status 1
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\SDELAC~1\AppData\Local\Temp\go-link-869185431\go.o:(.rdata+0x1d3e08): multiple definition of `go.map.zero'; C:\Users\SDELAC~1\AppData\Local\Temp\go-link-869185431\go.o:(.rdata+0x1d7f58): first defined here
collect2.exe: error: ld returned 1 exit status

Loading

@xhit
Copy link
Contributor Author

@xhit xhit commented Jul 14, 2021

I'm working in reproducible code. I will share it soon.

Loading

@cherrymui cherrymui changed the title build error with cgo in Windows cmd/link: build error with cgo in Windows, redefinition of go.map.zero Jul 14, 2021
@cherrymui cherrymui added this to the Backlog milestone Jul 14, 2021
@cherrymui
Copy link
Contributor

@cherrymui cherrymui commented Jul 14, 2021

Thanks. I'll look into it.

Also cc @thanm , if you happen to have some recent knowledge of redefinition of of go.map.zero.

Loading

@thanm
Copy link
Contributor

@thanm thanm commented Jul 14, 2021

https://go-review.googlesource.com/c/go/+/326211 seems like a possible culprit? Without having a reproducer it's hard to tell though. One way to tell would be to see if the same program builds ok with Go 1.16.5, since CL 326211 is only in the most recent.

Loading

@xhit
Copy link
Contributor Author

@xhit xhit commented Jul 15, 2021

From Go 1.13.5 to Go 1.16.5 builds fine.

The reproducible code: https://github.com/xhit/go-issue-47185

Loading

@thanm
Copy link
Contributor

@thanm thanm commented Jul 15, 2021

Thanks. I'll take a look this morning.

Loading

@thanm
Copy link
Contributor

@thanm thanm commented Jul 15, 2021

@xhit Thanks for reporting this problem.

It does indeed look as though the failure is with CL 326211; this fix isn't doing quite what it should.

Here is a detailed breakdown of what's going on, first recap of sorts for posterity:

The Go compiler + runtime implementation of maps utilitizes a "map zero" symbol in cases where a map lookup fails and we need a zero'd symbol whose size matches that of the map value type. Example:

  --- package p1 ---
  type A [8]float64
  ...
  m := make(map[int]A)
  x := m[0]
  
  --- package p2 ---
  type C [19]int64
  m := make(map[int]C)
  x := m[0]

When compiling package p1, the compiler (behind the scenes) generates a read-only data symbol "go.map.zero" of whose size is equal to the value type of the map (here "A"), so that the map lookup can read from it in the case that a given key is not in the map (as in "x := m[0]").

Similar thing happens when package p2 is compiled (another go.map.zero symbol is generated), but with a larger size, since type "C" takes up more size.

At link time what's supposed to happen is that the Go linker selects the single largest "go.map.zero" symbol (from all the incoming packages) and then rewrites all "go.map.zero" sym references to point to that symbol.

When we modernized the linker in the Go 1.15/1.16 timeframe, we wound up introducing a bug such that instead of selecting the largest go.map.zero, the linker would just pick an arbitrary instance. This bug was reported in issue #46653, the fix for which was CL 326211.

Turns out that the fix was buggy-- the linker was supposed to be selecting a single symbol, but instead it was carrying along all of the symbols. What appears to be happening on Linux is that the external linker doesn't seem to have a problem with the duplicates, whereas on Windows we get an error.

The original intent (as mentioned in the CL 326211 commit message) was that the larger symbol would be selected as result of this code here:

https://go.googlesource.com/go/+/ef8ae82b37657ab788f490bd757ad1b5592b952f/src/cmd/link/internal/loader/loader.go#438

however this was a misreading of the code -- while it looks as though it should cause the larger symbol to be selected, the blob in question only applies to hashed64 symbols and not regular hashed symbols. Although it appears that it runs for regular hashed symbols, it will never kick in due to this code in the object file writer:

https://go.googlesource.com/go/+/ef8ae82b37657ab788f490bd757ad1b5592b952f/src/cmd/internal/obj/objfile.go#434

which includes the size of the symbol in the hash (resulting in different hashes, hence we'll never get to the code above).

So: what happens on Linux is that we wind up with duplicate go.map.zero symbols; the linux linker doesn't seem to be bothered by the fact that we have two symbols with the same name. Example:

  $ rm issue46653 ; go build -ldflags="-linkmode=external"  .
  $ objdump -t issue46653 | fgrep go.map.zero
  000000000047a080 l     O .rodata	0000000000000420              go.map.zero
  000000000047ab50 l     O .rodata	0000000000001000              go.map.zero
  $

There is a final additional aggravating factor: in the regression test added for issue 46653, only one of the map.zero symbols turns out to be actually reachable (which is all you need it turns out). So this means that that test won't trigger the duplicate definition on Windows, which is why we didn't see this from the get-go ... sigh.

I think the right fix is to basically back out the change to convert go.map.zero to content-addressible and just use the same logic that was used in the fix that got back-ported to the 1.15 release. This will also have the side effect of producing less RODATA overall on linux.

Cherry let me know what you think about this and/or if you can think of a better fix.

Loading

@cherrymui
Copy link
Contributor

@cherrymui cherrymui commented Jul 15, 2021

Thanks for the repro and the analysis. Fixing the DUPOK symbol size using 1.15 logic SGTM.

I was thinking about it yesterday (without looking at code). Do/did we generate static symbols for content addressable symbols in the go.o for external linking? If so, duplicates should be okay. Maybe this is what we do for ELF but not PE? Maybe we should do it everywhere (if not already).

DUPOK symbols with different sizes are still concerning. I think it only makes sense if the extra bytes are all zeros. Is go.map.zero the only case that needs this logic? If so, I'd like to rethink it and use some better mechanism for long term.

That said, for short term (1.16 and 1.17), restoring the 1.15 logic is probably the best. Thanks.

Loading

@cherrymui cherrymui removed this from the Backlog milestone Jul 15, 2021
@cherrymui cherrymui added this to the Go1.17 milestone Jul 15, 2021
@thanm
Copy link
Contributor

@thanm thanm commented Jul 15, 2021

I was thinking about it yesterday (without looking at code). Do/did we generate static symbols for content addressable symbols in the go.o for external linking? If so, duplicates should be okay. Maybe this is what we do for ELF but not PE? Maybe we should do it everywhere (if not already).

Yes, symbols are static for ELF right now and I agree that going forward we should make sure they are static elsewhere (mac, windows, etc).

DUPOK symbols with different sizes are still concerning. I think it only makes sense if the extra bytes are all zeros. Is go.map.zero the only case that needs this logic? If so, I'd like to rethink it and use some better mechanism for long term.

My recollection is that we still have some DUPOK collisions where the payload is different, unfortunately (I seem to remember some cases with DWARF where this happens, due to slightly different FE source position handling in different packages). If we could clean this up it would be great.

Loading

@gopherbot
Copy link

@gopherbot gopherbot commented Jul 15, 2021

Change https://golang.org/cl/334930 mentions this issue: cmd/{compile,link}: fix bug in map.zero handling

Loading

@gopherbot gopherbot closed this in 49402be Jul 19, 2021
@cherrymui
Copy link
Contributor

@cherrymui cherrymui commented Jul 19, 2021

@gopherbot please open a backport for this to Go 1.16 release. This fixes a bug introduced in the previous point release.

Loading

@gopherbot
Copy link

@gopherbot gopherbot commented Jul 19, 2021

Backport issue(s) opened: #47289 (for 1.16).

Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://golang.org/wiki/MinorReleases.

Loading

@cherrymui
Copy link
Contributor

@cherrymui cherrymui commented Jul 19, 2021

No 1.15 backport, because it uses a different code path which does not have the issue.

Loading

@gopherbot
Copy link

@gopherbot gopherbot commented Jul 19, 2021

Change https://golang.org/cl/335629 mentions this issue: cmd/{compile,link}: fix bug in map.zero handling

Loading

steeve added a commit to znly/go that referenced this issue Aug 19, 2021
In CL 326211 a change was made to switch "go.map.zero" symbols from
non-pkg DUPOK symbols to hashed symbols. The intent of this change was
ensure that in cases where there are multiple competing go.map.zero
symbols feeding into a link, the largest map.zero symbol is selected.
The change was buggy, however, and resulted in duplicate symbols in
the final binary (see bug cited below for details). This duplication
was relatively benign for linux/ELF, but causes duplicate definition
errors on Windows.

This patch switches "go.map.zero" symbols back from hashed symbols to
non-pkg DUPOK symbols, and updates the relevant code in the loader to
ensure that we do the right thing when there are multiple competing
DUPOK symbols with different sizes.

Fixes golang#47185.

Change-Id: I8aeb910c65827f5380144d07646006ba553c9251
Reviewed-on: https://go-review.googlesource.com/c/go/+/334930
Trust: Than McIntosh <thanm@google.com>
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants