Skip to content

[SR-6857] Duplicate Symbols when Statically Linking on Windows #49406

@troughton

Description

@troughton
Previous ID SR-6857
Radar None
Original Reporter @troughton
Type Bug
Status Resolved
Resolution Done
Environment

Tested on Ubuntu 16.04, cross-compiling for Windows 10 x64 using lld-link.

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, AffectsABI, Swift4, Windows
Assignee @compnerd
Priority Medium

md5: 2962b39978a55b59b8ec5f9c40007f6f

Issue Description:

When statically linking Swift programs for Windows, duplicate symbols are emitted, preventing the object files/libs from being linked without /force:multiple (which is only supported on `link.exe` and not in LLD. This can be worked around by e.g. patching lld's COFF backend to ignore multiple definitions.

error: duplicate symbol: $Ss14CountableRangeVySiGAByxGs23BidirectionalCollectionsWL in /main.swift.o and in swiftcore.lib(swift.o)

error: duplicate symbol: __swift_memcpy24_8 in main.swift.o and in swiftcore.lib(swift.o)

error: duplicate symbol: $Ss23_ContiguousArrayStorageCyypGML in swiftcore.lib(swift.o) and in swiftswiftononesupport.lib(swiftononesupport.o)

Some of these functions should likely be marked 'COMDAT', so that they are used only when the compiler doesn't emit the implementation.

Similarly, swift_rt functions are (likely incorrectly) being exported twice:

/usr/bin/lld-link: error: duplicate symbol: swift_rt_swift_retain in main.swift.o and in swiftcore.lib(swift.o)
{{ /usr/bin/lld-link: error: duplicate symbol: swift_rt_swift_release in main.swift.o and in swiftcore.lib(swift.o)}}

which may also be a bug; as per @compnerd:

"The `swift_rt_` functions should not be exported I believe, as they are meant to be the local trampolines."

Metadata

Metadata

Assignees

Labels

WindowsPlatform: Windowsaffects ABIFlag: Affects ABIbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfswift 4.0

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions