Skip to content

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

Closed
checkraisefold wants to merge 7 commits into
rust-lang:mainfrom
checkraisefold:fix-questionmark-linking
Closed

Fix linking for symbols starting with ? on i686-pc-windows-msvc#130808
checkraisefold wants to merge 7 commits into
rust-lang:mainfrom
checkraisefold:fix-questionmark-linking

Conversation

@checkraisefold

@checkraisefoldcheckraisefold commented Sep 25, 2024

Copy link
Copy Markdown

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.

@rustbot

Copy link
Copy Markdown
Collaborator

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

@rustbotrustbot 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
Copy Markdown
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.

@jieyouxujieyouxu 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
Copy Markdown
Member

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

Comment threadcompiler/rustc_codegen_ssa/src/back/symbol_export.rs Outdated
@jieyouxu

Copy link
Copy Markdown
Member

Rerolling a reviewer. r? compiler

@rustbotrustbot assigned nnethercote and unassigned TaKO8KiNov 16, 2024
@nnethercotennethercote 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
Copy Markdown
Member

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

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

This comment has been minimized.

@rustbotrustbot removed the has-merge-commits PR has merge commits, merge with caution. label Dec 30, 2024
@rustbotrustbot added the A-run-make Area: port run-make Makefiles to rmake.rs label Dec 31, 2024
@rustbot

Copy link
Copy Markdown
Collaborator

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

checkraisefold commented Dec 31, 2024

Copy link
Copy Markdown
Author

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 commented Dec 31, 2024

Copy link
Copy Markdown
Author

Seeing as the test no longer sucks-
@rustbot review

Additionally, run-make label can be removed

@rustbotrustbot 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
@matthiaskrgr

Copy link
Copy Markdown
Member

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

@jyn514

jyn514 commented Jan 25, 2025

Copy link
Copy Markdown
Member

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.

@jieyouxu

Copy link
Copy Markdown
Member

Oh I guess this wasn't actually r+'d

@bors r=davidtwco

@bors

bors commented Jan 31, 2025

Copy link
Copy Markdown
Collaborator

📌 Commit 9c3b53d has been approved by davidtwco

It is now in the queue for this repository.

@borsbors 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 31, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 31, 2025
…ing, 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))
Closesrust-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

bors commented Jan 31, 2025

Copy link
Copy Markdown
Collaborator

⌛ Testing commit 9c3b53d with merge 794a00d...

@rust-log-analyzer

This comment has been minimized.

@bors

bors commented Jan 31, 2025

Copy link
Copy Markdown
Collaborator

💔 Test failed - checks-actions

@borsbors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jan 31, 2025
@workingjubileeworkingjubilee added the O-x86_32 Target: x86 processors, 32 bit (like i686-*) (also known as IA-32, i386, i586, i686) label Feb 10, 2025
@davidtwcodavidtwco 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 Feb 18, 2025
Noratrieb added a commit to Noratrieb/rust that referenced this pull request Mar 6, 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))
Closesrust-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
@NoratriebNoratrieb mentioned this pull request Mar 6, 2025
VlaDexa added a commit to VlaDexa/rust that referenced this pull request May 2, 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))
Closesrust-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
@VlaDexaVlaDexa mentioned this pull request May 2, 2025
@jieyouxu

Copy link
Copy Markdown
Member

@bors r-

@checkraisefold

Copy link
Copy Markdown
Author

Haven't gotten around to looking into this yet - my test fails with and without the actual compiler changes on that target. Will have to take a closer look at what the linker is doing

@rustbot

Copy link
Copy Markdown
Collaborator

Some changes occurred in compiler/rustc_codegen_ssa

cc @WaffleLapkin

@rustbot

Copy link
Copy Markdown
Collaborator

⚠️Warning⚠️

  • The following commits have merge commits (commits with multiple parents) in your changes. We have a no merge policy so these commits will need to be removed for this pull request to be merged.

    You can start a rebase with the following commands:

    $ # rebase
    $ git pull --rebase https://github.com/rust-lang/rust.git master
    $ git push --force-with-lease
    

@rustbotrustbot added the has-merge-commits PR has merge commits, merge with caution. label May 11, 2025
@alex-semenyuk

Copy link
Copy Markdown
Member

@checkraisefold
Thanks for your contribution
From wg-triage. Any updates on this PR?

@bors

bors commented Nov 5, 2025

Copy link
Copy Markdown
Collaborator

☔ The latest upstream changes (presumably #147645) made this pull request unmergeable. Please resolve the merge conflicts.

@alex-semenyuk

Copy link
Copy Markdown
Member

@checkraisefold
Thanks for your contribution
From wg-triage. Close this PR due to inactivity, please reopen or create new one.

@rustbotrustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Nov 23, 2025
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-linkageArea: linking into static, shared libraries and binarieshas-merge-commitsPR has merge commits, merge with caution.O-windows-msvcToolchain: MSVC, Operating system: WindowsO-x86_32Target: x86 processors, 32 bit (like i686-*) (also known as IA-32, i386, i586, i686)T-compilerRelevant 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

13 participants

@checkraisefold@rustbot@jieyouxu@alex-semenyuk@rust-log-analyzer@cjgillot@davidtwco@bors@matthiaskrgr@jyn514@nnethercote@TaKO8Ki@workingjubilee