rules_go: go: link error with libmsvcrt.a when race mode enabled on Windows

Example failure: https://buildkite.com/bazel/rules-go-golang/builds/2327#145a71ba-dee2-4eb7-b7ab-ff045ded70de

Looks like tests/core/race/race_test.go is failing with (snip):

        race_test.go:269: running: bazel test --features=race //:racy_test --test_arg=-wantrace=true
        race_test.go:277: unexpected build failure: exit status 1
            stderr:
            Loading: 
            Loading: 0 packages loaded
            INFO: Build option --features has changed, discarding analysis cache.
            Analyzing: target //:racy_test (0 packages loaded, 0 targets configured)
            INFO: Analyzed target //:racy_test (0 packages loaded, 7299 targets configured).
            INFO: Found 1 test target...
            [0 / 5] [Prepa] BazelWorkspaceStatusAction stable-status.txt
            ERROR: C:/b/ksckfvdp/bazel_testing/bazel_go_test/main/BUILD.bazel:27:8: GoLink racy_test_/racy_test.exe failed (Exit 1)
            c:/tools/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libmsvcrt.a(/2203): duplicate symbol reference: _unlock_file in both libgcc(.text) and libgcc(.data)
            libgcc(.text): relocation target ___chkstk_ms not defined
            libgcc(.text): relocation target atexit not defined
            link: error running the following subcommand: exit status 2

Not sure if this is due to an infra change; maybe someone more familiar with the tests can chime in?

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 20 (20 by maintainers)

Commits related to this issue

Most upvoted comments

I’m not entirely sure I understand what’s going on here, but it seems to be a problem between Go itself and mingw. I was able to reproduce this with go build -race hello.go, without involving Bazel at all. golang/go#23649 seems to be a related issue. CL 197977 was supposed to have fixed that, but it added the dependency on libmsvcrt.a, which is causing this failure at another version.

I think the right resolution here is to force external linking when race mode is enabled on Windows. That seems to resolve the problem.

I can confirm the difference of race.a indeed caused this problem (I replaced this library in one build with another build). But it’s hard for me to figure out how this library is built, that’s probably where you want to look into.