Skip to content

Commit bae33f8

Browse files
thanmjproberts
authored andcommitted
cmd/link: link against libsynchronization.a for -race on windows
As of LLVM rev 41cb504b7c4b18ac15830107431a0c1eec73a6b2, the race detector runtime now refers to things in the windows synchronization library, hence when doing windows internal linking, at that library to the list of host archives that we visit. The tsan code that makes the reference is here: https://github.com/llvm/llvm-project/blob/41cb504b7c4b18ac15830107431a0c1eec73a6b2/compiler-rt/lib/sanitizer_common/sanitizer_win.cpp#L48 https://github.com/llvm/llvm-project/blob/41cb504b7c4b18ac15830107431a0c1eec73a6b2/compiler-rt/lib/sanitizer_common/sanitizer_win.cpp#L834 Note that libsynchronization.a is not guaranteed to be available on all windows systems, so in the external linking case, check for its existence before adding "-lsynchronization" to the external linker args. Updates golang#53539. Change-Id: I433c95c869915693d59e9c1082d5b8a11da1fc8c Reviewed-on: https://go-review.googlesource.com/c/go/+/413817 Reviewed-by: Cherry Mui <[email protected]> Run-TryBot: Than McIntosh <[email protected]>
1 parent d1a8ad9 commit bae33f8

File tree

1 file changed

+10
-0
lines changed
  • src/cmd/link/internal/ld

1 file changed

+10
-0
lines changed

src/cmd/link/internal/ld/lib.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,11 @@ func loadWindowsHostArchives(ctxt *Link) {
652652
hostObject(ctxt, "crt2", p)
653653
}
654654
}
655+
if *flagRace {
656+
if p := ctxt.findLibPath("libsynchronization.a"); p != "none" {
657+
hostArchive(ctxt, p)
658+
}
659+
}
655660
if p := ctxt.findLibPath("libmingwex.a"); p != "none" {
656661
hostArchive(ctxt, p)
657662
}
@@ -1705,6 +1710,11 @@ func (ctxt *Link) hostlink() {
17051710
p := writeGDBLinkerScript()
17061711
argv = append(argv, "-Wl,-T,"+p)
17071712
}
1713+
if *flagRace {
1714+
if p := ctxt.findLibPath("libsynchronization.a"); p != "libsynchronization.a" {
1715+
argv = append(argv, "-lsynchronization")
1716+
}
1717+
}
17081718
// libmingw32 and libmingwex have some inter-dependencies,
17091719
// so must use linker groups.
17101720
argv = append(argv, "-Wl,--start-group", "-lmingwex", "-lmingw32", "-Wl,--end-group")

0 commit comments

Comments
 (0)