Go: runtime/race: __acrt_iob_func not defined building with -race on Windows

Created on 1 Feb 2018  Â·  39Comments  Â·  Source: golang/go

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

go version devel +6f37fee354 Wed Jan 31 22:12:10 2018 +0000 windows/amd64

Does this issue reproduce with the latest release?

No, maybe something wrong in recent commits.

What operating system and processor architecture are you using (go env)?

set GOARCH=amd64
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows

What did you do?

go test -race

What did you expect to see?

works

What did you see instead?

failed with following errors

runtime/cgo(.text): relocation target __acrt_iob_func not defined
runtime/cgo(.text): relocation target __acrt_iob_func not defined
runtime/cgo(.text): relocation target __acrt_iob_func not defined
runtime/cgo(.text): relocation target __acrt_iob_func not defined
runtime/cgo(.text): relocation target __acrt_iob_func not defined
runtime/cgo(.text): undefined: "__acrt_iob_func"
runtime/cgo(.text): undefined: "__acrt_iob_func"
runtime/cgo(.text): undefined: "__acrt_iob_func"
runtime/cgo(.text): undefined: "__acrt_iob_func"
runtime/cgo(.text): undefined: "__acrt_iob_func"
NeedsInvestigation OS-Windows RaceDetector help wanted

Most helpful comment

Workaround for this, try to add -ldflags="-linkmode=external" for build.

All 39 comments

In which directory are you running go test -race?

@ianlancetaylor anywhere can be possible.

$ mkdir %GOPATH%\src\github.com\mattn\foo
$ cd %GOPATH%\src\github.com\mattn\foo
$ cat > foo_test.go
package foo

import (
    "testing"
)

func TestSimple(t *testing.T) {
    got := 1
    want := 2
    if got != want {
        t.Fatalf("want %v, but %v:", want, got)
    }
}
^Z
$ go test -race
# github.com/mattn/foo (testmain)
runtime/cgo(.text): relocation target __acrt_iob_func not defined
runtime/cgo(.text): relocation target __acrt_iob_func not defined
runtime/cgo(.text): relocation target __acrt_iob_func not defined
runtime/cgo(.text): relocation target __acrt_iob_func not defined
runtime/cgo(.text): relocation target __acrt_iob_func not defined
runtime/cgo(.text): undefined: "__acrt_iob_func"
runtime/cgo(.text): undefined: "__acrt_iob_func"
runtime/cgo(.text): undefined: "__acrt_iob_func"
runtime/cgo(.text): undefined: "__acrt_iob_func"
runtime/cgo(.text): undefined: "__acrt_iob_func"
FAIL    github.com/mattn/foo [build failed]

Can you show us the output of go test -race -x?

The references may possibly be coming from runtime/race/race_windows_amd64.syso.

WORK=C:\Users\mattn\AppData\Local\Temp\go-build145566806
mkdir -p $WORK\b001\
mkdir -p $WORK\b052\
cat >$WORK\b052\vet.cfg << 'EOF' # internal
{
    "Compiler": "gc",
    "Dir": "c:\\dev\\go\\src\\github.com\\mattn\\foo",
    "GoFiles": [
        "c:\\dev\\go\\src\\github.com\\mattn\\foo\\foo_test.go"
    ],
    "ImportMap": {
        "fmt": "fmt",
        "testing": "testing"
    },
    "PackageFile": {
        "fmt": "C:\\Users\\mattn\\AppData\\Local\\go-build\\a3\\a3d8338a2cd5a66b9cd0ce3e19a2ba75cae2365147f3d65e37d2214eda7360a9-d",
        "testing": "C:\\Users\\mattn\\AppData\\Local\\go-build\\ed\\edcf0d2f0bf2ebf41c928d10bebf64e600e87fc72dd897c0951bb13dc86989ea-d"
    },
    "ImportPath": "github.com/mattn/foo",
    "SucceedOnTypecheckFailure": true
}
EOF
cd c:\dev\go\src\github.com\mattn\foo
"C:\\go\\pkg\\tool\\windows_amd64\\vet.exe" -atomic -bool -buildtags -nilfunc -printf "C:\\Users\\mattn\\AppData\\Local\\Temp\\go-build145566806\\b052\\vet.cfg"
cat >$WORK\b001\importcfg.link << 'EOF' # internal
packagefile github.com/mattn/foo (testmain)=C:\Users\mattn\AppData\Local\go-build\a1\a1cd7cb20a5f900d42bb15aed70e97bb42e4421b20bb2ee25b2ecf2e983957db-d
packagefile os=C:\Users\mattn\AppData\Local\go-build\83\837d4b3bdc415f8bcb91dcdabce57fa92c56b9518b71791e700f81d857e79e68-d
packagefile testing=C:\Users\mattn\AppData\Local\go-build\ed\edcf0d2f0bf2ebf41c928d10bebf64e600e87fc72dd897c0951bb13dc86989ea-d
packagefile testing/internal/testdeps=C:\Users\mattn\AppData\Local\go-build\ee\ee6f4653963b6916af2a304b23aac3a17080459df3fecf65dbd96759150078f6-d
packagefile runtime=C:\Users\mattn\AppData\Local\go-build\1e\1e02e966f3220ba3fa509fc0f88a1782dfab120d8d0140405537cbc5857bcd6e-d
packagefile runtime/race=C:\Users\mattn\AppData\Local\go-build\78\78c2b3fc30b8de4bf316f28c8f64417b6add42815c3f9e3e947f80b96e6d6c75-d
packagefile github.com/mattn/foo=C:\Users\mattn\AppData\Local\go-build\68\68f4246cdf49dc4424505adbe919adfcbb58be7b247c5cdbcc666f2c679dbcf2-d
packagefile errors=C:\Users\mattn\AppData\Local\go-build\68\68e3f9c288343074208dc9e0a266346ff7625e552ef829ada893db6628a51f8b-d
packagefile internal/poll=C:\Users\mattn\AppData\Local\go-build\b7\b7daed2c5d1cdfcf9f6480e996b73a0dd4433478e4dc8a4d3c6f747baae8c073-d
packagefile internal/syscall/windows=C:\Users\mattn\AppData\Local\go-build\13\13816b7dc009ed7c1e7274f912134c95e68ba9cc82a7031905c6b8b42c1f2891-d
packagefile internal/testlog=C:\Users\mattn\AppData\Local\go-build\f0\f0da1bc52eda632593bdb6d042a0fcd484fa373f29204ae36d41259241023492-d
packagefile io=C:\Users\mattn\AppData\Local\go-build\ca\ca0ff109878b733122cb5ac2fb576f5d6bb1652a7dde8e765dd65261156554ed-d
packagefile sync=C:\Users\mattn\AppData\Local\go-build\c1\c1ddb79625fec9aa4575933dbd316dba9b27d79555757941ede222d3cc6e4bb2-d
packagefile sync/atomic=C:\Users\mattn\AppData\Local\go-build\29\2937e911eec472bb2123d58af418e2da85468ba6ca3fd0a1533744f690356776-d
packagefile syscall=C:\Users\mattn\AppData\Local\go-build\2c\2c58e945883ab36d2410c5d364a63944cd39f0eaccbcfc4326a7b0778c854327-d
packagefile time=C:\Users\mattn\AppData\Local\go-build\45\4572e703e2c552c5d557caa54079f1f6074f059c277ae6567f51589f20c9643c-d
packagefile unicode/utf16=C:\Users\mattn\AppData\Local\go-build\6a\6a9a0523c33041ad28aa6b951f78b4940445672f274feca8c019afacf0594f16-d
packagefile bytes=C:\Users\mattn\AppData\Local\go-build\d0\d01cb1df3ed8d3f9e49d35230e43dce1ab928560bd37548fd1f859605b690d1b-d
packagefile flag=C:\Users\mattn\AppData\Local\go-build\8e\8e5a9f40700f231986b5fe7827befbc2dc832a33bf954a3555d941dc46370ec3-d
packagefile fmt=C:\Users\mattn\AppData\Local\go-build\a3\a3d8338a2cd5a66b9cd0ce3e19a2ba75cae2365147f3d65e37d2214eda7360a9-d
packagefile internal/race=C:\Users\mattn\AppData\Local\go-build\47\47969aa17e7eb3241750ed30f2cbd2fc100ad3ac7c4af97a47a0d28e678235e1-d
packagefile runtime/debug=C:\Users\mattn\AppData\Local\go-build\63\637b0a90189037487b87f9d8d1ab56aff367e6ef5c5cdf92ce9004551a13d6e8-d
packagefile runtime/trace=C:\Users\mattn\AppData\Local\go-build\cc\cc72603177f7f1a64234e4263075a00cb2a940d9de8ff935aaeee89f9c1a1b9a-d
packagefile sort=C:\Users\mattn\AppData\Local\go-build\7e\7eb34e9c94bb2e5765f2ea39a77592f416a8e5d45f892b7134534cb61d8b0143-d
packagefile strconv=C:\Users\mattn\AppData\Local\go-build\bf\bf8cb0e39b03fa85f5c18875f0f4b8ea940c17a9eb2b367c2d9ec60eb41b9f27-d
packagefile strings=C:\Users\mattn\AppData\Local\go-build\e3\e3921607adc7f7e34c5c3c7885e9e7a8de28dcadce77deae9f362d10ace9fef6-d
packagefile bufio=C:\Users\mattn\AppData\Local\go-build\31\3172eec9b4e15ba9b56253ad8a0bf3de77d3752ae423f552f2bb20f1fb5f0b5c-d
packagefile regexp=C:\Users\mattn\AppData\Local\go-build\9f\9f439c7b8919063d5dd387dca4e3e65a68e9195b8545194868c5bebdec840b1c-d
packagefile runtime/pprof=C:\Users\mattn\AppData\Local\go-build\7e\7eb89538e15c98300ddc1f774643f0610bdb9bcf8e8d4d286ac2b8e81f4b9d2e-d
packagefile runtime/internal/atomic=C:\Users\mattn\AppData\Local\go-build\24\240e5b9c27d638d2e2752efb5ad5aa9bf413d1ef39227bcf81edfc3638f9c69d-d
packagefile runtime/internal/sys=C:\Users\mattn\AppData\Local\go-build\9e\9ecbfdff43cebed79c4d60e65bd9b9fe62eaa357639bdd9e730410b85f69baff-d
packagefile runtime/cgo=C:\Users\mattn\AppData\Local\go-build\a5\a52e8da57055eafee31eb84a4893c9971088b8deaa63de99103f3e100a09ef2a-d
packagefile unicode/utf8=C:\Users\mattn\AppData\Local\go-build\6e\6efff469d5bf5358781c24fec393abd273bc605322f725abc0a581be9676286b-d
packagefile internal/syscall/windows/sysdll=C:\Users\mattn\AppData\Local\go-build\f1\f1b02e75282f68faefcaf8527406783929070b3c6178b7f5813bbf5275dd9818-d
packagefile internal/syscall/windows/registry=C:\Users\mattn\AppData\Local\go-build\45\452267d2da652a5afdf48dc13d2bf4842c63e42cee983833b0d24238f1469652-d
packagefile internal/cpu=C:\Users\mattn\AppData\Local\go-build\08\0820411bd99f23e507e18428a919a89772e24f45fde3993bbde77ddbe64693d2-d
packagefile unicode=C:\Users\mattn\AppData\Local\go-build\da\da22e4a89a2be70ca5572a07cbc04f555592fa5efa1945a5a236f8d16391e52f-d
packagefile reflect=C:\Users\mattn\AppData\Local\go-build\fe\fe0225cad5ff122232f6b54733283073c143e2bb7201c11911fa74afb37773b5-d
packagefile math=C:\Users\mattn\AppData\Local\go-build\54\5477db0575eaad986e6af44a6d92eb5b9b029f68bd2eda1cff695feef78ab65b-d
packagefile regexp/syntax=C:\Users\mattn\AppData\Local\go-build\ff\ff255ed1e973468deb90e18fbb8dfd410cbaedf18f28d5f962ffbf18507593c3-d
packagefile compress/gzip=C:\Users\mattn\AppData\Local\go-build\01\01e494cfaaaf1e74612ca5a553f42b57c7ace529f9014a66fed37ac5795f9cf1-d
packagefile context=C:\Users\mattn\AppData\Local\go-build\f3\f31d3ebc36126e980dda077c1e58e38807ea213eb5f2aeb5660d3bbb7bb0a211-d
packagefile encoding/binary=C:\Users\mattn\AppData\Local\go-build\20\201852e405473d2c0ba6af3f027543b807e62d9a51522011044368906db73cb4-d
packagefile io/ioutil=C:\Users\mattn\AppData\Local\go-build\ed\edbe00c607f78531a963dbe6201f18c2a7b3ccd4b1df109fb352cf03b47435b9-d
packagefile text/tabwriter=C:\Users\mattn\AppData\Local\go-build\63\63adbe090316bef2abadb405f567ad610d9b67394b9c759c84ba1d835e5bf6e1-d
packagefile compress/flate=C:\Users\mattn\AppData\Local\go-build\15\154623f1674dd99d895f1da69c50f27258b7a12ac729ae26182ad1b378eeaaad-d
packagefile hash/crc32=C:\Users\mattn\AppData\Local\go-build\ce\cead5fd22d068fcf09b8e5243bc51760a843e6bdcb21bb4ad0d5850b9748135b-d
packagefile path/filepath=C:\Users\mattn\AppData\Local\go-build\74\745eee1f96c076cc9d5022442547312bc1b877ceb2dbdab11fe92a062c4196d9-d
packagefile math/bits=C:\Users\mattn\AppData\Local\go-build\44\44634ab159fd5fc49a33bfc094c9913922a2aa5d82551333f71c01daac982955-d
packagefile hash=C:\Users\mattn\AppData\Local\go-build\7b\7b545474ad2305b77c32f519c4c9d8c4d7e8a6631fdb4e68d36649820e0c0993-d
EOF
cd .
"C:\\go\\pkg\\tool\\windows_amd64\\link.exe" -o "C:\\Users\\mattn\\AppData\\Local\\Temp\\go-build145566806\\b001\\foo.test.exe" -importcfg "C:\\Users\\mattn\\AppData\\Local\\Temp\\go-build145566806\\b001\\importcfg.link" -installsuffix race -s -w -buildmode=exe -buildid=SahtbTegVVJvP74olz_7/8pJx4XviJbtdY1jhw28h/woq27DTbfcLI0z8p91IG/SahtbTegVVJvP74olz_7 -race -extld=gcc "C:\\Users\\mattn\\AppData\\Local\\go-build\\a1\\a1cd7cb20a5f900d42bb15aed70e97bb42e4421b20bb2ee25b2ecf2e983957db-d"
# github.com/mattn/foo (testmain)
runtime/cgo(.text): relocation target __acrt_iob_func not defined
runtime/cgo(.text): relocation target __acrt_iob_func not defined
runtime/cgo(.text): relocation target __acrt_iob_func not defined
runtime/cgo(.text): relocation target __acrt_iob_func not defined
runtime/cgo(.text): relocation target __acrt_iob_func not defined
runtime/cgo(.text): undefined: "__acrt_iob_func"
runtime/cgo(.text): undefined: "__acrt_iob_func"
runtime/cgo(.text): undefined: "__acrt_iob_func"
runtime/cgo(.text): undefined: "__acrt_iob_func"
runtime/cgo(.text): undefined: "__acrt_iob_func"
rm -r $WORK\b001\
FAIL    github.com/mattn/foo [build failed]

@mattn are you sure?

I cannot reproduce this:

c:\Users\Alex\dev\src\issue\go\23649>type foo_test.go
package foo

import (
        "testing"
)

func TestSimple(t *testing.T) {
        got := 1
        want := 2
        if got != want {
                t.Fatalf("want %v, but %v:", want, got)
        }
}

c:\Users\Alex\dev\src\issue\go\23649>go version
go version devel +6f37fee354 Wed Jan 31 22:12:10 2018 +0000 windows/amd64

c:\Users\Alex\dev\src\issue\go\23649>go test -race
--- FAIL: TestSimple (0.00s)
        foo_test.go:11: want 2, but 1:
FAIL
exit status 1
FAIL    issue/go/23649  0.052s

c:\Users\Alex\dev\src\issue\go\23649>

Alex

Yes, I found this on my Windows7. Now I'm on Windows10 and reproduce this. This is gcc version I use.

gcc (Rev1, Built by MSYS2 project) 7.3.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

If I put following code on same directory, go test -race works fine.

package foo

//
import "C"

gcc (Rev1, Built by MSYS2 project) 7.3.0

The latest of gcc I have is version 5. How do I install 7.3.0 ?

Thank you

Alex

I installed gcc 7.3.0 from https://github.com/Alexpux/MINGW-packages

Yesterday, I updated mingw gcc using pacman command. And it seems that this problem disappears. I apologize for bothering you

Yesterday, I updated mingw gcc using pacman command. And it seems that this problem disappears. I apologize for bothering you

No worries. All is good.

Alex

I could reproduce this on my Windows 10. So I reopen this.

libgcc.a (which is placed at pointed by gcc --print-libgcc-file-name command) seems not include symbol __acrt_iob_func. It seems to be contained in libmsvcrt.a. But even if I patched below, duplicated symbol error occured then.

diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go
index bfff5209a6..9f18cfac50 100644
--- a/src/cmd/link/internal/ld/lib.go
+++ b/src/cmd/link/internal/ld/lib.go
@@ -528,6 +528,9 @@ func (ctxt *Link) loadlib() {
                if p := ctxt.findLibPath("libmingw32.a"); p != "none" {
                    hostArchive(ctxt, p)
                }
+               if p := ctxt.findLibPath("libmsvcrt.a"); p != "none" {
+                   hostArchive(ctxt, p)
+               }
                // TODO: maybe do something similar to peimporteddlls to collect all lib names
                // and try link them all to final exe just like libmingwex.a and libmingw32.a:
                /*

Any idea to fix this?

facing same issue
➜ dddgit:(bolt) ✗ env GOOS=linux go build . runtime/cgo(__TEXT/__text): relocation target x_cgo_inittls not defined runtime/cgo(__TEXT/__text): relocation target x_cgo_threadentry not defined runtime/cgo(__TEXT/__text): undefined: "x_cgo_inittls" runtime/cgo(__TEXT/__text): undefined: "x_cgo_threadentry"

I have the same issue. If it helps to have more logs, here are mine.

This is the version of MinGW I am using on Windows 10.

Workaround for this, try to add -ldflags="-linkmode=external" for build.

Can confirm this as well on windows 10, go 1.10.3 and gcc 8.1.0 x86_64

Having the same issue. @mattn 's workaround did not work for me.

Windows 10
mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0
go version go1.10.3 windows/amd64

Also seeing this. Only effects tests that bring in cgo code

Windows 10
gcc version 8.1.0 (x86_64-posix-sjlj-rev0, Built by MinGW-W64 project)
go version go1.11 windows/amd64

Full GCC version info:

C:\MyGo\src\repo.jazznetworks.com\jazz\main>gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=C:/mingw64/bin/../libexec/gcc/x86_64-w64-mingw32/8.1.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../../../src/gcc-8.1.0/configure --host=x86_64-w64-mingw32 --build=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --prefix=/mingw64 --with-sysroot=/c/mingw810/x86_64-810-posix-sjlj-rt_v6-rev0/mingw64 --enable-shared --enable-static --enable-targets=all --enable-multilib --enable-languages=c,c++,fortran,lto --enable-libstdcxx-time=yes --enable-threads=posix --enable-libgomp --enable-libatomic --enable-lto --enable-graphite --enable-checking=release --enable-fully-dynamic-string --enable-version-specific-runtime-libs --enable-sjlj-exceptions --disable-libstdcxx-pch --disable-libstdcxx-debug --enable-bootstrap --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-gnu-as --with-gnu-ld --with-arch-32=i686 --with-arch-64=nocona --with-tune-32=generic --with-tune-64=core2 --with-libiconv --with-system-zlib --with-gmp=/c/mingw810/prerequisites/x86_64-w64-mingw32-static --with-mpfr=/c/mingw810/prerequisites/x86_64-w64-mingw32-static --with-mpc=/c/mingw810/prerequisites/x86_64-w64-mingw32-static --with-isl=/c/mingw810/prerequisites/x86_64-w64-mingw32-static --with-pkgversion='x86_64-posix-sjlj-rev0, Built by MinGW-W64 project' --with-bugurl=https://sourceforge.net/projects/mingw-w64 CFLAGS='-O2 -pipe -fno-ident -I/c/mingw810/x86_64-810-posix-sjlj-rt_v6-rev0/mingw64/opt/include -I/c/mingw810/prerequisites/x86_64-zlib-static/include -I/c/mingw810/prerequisites/x86_64-w64-mingw32-static/include' CXXFLAGS='-O2 -pipe -fno-ident -I/c/mingw810/x86_64-810-posix-sjlj-rt_v6-rev0/mingw64/opt/include -I/c/mingw810/prerequisites/x86_64-zlib-static/include -I/c/mingw810/prerequisites/x86_64-w64-mingw32-static/include' CPPFLAGS=' -I/c/mingw810/x86_64-810-posix-sjlj-rt_v6-rev0/mingw64/opt/include -I/c/mingw810/prerequisites/x86_64-zlib-static/include -I/c/mingw810/prerequisites/x86_64-w64-mingw32-static/include' LDFLAGS='-pipe -fno-ident -L/c/mingw810/x86_64-810-posix-sjlj-rt_v6-rev0/mingw64/opt/lib -L/c/mingw810/prerequisites/x86_64-zlib-static/lib -L/c/mingw810/prerequisites/x86_64-w64-mingw32-static/lib '
Thread model: posix
gcc version 8.1.0 (x86_64-posix-sjlj-rev0, Built by MinGW-W64 project)

I've enclosed objdump -tr for mingw32.a and mingwew.a , not sure if thats useful?:
libmingw32.txt
libmingwex.txt

CC @dvyukov

Not an entirely new data point, but, on Windows 7 with Go 1.11.4.

# uname -a
MINGW64_NT-6.1 WIN-2R64B2Q8DUG 2.11.2(0.329/5/3) 2018-11-26 09:22 x86_64 Msys

# gcc --version
gcc.exe (Rev1, Built by MSYS2 project) 8.2.1 20181214
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

AFAICT, I only get it when _not_ importing "C".

I just downloaded x86_64-7.3.0-release-win32-seh-rt_v5-rev0.7z file from https://sourceforge.net/projects/mingw-w64/files/

The file contains

c:\>gcc --version
gcc (x86_64-win32-seh-rev0, Built by MinGW-W64 project) 7.3.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


c:\>gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=c:/users/alex/dev/x86_64-7.3.0-release-win32-seh-rt_v5-rev0/bin/../libexec/gcc/x86_64-w64-mingw32/7.3.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../../../src/gcc-7.3.0/configure --host=x86_64-w64-mingw32 --build=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --prefix=/mingw64 --with-sysroot=/c/mingw730/x86_64-730-win32-seh-rt_v5-rev0/mingw64 --enable-shared --enable-static --disable-multilib --enable-languages=c,c++,fortran,lto --enable-libstdcxx-time=yes --enable-threads=win32 --enable-libgomp --enable-libatomic --enable-lto --enable-graphite --enable-checking=release --enable-fully-dynamic-string --enable-version-specific-runtime-libs --enable-libstdcxx-filesystem-ts=yes --disable-libstdcxx-pch --disable-libstdcxx-debug --enable-bootstrap --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-gnu-as --with-gnu-ld --with-arch=nocona --with-tune=core2 --with-libiconv --with-system-zlib --with-gmp=/c/mingw730/prerequisites/x86_64-w64-mingw32-static --with-mpfr=/c/mingw730/prerequisites/x86_64-w64-mingw32-static --with-mpc=/c/mingw730/prerequisites/x86_64-w64-mingw32-static --with-isl=/c/mingw730/prerequisites/x86_64-w64-mingw32-static --with-pkgversion='x86_64-win32-seh-rev0, Built by MinGW-W64 project' --with-bugurl=https://sourceforge.net/projects/mingw-w64 CFLAGS='-O2 -pipe -fno-ident -I/c/mingw730/x86_64-730-win32-seh-rt_v5-rev0/mingw64/opt/include -I/c/mingw730/prerequisites/x86_64-zlib-static/include -I/c/mingw730/prerequisites/x86_64-w64-mingw32-static/include' CXXFLAGS='-O2 -pipe -fno-ident -I/c/mingw730/x86_64-730-win32-seh-rt_v5-rev0/mingw64/opt/include -I/c/mingw730/prerequisites/x86_64-zlib-static/include -I/c/mingw730/prerequisites/x86_64-w64-mingw32-static/include' CPPFLAGS=' -I/c/mingw730/x86_64-730-win32-seh-rt_v5-rev0/mingw64/opt/include -I/c/mingw730/prerequisites/x86_64-zlib-static/include -I/c/mingw730/prerequisites/x86_64-w64-mingw32-static/include' LDFLAGS='-pipe -fno-ident -L/c/mingw730/x86_64-730-win32-seh-rt_v5-rev0/mingw64/opt/lib -L/c/mingw730/prerequisites/x86_64-zlib-static/lib -L/c/mingw730/prerequisites/x86_64-w64-mingw32-static/lib '
Thread model: win32
gcc version 7.3.0 (x86_64-win32-seh-rev0, Built by MinGW-W64 project)

c:\>

Seems to be working fine for me

c:\>go version
go version devel +249f5d2af4 Fri Mar 1 23:14:39 2019 +0000 windows/amd64

c:\>go test -race -count=1 path/filepath
ok      path/filepath   1.983s

c:\>

Alex

mingw64 compiler bundled on msys2

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=c:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.2.1/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../gcc-8-20181214/configure --prefix=/mingw64 --with-local-prefix=/mingw64/local --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --with-native-system-header-dir=/mingw64/x86_64-w64-mingw32/include --libexecdir=/mingw64/lib --enable-bootstrap --with-arch=x86-64 --with-tune=generic --enable-languages=ada,c,lto,c++,objc,obj-c++,fortran --enable-shared --enable-static --enable-libatomic --enable-threads=posix --enable-graphite --enable-fully-dynamic-string --enable-libstdcxx-filesystem-ts=yes --enable-libstdcxx-time=yes --disable-libstdcxx-pch --disable-libstdcxx-debug --disable-isl-version-check --enable-lto --enable-libgomp --disable-multilib --enable-checking=release --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-libiconv --with-system-zlib --with-gmp=/mingw64 --with-mpfr=/mingw64 --with-mpc=/mingw64 --with-isl=/mingw64 --with-pkgversion='Rev1, Built by MSYS2 project' --with-bugurl=https://sourceforge.net/projects/msys2 --with-gnu-as --with-gnu-ld
Thread model: posix
gcc version 8.2.1 20181214 (Rev1, Built by MSYS2 project) 
runtime/cgo(.text): relocation target __acrt_iob_func not defined for ABI0 (but is defined for ABI0)
runtime/cgo(.text): relocation target __acrt_iob_func not defined for ABI0 (but is defined for ABI0)
runtime/cgo(.text): relocation target __acrt_iob_func not defined for ABI0 (but is defined for ABI0)
FAIL    github.com/mattn/go-sandbox/race [build failed]

Thread model: posix

Hey! I know nothing about GCC. But mine has

Thread model: win32

Try find GCC similar to mine. Or download one from https://sourceforge.net/projects/mingw-w64/files/

See, if it works.

Alex

@mattn I managed to reproduce your problem, if I use internal linker:

c:\>go version
go version devel +2177bfb343 Fri Apr 26 21:54:41 2019 +0000 windows/amd64

c:\>gcc --version
gcc (x86_64-win32-seh-rev0, Built by MinGW-W64 project) 7.3.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


c:\>go test -short debug/pe
--- FAIL: TestInternalLinkerDWARF (1.25s)
    file_test.go:356: building test executable for linktype 2 failed: exit status 2 # command-line-arguments
        runtime/cgo(.text): relocation target __acrt_iob_func not defined for ABI0 (but is defined for ABI0)
        runtime/cgo(.text): relocation target __acrt_iob_func not defined for ABI0 (but is defined for ABI0)
        runtime/cgo(.text): relocation target __acrt_iob_func not defined for ABI0 (but is defined for ABI0)
FAIL
FAIL    debug/pe        6.120s

c:\>

Alex

Ran into this issue recently when trying to build gdrive on Linux. Here's the build script that was used and the log. Was only able to fix it with @mattn's workaround above.

Edited: To provide more stable links to these artifacts.

I reproduce this error every time I try debugging a binary with a -race argument for go tool in the GoLand IDE.

libcrtdll.al include symbol of __acrt_iob_func. So I tried to specify -libgcc to libcrtdll.a but new error occured.

HEADER = -H11 -T0xffffffffffffffff -R0xffffffff
c:\msys64\mingw64\x86_64-w64-mingw32\lib\libcrtdll.a(/75): duplicate symbol reference: __acrt_iob_func in both libgcc(.text) and libgcc(.data)
gcc [-m64 --print-file-name=libmingwex.a]
gcc [-m64 --print-file-name=libmingw32.a]
 0.00 deadcode
 0.02 windynrelocsyms
 0.04 pclntab=883521 bytes, funcdata total 205602 bytes
 0.05 dodata
 0.06 reloc
 0.07 asmb
 0.07 codeblk
 0.08 rodatblk
 0.09 datblk
 0.09 headr
 0.09 cpu time
70990 symbols
137048 liveness data

Applying workaround patch to ignore duplicate symbol to link.

diff --git a/src/cmd/link/internal/loadpe/ldpe.go b/src/cmd/link/internal/loadpe/ldpe.go
index f08e1241a7..b02ffd0ceb 100644
--- a/src/cmd/link/internal/loadpe/ldpe.go
+++ b/src/cmd/link/internal/loadpe/ldpe.go
@@ -465,6 +465,7 @@ func readpesym(arch *sys.Arch, syms *sym.Symbols, f *pe.File, pesym *pe.COFFSymb
        switch pesym.StorageClass {
        case IMAGE_SYM_CLASS_EXTERNAL: //global
            s = syms.Lookup(name, 0)
+           s.Attr |= sym.AttrDuplicateOK

        case IMAGE_SYM_CLASS_NULL, IMAGE_SYM_CLASS_STATIC, IMAGE_SYM_CLASS_LABEL:
            s = syms.Lookup(name, localSymVersion)

And replace libgcc to libcrtdll.a

"C:\go\pkg\tool\windows_amd64\link.exe" -libgcc c:\msys64\mingw64\x86_64-w64-mingw32\lib\libcrtdll.a -v -o race.test.exe -importcfg "C:\Users\mattn\AppData\Local\Temp\go-build513371986\b001\importcfg.link" -installsuffix race -s -w -buildmode=exe -buildid=3esQSTFNwKjQb1FEP_7l/gjURKijru_dPeOTOCljs/eEnc_vxaS0uhL6wLrl5X/3esQSTFNwKjQb1FEP_7l -race -extld=gcc "C:\Users\mattn\AppData\Local\go-build\a0\a0796ee7b6afc644bdeb01ed7dac7357541ae2e2eaf4a534dee5e10f0da662ba-d"

Now I could generate race.test.exe and works correctly. I wonder this information become a hint to solve this issue.

Change https://golang.org/cl/190481 mentions this issue: cmd/link/internal: ignore duplicate symbols for cgo

Another solution is removing stderr from runtime/cgo/windows.c

Another solution is removing stderr from runtime/cgo/_windows_.c

I do not understand. What exactly are you proposing? Thank you.

Alex

stdout/stdin/stderr is macro of __acrt_iob_func. So if remove using them, this error should be removed, I guess.

stdout/stdin/stderr is macro of __acrt_iob_func. So if remove using them, this error should be removed

We have no control over what other people do in their C code. They could include whatever headers they need. So this will not work.

Alex

Change https://golang.org/cl/197977 mentions this issue: cmd/link: use libmsvcrt.a during internal link

Change https://golang.org/cl/203603 mentions this issue: Revert "cmd/link: use libmsvcrt.a during internal link"

So if the fix was reverted, should this be reopened?

So if the fix was reverted,

@jakirkham

Change https://golang.org/cl/203603 has not been submitted yet. So the fix is still there.

We are considering to use this copy of Mingw - http://musl.cc/x86_64-w64-mingw32-native.zip (see https://github.com/golang/go/issues/35006#issuecomment-546573751 for details). If you are affected by this current issue, can you try this Mingw to see, if it fixes your problem?

Thank you.

Alex

For anyone else who ends up here, I've used the excellent MinGW compiler collection bundle from @StephanTLavavej for building CGO stuff on Windows for years. It's great, up-to-date, and it fixed this issue for me.

  1. Download from https://nuwen.net/mingw.html
  2. Unpack to C:\MinGW
  3. Add C:\MinGW\bin to PATH
  4. Profit.
Was this page helpful?
0 / 5 - 0 ratings