Skip to content

Use .drectve for MSVC DLL exports#158294

Open
AsakuraMizu wants to merge 4 commits into
rust-lang:mainfrom
AsakuraMizu:windows-drectve-export
Open

Use .drectve for MSVC DLL exports#158294
AsakuraMizu wants to merge 4 commits into
rust-lang:mainfrom
AsakuraMizu:windows-drectve-export

Conversation

@AsakuraMizu

@AsakuraMizu AsakuraMizu commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

View all comments

This is a continuation of #142568.

This fixes the i686 MSVC issue mentioned there: .def files accept undecorated names, but .drectve /EXPORT needs decorated symbol names. The public export name is preserved with EXPORTAS.

It's worth noting that EII with defaults now also works on MSVC.

@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 23, 2026
@rustbot

rustbot commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

r? @oli-obk

rustbot has assigned @oli-obk.
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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: codegen, compiler
  • codegen, compiler expanded to 73 candidates
  • Random selection from 21 candidates

@rust-log-analyzer

This comment has been minimized.

Comment thread compiler/rustc_codegen_ssa/src/back/link.rs Outdated
Comment thread compiler/rustc_codegen_ssa/src/back/linker.rs
@oli-obk oli-obk 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 Jun 23, 2026
@AsakuraMizu AsakuraMizu force-pushed the windows-drectve-export branch from b0075d5 to 4051560 Compare June 24, 2026 05:22
@AsakuraMizu

Copy link
Copy Markdown
Contributor Author

Updated :)

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 24, 2026

@oli-obk oli-obk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@rust-bors

rust-bors Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 4051560 has been approved by oli-obk

It is now in the queue for this repository.

@rust-bors rust-bors Bot 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 24, 2026
@bjorn3

bjorn3 commented Jun 24, 2026

Copy link
Copy Markdown
Member

Maybe rollup=iffy? Linkage related things tend to be tricky.

@oli-obk

oli-obk commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

@bors rollup=iffy reason=windows linker shenanigans

JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 25, 2026
…, r=oli-obk

Use .drectve for MSVC DLL exports

This is a continuation of rust-lang#142568.

This fixes the i686 MSVC issue mentioned there: `.def` files accept undecorated names, but `.drectve` `/EXPORT` needs decorated symbol names. The public export name is preserved with `EXPORTAS`.

It's worth noting that EII with defaults now also works on MSVC.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 25, 2026
…, r=oli-obk

Use .drectve for MSVC DLL exports

This is a continuation of rust-lang#142568.

This fixes the i686 MSVC issue mentioned there: `.def` files accept undecorated names, but `.drectve` `/EXPORT` needs decorated symbol names. The public export name is preserved with `EXPORTAS`.

It's worth noting that EII with defaults now also works on MSVC.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 25, 2026
…, r=oli-obk

Use .drectve for MSVC DLL exports

This is a continuation of rust-lang#142568.

This fixes the i686 MSVC issue mentioned there: `.def` files accept undecorated names, but `.drectve` `/EXPORT` needs decorated symbol names. The public export name is preserved with `EXPORTAS`.

It's worth noting that EII with defaults now also works on MSVC.
rust-bors Bot pushed a commit that referenced this pull request Jun 25, 2026
…uwer

Rollup of 17 pull requests

Successful merges:

 - #153697 (Add arg splat experiment initial tuple impl)
 - #158294 (Use .drectve for MSVC DLL exports)
 - #158253 (codegen_ssa: multiply scalable vec size by `vscale`)
 - #158308 (Fix bug when rustdoc "go to only result" setting is not working as expected")
 - #158345 (Use `transmute_neo` in `assume_init`)
 - #158369 (std: abort when `resume_unwind` is called inside the panic hook)
 - #158374 (disallow tail calling extern "rust-call" functions)
 - #158380 (Revert "rebuild LLVM when `bootstrap.toml` config changes")
 - #154398 (Add test for async Send with PhantomData<*mut ()> + unsafe impl Send + dyn Trait)
 - #157181 (autodiff: stop always needing an alloca)
 - #158278 (autodiff - typtree cleanups)
 - #158311 (doc(unstable-book): fix typo "earier" -> "earlier" in default-visibility flag)
 - #158318 (Make normalization in a test case resilient to dist compilation)
 - #158338 (Reorganize `tests/ui/issues` [14/N])
 - #158343 (Include `Item::const_stability` info in rustdoc JSON.)
 - #158355 (Fixup the refactoring errors in #156246)
 - #158390 (Fix: auto trait, const trait bound)

Failed merges:

 - #155535 (export symbols: support macos/windows(32/64))
@JonathanBrouwer

Copy link
Copy Markdown
Contributor

💔 I suspect this PR failed tests as part of a rollup
@bors r-

After fixing the problem, consider running a try job for the failed job before re-approving.

Link to failure: #158391 (comment)

@rust-bors rust-bors Bot 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 Jun 25, 2026
@rust-bors

rust-bors Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

This pull request was unapproved.

This PR was contained in a rollup (#158391), which was unapproved.

View changes since this unapproval

@oli-obk

oli-obk commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

@bors try jobs=x86_64-msvc-1

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Jun 29, 2026
Use .drectve for MSVC DLL exports


try-job: x86_64-msvc-1
@rust-bors

rust-bors Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: fbb1950 (fbb195002ee8f5118ac156c1b0e56dd4b38aa343)
Base parent: 63f05e3 (63f05e3635171e7ac3f9ca78bad6c71052cda5a3)

@oli-obk

oli-obk commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

@bors r+

@rust-bors

rust-bors Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

📌 Commit c84bcbe has been approved by oli-obk

It is now in the queue for this repository.

@rust-bors rust-bors Bot 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 29, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Jun 29, 2026
Use .drectve for MSVC DLL exports



This is a continuation of #142568.

This fixes the i686 MSVC issue mentioned there: `.def` files accept undecorated names, but `.drectve` `/EXPORT` needs decorated symbol names. The public export name is preserved with `EXPORTAS`.

It's worth noting that EII with defaults now also works on MSVC.
@rust-log-analyzer

This comment has been minimized.

@rust-bors rust-bors Bot 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 Jun 29, 2026
@rust-bors

rust-bors Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

💔 Test for 2523831 failed: CI. Failed job:

@rust-bors rust-bors Bot 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 Jun 30, 2026
@rust-log-analyzer

This comment has been minimized.

@AsakuraMizu AsakuraMizu force-pushed the windows-drectve-export branch from c359042 to 2f749bd Compare June 30, 2026 05:10
@oli-obk

oli-obk commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

@bors try jobs=x86_64-msvc-ext1

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Jun 30, 2026
Use .drectve for MSVC DLL exports


try-job: x86_64-msvc-ext1
@rust-bors

rust-bors Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: a558f27 (a558f2706edcfaa8ced9843b1d3addc791a7c012)
Base parent: 0966944 (096694416a41840709140eb0fd0ca193d1a3e6ba)

@AsakuraMizu

Copy link
Copy Markdown
Contributor Author

It seems that if we don't pass a /DEF:lib.def, link.exe won't generate a .lib file for an empty cdylib. lld, on the other hand, doesn't have this problem.

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 30, 2026

@bjorn3 bjorn3 Jun 30, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is missing a check that the symbols were actually exported. And maybe run it on all Windows targets?

View changes since the review

Comment on lines 832 to 843
// .def file similar to MSVC one but without LIBRARY section
// because LD doesn't like when it's empty
writeln!(f, "EXPORTS")?;
for (symbol, kind) in symbols {
let kind_marker = if *kind == SymbolExportKind::Data { " DATA" } else { "" };
debug!(" _{symbol}");
for symbol in symbols {
let kind_marker =
if symbol.kind == SymbolExportKind::Data { " DATA" } else { "" };
debug!(" _{}", symbol.name);
// Quote the name in case it's reserved by linker in some way
// (this accounts for names with dots in particular).
writeln!(f, " \"{symbol}\"{kind_marker}")?;
writeln!(f, " \"{}\"{kind_marker}", symbol.name)?;
}
};

@bjorn3 bjorn3 Jun 30, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this still necessary? I would assume the MinGW linker also respects /EXPORT in .drectve.

View changes since the review

@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 30, 2026
@rustbot

rustbot commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@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 Jun 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants