Skip to content

[LLD] [COFF] Add a separate option for allowing duplicate weak symbols #8944

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 8, 2024

Conversation

hamishknight
Copy link

This cherry-picks llvm#68077 to stable/20230725. Swift code coverage relies on the linker being able to handle duplicate weak symbols since LLVM emits a weak symbol for the coverage counters for a given function when it encounters a counter increment instruction, and counter increments can be inlined across translation units. However link.exe does not support duplicate weak symbols and, in an effort to maintain compatibility, neither does lld-link by default. Upstream lld-link does however have an option to enable this behavior. Cherry-pick that change to stable/20230725 so we can start using it in the Swift driver when coverage is enabled.

rdar://129337999

llvm#68077)

The MinGW mode (enabled with the flag -lldmingw) does allow duplicate
weak symbols. A test in
compiler-rt/test/profile/Windows/coverage-weak-lld.cpp does currently
enable the -lldmingw flag in an MSVC context, in order to deal with
duplicate weak symbols.

Add a new, separate, lld specific flag for enabling this. In MinGW mode,
this is enabled by default, otherwise it is disabled.

This allows making the MinGW mode more restrictive in adding libpaths
from the surrounding environment; in MinGW mode, all libpaths are passed
explicitly by the compiler driver to the linker, which is attempted in
https://reviews.llvm.org/D144084.
@hamishknight
Copy link
Author

@swift-ci please test

@hamishknight
Copy link
Author

cc @compnerd, would you mind reviewing, or would you know who else to tag?

Copy link
Member

@compnerd compnerd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cherry-pick is fine. However, I am concerned that this is going to break compatibility with link.exe. We default to link.exe as the linker and have tried to maintain compatibility with the platform linker. This would be akin to saying that you cannot use ld64 on Apple targets.

@hamishknight
Copy link
Author

I'm looking into whether we can change coverage to avoid relying on duplicate weak symbols, though I'm not sure it will be an entirely straightforward change. For now though, I think using lld-link with -lld-allow-duplicate-weak is a reasonable enough workaround, it's at least an improvement over the current situation where coverage simply does not work on Windows for non-trivial projects.

@hamishknight hamishknight merged commit 3f3acbc into swiftlang:stable/20230725 Jul 8, 2024
3 checks passed
@hamishknight hamishknight deleted the dup-weak branch July 8, 2024 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants