Skip to content

[WIP] Use weak linkage instead of compiler generated shims #134522

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

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

Conversation

bjorn3
Copy link
Member

@bjorn3 bjorn3 commented Dec 19, 2024

#86844 (unstably) made it possible to avoid the allocator shim when using #[global_allocator]. This PR makes it possible to also avoid the allocator shim when using the default allocator in libstd by making use of weak linkage. Eventual stabilization of avoiding the allocator shim may be blocked on it working with the default allocator too.

This is still keeping the __rust_no_alloc_shim_is_unstable symbol for now until #123015 gets stabilized.

TODO: Update comments everywhere, test on macOS and Windows and write a better PR description why we want this. Also prevent codegen of weak symbols when there is a non-weak definition of the same symbol in the same codegen unit.

try-job: x86_64-msvc
try-zzz-job: x86_64-apple-1
try-zzz-job: x86_64-apple-2

@rustbot
Copy link
Collaborator

rustbot commented Dec 19, 2024

r? @fee1-dead

rustbot has assigned @fee1-dead.
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 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. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Dec 19, 2024
@rust-log-analyzer

This comment has been minimized.

@bjorn3 bjorn3 force-pushed the weak_linkage_allocator branch from f4f6936 to 93bd5d3 Compare December 19, 2024 16:38
@rust-log-analyzer

This comment has been minimized.

@bjorn3 bjorn3 force-pushed the weak_linkage_allocator branch 5 times, most recently from d179738 to 1b00966 Compare December 20, 2024 09:28
@rust-log-analyzer

This comment has been minimized.

@bjorn3 bjorn3 force-pushed the weak_linkage_allocator branch from 8f98f5e to 08bddfb Compare December 20, 2024 10:53
@bjorn3
Copy link
Member Author

bjorn3 commented Dec 20, 2024

@bors try

bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 20, 2024
[WIP] Use weak linkage instead of compiler generated shims

rust-lang#86844 (unstably) made it possible to avoid the allocator shim when using `#[global_allocator]`. This PR makes it possible to also avoid the allocator shim when using the default allocator in libstd by making use of weak linkage. Eventual stabilization of avoiding the allocator shim may be blocked on it working with the default allocator too.

This is still keeping the `__rust_no_alloc_shim_is_unstable` symbol for now until rust-lang#123015 gets stabilized.

TODO: Update comments everywhere, test on macOS and Windows and write a better PR description why we want this. Also prevent codegen of weak symbols when there is a non-weak definition of the same symbol in the same codegen unit.

try-job: x86_64-msvc
try-job: x86_64-apple-1
try-job: x86_64-apple-2
@bors
Copy link
Collaborator

bors commented Dec 20, 2024

⌛ Trying commit abd406c with merge 25f4036...

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Collaborator

bors commented Dec 20, 2024

💔 Test failed - checks-actions

@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-review Status: Awaiting review from the assignee but also interested parties. labels Dec 20, 2024
@rust-log-analyzer

This comment has been minimized.

@bjorn3
Copy link
Member Author

bjorn3 commented Dec 20, 2024

@bors try

@bors
Copy link
Collaborator

bors commented Dec 20, 2024

⌛ Trying commit 3e25d5a with merge 3659c42...

bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 20, 2024
[WIP] Use weak linkage instead of compiler generated shims

rust-lang#86844 (unstably) made it possible to avoid the allocator shim when using `#[global_allocator]`. This PR makes it possible to also avoid the allocator shim when using the default allocator in libstd by making use of weak linkage. Eventual stabilization of avoiding the allocator shim may be blocked on it working with the default allocator too.

This is still keeping the `__rust_no_alloc_shim_is_unstable` symbol for now until rust-lang#123015 gets stabilized.

TODO: Update comments everywhere, test on macOS and Windows and write a better PR description why we want this. Also prevent codegen of weak symbols when there is a non-weak definition of the same symbol in the same codegen unit.

try-job: x86_64-msvc
try-job: x86_64-apple-1
try-job: x86_64-apple-2
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Collaborator

bors commented Dec 20, 2024

💔 Test failed - checks-actions

@bjorn3
Copy link
Member Author

bjorn3 commented Dec 20, 2024

@bors try

@bors
Copy link
Collaborator

bors commented Dec 20, 2024

⌛ Trying commit 3e25d5a with merge f0b0345...

bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 20, 2024
[WIP] Use weak linkage instead of compiler generated shims

rust-lang#86844 (unstably) made it possible to avoid the allocator shim when using `#[global_allocator]`. This PR makes it possible to also avoid the allocator shim when using the default allocator in libstd by making use of weak linkage. Eventual stabilization of avoiding the allocator shim may be blocked on it working with the default allocator too.

This is still keeping the `__rust_no_alloc_shim_is_unstable` symbol for now until rust-lang#123015 gets stabilized.

TODO: Update comments everywhere, test on macOS and Windows and write a better PR description why we want this. Also prevent codegen of weak symbols when there is a non-weak definition of the same symbol in the same codegen unit.

try-zzz-job: x86_64-msvc
try-job: x86_64-apple-1
try-job: x86_64-apple-2
@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot added A-run-make Area: port run-make Makefiles to rmake.rs PG-exploit-mitigations Project group: Exploit mitigations labels Dec 20, 2024
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Collaborator

bors commented Dec 21, 2024

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

@bjorn3 bjorn3 force-pushed the weak_linkage_allocator branch from a351266 to 7952352 Compare January 17, 2025 13:36
@bjorn3
Copy link
Member Author

bjorn3 commented Jan 17, 2025

@bors try

bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 17, 2025
[WIP] Use weak linkage instead of compiler generated shims

rust-lang#86844 (unstably) made it possible to avoid the allocator shim when using `#[global_allocator]`. This PR makes it possible to also avoid the allocator shim when using the default allocator in libstd by making use of weak linkage. Eventual stabilization of avoiding the allocator shim may be blocked on it working with the default allocator too.

This is still keeping the `__rust_no_alloc_shim_is_unstable` symbol for now until rust-lang#123015 gets stabilized.

TODO: Update comments everywhere, test on <strike>macOS and</strike> Windows and write a better PR description why we want this. Also prevent codegen of weak symbols when there is a non-weak definition of the same symbol in the same codegen unit.

try-zzz-job: x86_64-msvc
try-job: x86_64-apple-1
try-job: x86_64-apple-2
@bors
Copy link
Collaborator

bors commented Jan 17, 2025

⌛ Trying commit 7952352 with merge d5915d9...

@bors
Copy link
Collaborator

bors commented Jan 17, 2025

☀️ Try build successful - checks-actions
Build commit: d5915d9 (d5915d9567206920e25d38421ce09513599a9d53)

@bjorn3
Copy link
Member Author

bjorn3 commented Jan 17, 2025

And for windows.

@bors try

@bors
Copy link
Collaborator

bors commented Jan 17, 2025

⌛ Trying commit 7952352 with merge 0b44463...

bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 17, 2025
[WIP] Use weak linkage instead of compiler generated shims

rust-lang#86844 (unstably) made it possible to avoid the allocator shim when using `#[global_allocator]`. This PR makes it possible to also avoid the allocator shim when using the default allocator in libstd by making use of weak linkage. Eventual stabilization of avoiding the allocator shim may be blocked on it working with the default allocator too.

This is still keeping the `__rust_no_alloc_shim_is_unstable` symbol for now until rust-lang#123015 gets stabilized.

TODO: Update comments everywhere, test on <strike>macOS and</strike> Windows and write a better PR description why we want this. Also prevent codegen of weak symbols when there is a non-weak definition of the same symbol in the same codegen unit.

try-job: x86_64-msvc
try-zzz-job: x86_64-apple-1
try-zzz-job: x86_64-apple-2
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Collaborator

bors commented Jan 17, 2025

💔 Test failed - checks-actions

@bors
Copy link
Collaborator

bors commented Jan 30, 2025

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

@ChrisDenton
Copy link
Member

I don't think anyone has worked on Rust's support for Windows weak linkage yet? Maybe extern_weak would work on Windows but I'm not even sure that's hooked up properly yet.

IIRC #[linkage] is just forwarding straight to LLVM and not always correctly.

@bjorn3 bjorn3 force-pushed the weak_linkage_allocator branch 2 times, most recently from afbc5b3 to 8f53ab0 Compare February 7, 2025 15:33
@bors
Copy link
Collaborator

bors commented Feb 9, 2025

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

@bjorn3 bjorn3 force-pushed the weak_linkage_allocator branch from 8f53ab0 to dcf9961 Compare June 16, 2025 10:20
@rustbot rustbot added the A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. label Jun 16, 2025
@rust-log-analyzer
Copy link
Collaborator

The job mingw-check-2 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)

error[E0308]: mismatched types
   --> src/tools/miri/src/shims/foreign_items.rs:54:69
    |
54  |         match this.emulate_foreign_item_inner(link_name, abi, args, &dest)? {
    |                    --------------------------                       ^^^^^ expected `&MPlaceTy<'_, Provenance>`, found `&&PlaceTy<'_, Provenance>`
    |                    |
    |                    arguments to this method are incorrect
    |
    = note: expected reference `&rustc_const_eval::interpret::MPlaceTy<'_, machine::Provenance>`
               found reference `&&rustc_const_eval::interpret::PlaceTy<'tcx, machine::Provenance>`
---
    |
130 |                     if symbol_name == link_name {
    |                                    ^^ no implementation for `&str == rustc_span::Symbol`
    |
    = help: the trait `std::cmp::PartialEq<rustc_span::Symbol>` is not implemented for `&str`
    = help: the following other types implement trait `std::cmp::PartialEq<Rhs>`:
              `&str` implements `std::cmp::PartialEq<ByteString>`
              `&str` implements `std::cmp::PartialEq<Cow<'_, str>>`
              `&str` implements `std::cmp::PartialEq<OsString>`
              `&str` implements `std::cmp::PartialEq<bstr::bstr::BStr>`
              `&str` implements `std::cmp::PartialEq<bstr::bstring::BString>`
              `&str` implements `std::cmp::PartialEq<rustc_target::json::Json>`
              `&str` implements `std::cmp::PartialEq<std::bstr::ByteStr>`
              `&str` implements `std::cmp::PartialEq<std::string::String>`
            and 13 others

error[E0433]: failed to resolve: use of undeclared type `Conv`
   --> src/tools/miri/src/shims/foreign_items.rs:509:61
    |
509 |                     let [size, align] = ecx.check_shim(abi, Conv::Rust, link_name, args)?;
    |                                                             ^^^^ use of undeclared type `Conv`

error[E0433]: failed to resolve: use of undeclared type `Conv`
   --> src/tools/miri/src/shims/foreign_items.rs:544:62
    |
544 |                     let [size, align] = this.check_shim(abi, Conv::Rust, link_name, args)?;
    |                                                              ^^^^ use of undeclared type `Conv`

error[E0433]: failed to resolve: use of undeclared type `Conv`
   --> src/tools/miri/src/shims/foreign_items.rs:571:45
    |
571 |                         ecx.check_shim(abi, Conv::Rust, link_name, args)?;
    |                                             ^^^^ use of undeclared type `Conv`

error[E0433]: failed to resolve: use of undeclared type `Conv`
   --> src/tools/miri/src/shims/foreign_items.rs:606:46
    |
606 |                         this.check_shim(abi, Conv::Rust, link_name, args)?;
    |                                              ^^^^ use of undeclared type `Conv`

error[E0277]: can't compare `&str` with `rustc_span::Symbol`
   --> src/tools/miri/src/shims/foreign_items.rs:130:36
    |
130 |                     if symbol_name == link_name {
    |                                    ^^ no implementation for `&str == rustc_span::Symbol`
    |
    = help: the trait `std::cmp::PartialEq<rustc_span::Symbol>` is not implemented for `&str`
    = help: the following other types implement trait `std::cmp::PartialEq<Rhs>`:
              `&str` implements `std::cmp::PartialEq<ByteString>`
              `&str` implements `std::cmp::PartialEq<Cow<'_, str>>`
              `&str` implements `std::cmp::PartialEq<OsString>`
              `&str` implements `std::cmp::PartialEq<bstr::BStr>`
              `&str` implements `std::cmp::PartialEq<bstr::BString>`
              `&str` implements `std::cmp::PartialEq<bstr::bstr::BStr>`
              `&str` implements `std::cmp::PartialEq<bstr::bstring::BString>`
              `&str` implements `std::cmp::PartialEq<camino::Utf8Path>`
            and 24 others

Some errors have detailed explanations: E0277, E0308, E0433.
For more information about an error, try `rustc --explain E0277`.
[RUSTC-TIMING] miri test:false 3.888

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-run-make Area: port run-make Makefiles to rmake.rs PG-exploit-mitigations Project group: Exploit mitigations 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. T-libs Relevant to the library 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