Use the .drectve section for exporting symbols from dlls on Windows by bjorn3 · Pull Request #142568 · rust-lang/rust (original) (raw)

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 andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation47 Commits1 Checks10 Files changed

Conversation

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

@bjorn3

While it would be reasonable to expect the Windows linker to handle linker args in the .drectve section identical to cli arguments, as it turns out exporting weak symbols only works when the /EXPORT is in the .drectve section, not when it is a linker argument or when a .DEF file is used.

Necessary for and extracted out of #142366.

Thanks @dpaoliello for figuring out this weird quirk of link.exe!

@rustbot

r? @wesleywiser

rustbot has assigned @wesleywiser.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot

Some changes occurred in compiler/rustc_codegen_ssa

cc @WaffleLapkin

@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

Jun 16, 2025

bjorn3

bjorn3

@bjorn3

@bors2 try jobs=x86_64-msvc-1,x86_64-msvc-2

@rust-bors

⌛ Trying commit 5e2efb6 with merge 7bae343

To cancel the try build, run the command @bors2 try cancel.

rust-bors bot added a commit that referenced this pull request

Jun 16, 2025

@rust-bors

Use the .drectve section for exporting symbols from dlls on Windows

While it would be reasonable to expect the Windows linker to handle linker args in the .drectve section identical to cli arguments, as it turns out exporting weak symbols only works when the /EXPORT is in the .drectve section, not when it is a linker argument or when a .DEF file is used.

Necessary for and extracted out of #142366.

Thanks @dpaoliello for figuring out this weird quirk of link.exe! try-job: x86_64-msvc-1 try-job: x86_64-msvc-2

@rust-bors

@bjorn3

@bors2 try jobs=x86_64-msvc-1,x86_64-msvc-2

@rust-bors

⌛ Trying commit c353c7d with merge 3dadabc

To cancel the try build, run the command @bors2 try cancel.

rust-bors bot added a commit that referenced this pull request

Jun 16, 2025

@rust-bors

Use the .drectve section for exporting symbols from dlls on Windows

While it would be reasonable to expect the Windows linker to handle linker args in the .drectve section identical to cli arguments, as it turns out exporting weak symbols only works when the /EXPORT is in the .drectve section, not when it is a linker argument or when a .DEF file is used.

Necessary for and extracted out of #142366.

Thanks @dpaoliello for figuring out this weird quirk of link.exe! try-job: x86_64-msvc-1 try-job: x86_64-msvc-2

dpaoliello

Choose a reason for hiding this comment

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

LGTM.

One overall design question: is it supported for folks to run the linker themselves AND specify their own def file? A couple of my changes broke the Chromium and Fuschia folks, so I'm a little paranoid now about changing anything to do with linking that may affect them.

@bjorn3

One overall design question: is it supported for folks to run the linker themselves AND specify their own def file?

This PR on it's own has no effect at all on people running the linker themself. Both the .DEF file and the symbols.o file are only generated when rustc itself runs the linker.

As for a future PR that will use weak definitions, those symbols are not meant to be exported from a staticlib anyway. The only case that could break is if someone (Chromium) tries to link rlibs together into a dll and wants to export all symbols, which we don't officially support anyway. The Chromium people have had to adaot their build system for rustc changes anyway and I expect it to not all that hard to adapt to said future weak symbol usage too.

@rust-bors

@dpaoliello

@bjorn3

@bors2 try jobs=x86_64-msvc-1,x86_64-msvc-2

@rust-bors

⌛ Trying commit 8c88ff4 with merge e97fbdf

To cancel the try build, run the command @bors2 try cancel.

rust-bors bot added a commit that referenced this pull request

Jun 17, 2025

@rust-bors

Use the .drectve section for exporting symbols from dlls on Windows

While it would be reasonable to expect the Windows linker to handle linker args in the .drectve section identical to cli arguments, as it turns out exporting weak symbols only works when the /EXPORT is in the .drectve section, not when it is a linker argument or when a .DEF file is used.

Necessary for and extracted out of #142366.

Thanks @dpaoliello for figuring out this weird quirk of link.exe! try-job: x86_64-msvc-1 try-job: x86_64-msvc-2

@rust-bors

☀️ Try build successful (CI)
Build commit: e97fbdf (e97fbdf63e618534ac0929eef0229de9fb477dad, parent: 55d436467c351b56253deeba209ae2553d1c243f)

@bjorn3

Squashed everything and reverted some now unnecessary changes.

@rustbot ready

This was referenced

Jun 17, 2025

wesleywiser

@wesleywiser

wesleywiser

@wesleywiser

@bors

📌 Commit 7539730 has been approved by wesleywiser

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

Jun 30, 2025

jhpratt added a commit to jhpratt/rust that referenced this pull request

Jul 1, 2025

@jhpratt

…=wesleywiser

Use the .drectve section for exporting symbols from dlls on Windows

While it would be reasonable to expect the Windows linker to handle linker args in the .drectve section identical to cli arguments, as it turns out exporting weak symbols only works when the /EXPORT is in the .drectve section, not when it is a linker argument or when a .DEF file is used.

Necessary for and extracted out of rust-lang#142366.

Thanks @dpaoliello for figuring out this weird quirk of link.exe!

bors added a commit that referenced this pull request

Jul 2, 2025

@bors

Rollup of 12 pull requests

Successful merges:

r? @ghost @rustbot modify labels: rollup

@jhpratt

@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

Jul 2, 2025

@bjorn3

@bors2 try jobs=dist-i686-msvc

@rust-bors

⌛ Trying commit c16b891 with merge ab158cd

To cancel the try build, run the command @bors2 try cancel.

rust-bors bot added a commit that referenced this pull request

Jul 3, 2025

@rust-bors

Use the .drectve section for exporting symbols from dlls on Windows

While it would be reasonable to expect the Windows linker to handle linker args in the .drectve section identical to cli arguments, as it turns out exporting weak symbols only works when the /EXPORT is in the .drectve section, not when it is a linker argument or when a .DEF file is used.

Necessary for and extracted out of #142366.

Thanks @dpaoliello for figuring out this weird quirk of link.exe! try-job: dist-i686-msvc

@rust-bors

@bjorn3

I think def files allow undecorated names, while /export needs the decorated name.

@bjorn3

While it would be reasonable to expect the Windows linker to handle linker args in the .drectve section identical to cli arguments, as it turns out exporting weak symbols only works when the /EXPORT is in the .drectve section, not when it is a linker argument or when a .DEF file is used.

wesleywiser

@wesleywiser

@bors

📌 Commit dda12ce has been approved by wesleywiser

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-author

Status: This is awaiting some action (such as code changes or more information) from the author.

labels

Aug 9, 2025

@bjorn3

@rustbot rustbot added the S-waiting-on-author

Status: This is awaiting some action (such as code changes or more information) from the author.

label

Aug 9, 2025

@bors bors removed the S-waiting-on-bors

Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

label

Aug 9, 2025

@jdonszelmann

hey, I was wondering what the status of this was. I'm sorry if you've just had no time, that's completely understandable.

@bjorn3

It seems that I need to implement symbol mangling for the symbol names that I pass as /export: in .drectve, which requires some refactors to thread through the necessary data like function calling convention and argument sizes to the symbols.o generation location. I haven't had time to work on this yet.

@jdonszelmann

Labels

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.