Skip to content

Commit a2b7ff4

Browse files
authored
Fix duplicate symbol linker error when building Windows tests w/ coverage (#942)
This fixes the fatalError seen on Windows when attempting to build tests with code coverage enabled. The linker doesn't allow duplicate symbols by default on Windows, while this is OK on macOS/Linux. Use the `-lldmingw` linker flag to work around this issue.
1 parent d7f92c6 commit a2b7ff4

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/debugger/buildConfig.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,20 @@ export class TestingDebugConfigurationFactory {
336336
if (isRelease(this.testKind)) {
337337
result = [...result, "-c", "release", "-Xswiftc", "-enable-testing"];
338338
}
339+
// `link.exe` doesn't support duplicate weak symbols, and lld-link in an effort to
340+
// match link.exe also doesn't support them by default. We can use `-lldmingw` to get
341+
// lld-link to allow duplicate weak symbols, but that also changes its library search
342+
// path behavior, which could(?) be unintended.
343+
//
344+
// On the `next` branch (6.1?) in llvm, the duplicate symbol behavior now has its own flag
345+
// `-lld-allow-duplicate-weak` (https://github.com/llvm/llvm-project/pull/68077).
346+
// Once this is available we should use it if possible, as it will suppress the warnings
347+
// seen with `-lldmingw`.
348+
//
349+
// SEE: rdar://129337999
350+
if (process.platform === "win32" && this.testKind === TestKind.coverage) {
351+
result = [...result, "-Xlinker", "-lldmingw"];
352+
}
339353
return result;
340354
}
341355

0 commit comments

Comments
 (0)