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 }})
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!
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
Some changes occurred in compiler/rustc_codegen_ssa
rustbot added S-waiting-on-review
Status: Awaiting review from the assignee but also interested parties.
Relevant to the compiler team, which will review and decide on the PR/issue.
labels
@bors2 try jobs=x86_64-msvc-1,x86_64-msvc-2
⌛ 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
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
@bors2 try jobs=x86_64-msvc-1,x86_64-msvc-2
⌛ 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
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
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.
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.
@bors2 try jobs=x86_64-msvc-1,x86_64-msvc-2
⌛ 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
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
☀️ Try build successful (CI)
Build commit: e97fbdf (e97fbdf63e618534ac0929eef0229de9fb477dad, parent: 55d436467c351b56253deeba209ae2553d1c243f)
Squashed everything and reverted some now unnecessary changes.
@rustbot ready
This was referenced
Jun 17, 2025
📌 Commit 7539730 has been approved by wesleywiser
It is now in the queue for this repository.
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
jhpratt added a commit to jhpratt/rust that referenced this pull request
…=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
Rollup of 12 pull requests
Successful merges:
- #141829 (Specialize sleep_until implementation for unix (except mac))
- #141847 (Explain
TOCTOUon the top ofstd::fs, and reference it in functions) - #142138 (Add
Vec::into_chunks) - #142321 (Expose elf abi on ppc64 targets)
- #142568 (Use the .drectve section for exporting symbols from dlls on Windows)
- #142886 (ci: aarch64-gnu: Stop skipping
panic_abort_doc_tests) - #143038 (avoid suggesting traits from private dependencies)
- #143194 (fix bitcast of single-element SIMD vectors)
- #143206 (Align attr fixes)
- #143258 (Don't recompute
DisambiguatorStatefor every RPITIT in trait definition) - #143260 (Use the correct export kind for __rust_alloc_error_handler_should_panic)
- #143274 (ci: support optional jobs)
r? @ghost
@rustbot modify labels: rollup
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
@bors2 try jobs=dist-i686-msvc
⌛ 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
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
I think def files allow undecorated names, while /export needs the decorated name.
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.
📌 Commit dda12ce has been approved by wesleywiser
It is now in the queue for this repository.
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
rustbot added the S-waiting-on-author
Status: This is awaiting some action (such as code changes or more information) from the author.
label
bors removed the S-waiting-on-bors
Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
label
hey, I was wondering what the status of this was. I'm sorry if you've just had no time, that's completely understandable.
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.
Labels
Status: This is awaiting some action (such as code changes or more information) from the author.
Relevant to the compiler team, which will review and decide on the PR/issue.