Skip to content
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

Mangle rustc_std_internal_symbols functions #127173

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

bjorn3
Copy link
Member

@bjorn3 bjorn3 commented Jun 30, 2024

This reduces the risk of issues when using a staticlib or rust dylib compiled with a different rustc version in a rust program. Currently this will either (in the case of staticlib) cause a linker error due to duplicate symbol definitions, or (in the case of rust dylibs) cause rustc_std_internal_symbols functions to be silently overridden. As rust gets more commonly used inside the implementation of libraries consumed with a C interface (like Spidermonkey, Ruby YJIT (curently has to do partial linking of all rust code to hide all symbols not part of the C api), the Rusticl OpenCL implementation in mesa) this is becoming much more of an issue. With this PR the only symbols remaining with an unmangled name are rust_eh_personality (LLVM doesn't allow renaming it) and __rust_no_alloc_shim_is_unstable.

Helps mitigate #104707

try-job: aarch64-gnu-debug
try-job: aarch64-apple
try-job: x86_64-apple-1
try-job: x86_64-mingw-1
try-job: i686-mingw-1
try-job: x86_64-msvc-1
try-job: i686-msvc-1
try-job: test-various
try-job: armhf-gnu

@rustbot
Copy link
Collaborator

rustbot commented Jun 30, 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 Jun 30, 2024
@rustbot
Copy link
Collaborator

rustbot commented Jun 30, 2024

Some changes occurred in compiler/rustc_codegen_gcc

cc @antoyo, @GuillaumeGomez

@rust-log-analyzer

This comment has been minimized.

@bjorn3 bjorn3 force-pushed the mangle_rustc_std_internal_symbol branch from aea9a3c to db57b2a Compare June 30, 2024 16:50
@rust-log-analyzer

This comment has been minimized.

@bjorn3 bjorn3 force-pushed the mangle_rustc_std_internal_symbol branch from db57b2a to 4859689 Compare June 30, 2024 17:27
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Jun 30, 2024

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

@bjorn3 bjorn3 force-pushed the mangle_rustc_std_internal_symbol branch from 4859689 to 10bad43 Compare June 30, 2024 19:57
@rust-log-analyzer

This comment has been minimized.

@rustbot
Copy link
Collaborator

rustbot commented Jun 30, 2024

The Miri subtree was changed

cc @rust-lang/miri

@rust-log-analyzer

This comment has been minimized.

@fee1-dead
Copy link
Member

r? compiler

@bjorn3
Copy link
Member Author

bjorn3 commented Jul 1, 2024

Opened rust-lang/miri#3724 with some miri changes that can be made independently of this PR.

bors added a commit to rust-lang/miri that referenced this pull request Jul 2, 2024
Use the symbol_name query instead of trying to infer from the link_name attribute

This prevents the calculated name from going out of sync with exported_symbols. It also avoids having to special case the panic_impl lang item.

It also makes it easier to fix miri with rust-lang/rust#127173.
@bors
Copy link
Contributor

bors commented Jul 3, 2024

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

RalfJung pushed a commit to RalfJung/rust that referenced this pull request Jul 4, 2024
Use the symbol_name query instead of trying to infer from the link_name attribute

This prevents the calculated name from going out of sync with exported_symbols. It also avoids having to special case the panic_impl lang item.

It also makes it easier to fix miri with rust-lang#127173.
@bjorn3 bjorn3 force-pushed the mangle_rustc_std_internal_symbol branch from e1d353a to f8f4b88 Compare July 5, 2024 11:55
@rust-log-analyzer

This comment has been minimized.

@bjorn3 bjorn3 force-pushed the mangle_rustc_std_internal_symbol branch from f8f4b88 to 266c7c2 Compare July 5, 2024 12:56
@rust-log-analyzer

This comment has been minimized.

@bjorn3 bjorn3 force-pushed the mangle_rustc_std_internal_symbol branch from 266c7c2 to 9c91546 Compare July 5, 2024 13:35
@jieyouxu
Copy link
Member

jieyouxu commented Mar 4, 2025

I can't reproduce this locally on arm64 linux. Neither with nor without lld.

I'm not 100% sure, but maybe this symbol comes from LLVM compiler-rt?

https://github.com/llvm/llvm-project/blob/794ba171a43baaf9de9739440ddb582500527031/compiler-rt/lib/builtins/cpu_model/aarch64.c#L59-L64

Though the symbol visibility of that is hidden so idk.

For staticlib we still keep checking symbols that don't contain rust as
substring.
@bjorn3
Copy link
Member Author

bjorn3 commented Mar 4, 2025

Though the symbol visibility of that is hidden so idk.

Looks like symbol.is_global() doesn't take symbol visibility into account, just linkage.

I've changed symbols_check to ignore symbols that don't have rust in the name, but keep symbols_check_archive check all symbols. I've also changed the test back to running on all targets.

@bjorn3 bjorn3 force-pushed the mangle_rustc_std_internal_symbol branch from e377765 to bf70cce Compare March 4, 2025 16:13
@jieyouxu
Copy link
Member

jieyouxu commented Mar 4, 2025

That seems reasonble. I'd like to see if there's any nasty surprises since the queue is currently backed up a lot, so

@bors try

bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 4, 2025
…bol, r=<try>

Mangle rustc_std_internal_symbols functions

This reduces the risk of issues when using a staticlib or rust dylib compiled with a different rustc version in a rust program. Currently this will either (in the case of staticlib) cause a linker error due to duplicate symbol definitions, or (in the case of rust dylibs) cause rustc_std_internal_symbols functions to be silently overridden. As rust gets more commonly used inside the implementation of libraries consumed with a C interface (like Spidermonkey, Ruby YJIT (curently has to do partial linking of all rust code to hide all symbols not part of the C api), the Rusticl OpenCL implementation in mesa) this is becoming much more of an issue. With this PR the only symbols remaining with an unmangled name are rust_eh_personality (LLVM doesn't allow renaming it) and `__rust_no_alloc_shim_is_unstable`.

Helps mitigate rust-lang#104707

try-job: aarch64-gnu-debug
try-job: aarch64-apple
try-job: x86_64-apple-1
try-job: x86_64-mingw-1
try-job: i686-mingw-1
try-job: x86_64-msvc-1
try-job: i686-msvc-1
try-job: test-various
try-job: armhf-gnu
@bors
Copy link
Contributor

bors commented Mar 4, 2025

⌛ Trying commit bf70cce with merge 6255ed0...

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Mar 4, 2025

💔 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 Mar 4, 2025
@bjorn3
Copy link
Member Author

bjorn3 commented Mar 5, 2025

@bors try

@bors
Copy link
Contributor

bors commented Mar 5, 2025

⌛ Trying commit 6d4de52 with merge ed25e8e...

bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 5, 2025
…bol, r=<try>

Mangle rustc_std_internal_symbols functions

This reduces the risk of issues when using a staticlib or rust dylib compiled with a different rustc version in a rust program. Currently this will either (in the case of staticlib) cause a linker error due to duplicate symbol definitions, or (in the case of rust dylibs) cause rustc_std_internal_symbols functions to be silently overridden. As rust gets more commonly used inside the implementation of libraries consumed with a C interface (like Spidermonkey, Ruby YJIT (curently has to do partial linking of all rust code to hide all symbols not part of the C api), the Rusticl OpenCL implementation in mesa) this is becoming much more of an issue. With this PR the only symbols remaining with an unmangled name are rust_eh_personality (LLVM doesn't allow renaming it) and `__rust_no_alloc_shim_is_unstable`.

Helps mitigate rust-lang#104707

try-job: aarch64-gnu-debug
try-job: aarch64-apple
try-job: x86_64-apple-1
try-job: x86_64-mingw-1
try-job: i686-mingw-1
try-job: x86_64-msvc-1
try-job: i686-msvc-1
try-job: test-various
try-job: armhf-gnu
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Mar 5, 2025

💔 Test failed - checks-actions

@jieyouxu
Copy link
Member

jieyouxu commented Mar 5, 2025

Hm, is that from a dependency 🤔

@bjorn3
Copy link
Member Author

bjorn3 commented Mar 6, 2025

.refptr. and __imp_ are implementation details of the PE/COFF object file formats. I've changed the test to only run on ELF for which I know that this kind of weird things don't happen.

@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 Mar 6, 2025
@jieyouxu
Copy link
Member

jieyouxu commented Mar 6, 2025

@bjorn3 I think you forgot to push. But r=wesleywiser and me afterwards; that sounds reasonable.

@jieyouxu jieyouxu 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 Mar 6, 2025
@bjorn3
Copy link
Member Author

bjorn3 commented Mar 6, 2025

I did push, but it seems that github is still processing the push.
image

@bjorn3 bjorn3 force-pushed the mangle_rustc_std_internal_symbol branch from d21cc49 to 701dc0f Compare March 6, 2025 15:09
@bjorn3
Copy link
Member Author

bjorn3 commented Mar 6, 2025

git commit --amend && git push --force-with-lease fixed it.

@bors r=wesleywiser,jieyouxu

@bors
Copy link
Contributor

bors commented Mar 6, 2025

📌 Commit 701dc0f has been approved by wesleywiser,jieyouxu

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 Mar 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-run-make Area: port run-make Makefiles to rmake.rs S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

10 participants