Skip to content
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

Fix linking for symbols starting with ? on i686-pc-windows-msvc #130808

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

checkraisefold
Copy link

@checkraisefold checkraisefold commented Sep 25, 2024

When using the export_name attribute to specifically export a symbol beginning with a question mark on the i686-pc-windows-msvc target, that symbol will fail to link and throw a linker error 100% of the time.
Issue writeup.

Closes #44282

I'm not sure if this is a proper solution, but LLVM does the same check which causes this issue, and is applied to all 32- and 64-bit Windows COFF objects (maybe the same patch should be applied for 64 bit windows as well then?). I am more unsure of whether this is the proper place for such a solution (and if the exact conditions of is_like_windows are proper for this usecase), or if the underscore should be stripped elsewhere, but it seems like the most correct place.

I'm also unsure if there are any backwards compatibility ramifications here. There shouldn't be, because binaries with exported symbols starting with ? for this target failed to link because of this issue anyway, but still.

try-job: i686-mingw

@rustbot
Copy link
Collaborator

rustbot commented Sep 25, 2024

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @TaKO8Ki (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 25, 2024
@checkraisefold
Copy link
Author

Just tested this patch with rust-lld; the original issue exists with lld being used as well, not just MSVC's linker, and is fixed by this patch.

@jieyouxu jieyouxu added O-windows-msvc Toolchain: MSVC, Operating system: Windows A-linkage Area: linking into static, shared libraries and binaries labels Sep 25, 2024
@jieyouxu
Copy link
Member

cc @bjorn3, @petrochenkov and @ChrisDenton, in case anyone has any clues about this 😅

@jieyouxu
Copy link
Member

Rerolling a reviewer. r? compiler

@rustbot rustbot assigned nnethercote and unassigned TaKO8Ki Nov 16, 2024
@nnethercote nnethercote added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 18, 2024
@alex-semenyuk
Copy link
Member

@checkraisefold
From wg-triage. Could you please take a look question above

@rustbot rustbot added the has-merge-commits PR has merge commits, merge with caution. label Dec 30, 2024
@rustbot

This comment has been minimized.

@checkraisefold checkraisefold force-pushed the fix-questionmark-linking branch from a79b6c2 to 2ec1dce Compare December 30, 2024 05:44
@rustbot rustbot removed the has-merge-commits PR has merge commits, merge with caution. label Dec 30, 2024
@checkraisefold checkraisefold force-pushed the fix-questionmark-linking branch from 2ec1dce to 6994ee3 Compare December 30, 2024 05:47
@rustbot rustbot added the A-run-make Area: port run-make Makefiles to rmake.rs label Dec 31, 2024
@rustbot
Copy link
Collaborator

rustbot commented Dec 31, 2024

This PR modifies tests/run-make/. If this PR is trying to port a Makefile
run-make test to use rmake.rs, please update the
run-make port tracking issue
so we can track our progress. You can either modify the tracking issue
directly, or you can comment on the tracking issue and link this PR.

cc @jieyouxu

@checkraisefold
Copy link
Author

checkraisefold commented Dec 31, 2024

Apologies for the time it took to get to this - aside from being busy, for a relative Rust newbie (and contributing to the compiler, lol) especially the testing harness is very intimidating and it takes a while to iterate on my beautiful Ryzen 5 3600.

I was hoping to be able to fit this into a codegen or assembly test with some FileCheck annotations, but the technical difficulties of that are very annoying compared to a general run-make test - the compilation fails without this fix, which I tested, and it's a whole lot easier to implement.

@rust-log-analyzer

This comment has been minimized.

@checkraisefold checkraisefold force-pushed the fix-questionmark-linking branch from c84f1b7 to a4c628c Compare December 31, 2024 08:33
@checkraisefold
Copy link
Author

checkraisefold commented Dec 31, 2024

Seeing as the test no longer sucks-
@rustbot review

Additionally, run-make label can be removed

@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Dec 31, 2024
@cjgillot
Copy link
Contributor

cjgillot commented Jan 8, 2025

r? compiler

@rustbot rustbot assigned davidtwco and unassigned cjgillot Jan 8, 2025
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@davidtwco
Copy link
Member

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Jan 24, 2025

📌 Commit 9c3b53d has been approved by davidtwco

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 24, 2025
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 25, 2025
…nking, r=davidtwco

Fix linking for symbols starting with ? on i686-pc-windows-msvc

When using the `export_name` attribute to specifically export a symbol beginning with a question mark on the `i686-pc-windows-msvc` target, that symbol will fail to link and throw a linker error 100% of the time.
[Issue writeup.](rust-lang#44282 (comment))

Closes rust-lang#44282

I'm not sure if this is a proper solution, but [LLVM does the same check](https://github.com/llvm/llvm-project/blob/main/llvm/lib/IR/Mangler.cpp#L48-L49) which causes this issue, and is applied to [all 32- and 64-bit Windows COFF objects](https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/IR/DataLayout.h#L255-L257) (maybe the same patch should be applied for 64 bit windows as well then?). I am *more* unsure of whether this is the proper place for such a solution (and if the exact conditions of is_like_windows are proper for this usecase), or if the underscore should be stripped elsewhere, but it seems like the most correct place.

I'm also unsure if there are any backwards compatibility ramifications here. There shouldn't be, because binaries with exported symbols starting with `?` for this target failed to link because of this issue anyway, but still.
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 25, 2025
Rollup of 7 pull requests

Successful merges:

 - rust-lang#130808 (Fix linking for symbols starting with ? on i686-pc-windows-msvc)
 - rust-lang#133138 (Target modifiers (special marked options) are recorded in metainfo)
 - rust-lang#133154 (Reword resolve errors caused by likely missing crate in dep tree)
 - rust-lang#135707 (Shorten linker output even more when `--verbose` is not present)
 - rust-lang#135764 (Fix tests on LLVM 20)
 - rust-lang#135785 (use `PassMode::Direct` for vector types on `s390x`)
 - rust-lang#135818 (tests: Port `translation` to rmake.rs)

Failed merges:

 - rust-lang#133951 (Make the wasm_c_abi future compat warning a hard error)

r? `@ghost`
`@rustbot` modify labels: rollup

try-job: aarch64-apple
try-job: i686-mingw
try-job: x86_64-gnu-llvm-19-3
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 25, 2025
…nking, r=davidtwco

Fix linking for symbols starting with ? on i686-pc-windows-msvc

When using the `export_name` attribute to specifically export a symbol beginning with a question mark on the `i686-pc-windows-msvc` target, that symbol will fail to link and throw a linker error 100% of the time.
[Issue writeup.](rust-lang#44282 (comment))

Closes rust-lang#44282

I'm not sure if this is a proper solution, but [LLVM does the same check](https://github.com/llvm/llvm-project/blob/main/llvm/lib/IR/Mangler.cpp#L48-L49) which causes this issue, and is applied to [all 32- and 64-bit Windows COFF objects](https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/IR/DataLayout.h#L255-L257) (maybe the same patch should be applied for 64 bit windows as well then?). I am *more* unsure of whether this is the proper place for such a solution (and if the exact conditions of is_like_windows are proper for this usecase), or if the underscore should be stripped elsewhere, but it seems like the most correct place.

I'm also unsure if there are any backwards compatibility ramifications here. There shouldn't be, because binaries with exported symbols starting with `?` for this target failed to link because of this issue anyway, but still.
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 25, 2025
Rollup of 6 pull requests

Successful merges:

 - rust-lang#130808 (Fix linking for symbols starting with ? on i686-pc-windows-msvc)
 - rust-lang#133154 (Reword resolve errors caused by likely missing crate in dep tree)
 - rust-lang#135707 (Shorten linker output even more when `--verbose` is not present)
 - rust-lang#135764 (Fix tests on LLVM 20)
 - rust-lang#135785 (use `PassMode::Direct` for vector types on `s390x`)
 - rust-lang#135818 (tests: Port `translation` to rmake.rs)

r? `@ghost`
`@rustbot` modify labels: rollup

try-job: aarch64-apple
try-job: i686-mingw
try-job: x86_64-gnu-llvm-19-3
@matthiaskrgr
Copy link
Member

@bors r- rollup=iffy
#136049 (comment)

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jan 25, 2025
@matthiaskrgr
Copy link
Member

@bors try

@bors
Copy link
Contributor

bors commented Jan 25, 2025

⌛ Trying commit 9c3b53d with merge e53ded5...

bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 25, 2025
…ing, r=<try>

Fix linking for symbols starting with ? on i686-pc-windows-msvc

When using the `export_name` attribute to specifically export a symbol beginning with a question mark on the `i686-pc-windows-msvc` target, that symbol will fail to link and throw a linker error 100% of the time.
[Issue writeup.](rust-lang#44282 (comment))

Closes rust-lang#44282

I'm not sure if this is a proper solution, but [LLVM does the same check](https://github.com/llvm/llvm-project/blob/main/llvm/lib/IR/Mangler.cpp#L48-L49) which causes this issue, and is applied to [all 32- and 64-bit Windows COFF objects](https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/IR/DataLayout.h#L255-L257) (maybe the same patch should be applied for 64 bit windows as well then?). I am *more* unsure of whether this is the proper place for such a solution (and if the exact conditions of is_like_windows are proper for this usecase), or if the underscore should be stripped elsewhere, but it seems like the most correct place.

I'm also unsure if there are any backwards compatibility ramifications here. There shouldn't be, because binaries with exported symbols starting with `?` for this target failed to link because of this issue anyway, but still.

 try-job: i686-mingw
@bors
Copy link
Contributor

bors commented Jan 25, 2025

☀️ Try build successful - checks-actions
Build commit: e53ded5 (e53ded5d975c4b7b232e5675ef5ed71e50e8d2f1)

@matthiaskrgr
Copy link
Member

Hm, I guess that this will clash with #135707 then 🤔
@bors=davidtwco

@jyn514
Copy link
Member

jyn514 commented Jan 25, 2025

Hm, I guess that this will clash with #135707 then 🤔

it shouldn't, #135707 only compares the linker invocation on x64 linux because it's too fragile to do anything else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linkage Area: linking into static, shared libraries and binaries O-windows-msvc Toolchain: MSVC, Operating system: Windows S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

export_name works for msvc x86_64 toolchain, but not i686