Skip to content

Change __rust_no_alloc_shim_is_unstable to be a function #141061

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dpaoliello
Copy link
Contributor

@dpaoliello dpaoliello commented May 15, 2025

This fixes a long sequence of issues:

  1. A customer reported that building for Arm64EC was broken: Linking error when compiled to arm64ec-pc-windows-msvc #138541
  2. This was caused by a bug in my original implementation of Arm64EC support, namely that only functions on Arm64EC need to be decorated with # but Rust was decorating statics as well.
  3. Once I corrected Rust to only decorate functions, I started linking failures where the linker couldn't find statics exported by dylib dependencies. This was caused by the compiler not marking exported statics in the generated DEF file with DATA, thus they were being exported as functions not data.
  4. Once I corrected the way that the DEF files were being emitted, the linker started failing saying that it couldn't find __rust_no_alloc_shim_is_unstable. This is because the MSVC linker requires the declarations of statics imported from other dylibs to be marked with dllimport (whereas it will happily link to functions imported from other dylibs whether they are marked dllimport or not).
  5. I then made a change to ensure that __rust_no_alloc_shim_is_unstable was marked as dllimport, but the MSVC linker started emitting warnings that __rust_no_alloc_shim_is_unstable was marked as dllimport but was declared in an obj file. This is a harmless warning which is a performance hint: anything that's marked dllimport must be indirected via an __imp symbol so I added a linker arg in the target to suppress the warning.
  6. A customer then reported a similar warning when using lld-link (Fix linking statics on Arm64EC #140176 (comment)). I don't think it was an implementation difference between the two linkers but rather that, depending on the obj that the declaration versus uses of __rust_no_alloc_shim_is_unstable landed in we would get different warnings, so I suppressed that warning as well: [win] Ignore MSVC linker warning 4217 #140954.
  7. Another customer reported that they weren't using the Rust compiler to invoke the linker, thus these warnings were breaking their build: Fix linking statics on Arm64EC #140176 (comment). At that point, my original change was reverted (Revert "Fix linking statics on Arm64EC #140176" #141024) leaving Arm64EC broken yet again.

Taking a step back, a lot of these linker issues arise from the fact that __rust_no_alloc_shim_is_unstable is marked as extern "Rust" in the standard library and, therefore, assumed to be a foreign item from a different crate BUT the Rust compiler may choose to generate it either in the current crate, some other crate that will be statically linked in OR some other crate that will by dynamically imported.

Worse yet, it is impossible while building a given crate to know if __rust_no_alloc_shim_is_unstable will statically linked or dynamically imported: it might be that one of its dependent crates is the one with an allocator kind set and thus that crate (which is compiled later) will decide depending if it has any dylib dependencies or not to import __rust_no_alloc_shim_is_unstable or generate it. Thus, there is no way to know if the declaration of __rust_no_alloc_shim_is_unstable should be marked with dllimport or not.

There is a simple fix for all this: there is no reason __rust_no_alloc_shim_is_unstable must be a static. It needs to be some symbol that must be linked in; thus, it could easily be a function instead. As a function, there is no need to mark it as dllimport when dynamically imported which avoids the entire mess above.

There may be a perf hit for changing the volatile load to be a tail call, so I'm happy to change that part back (although I question what the codegen of a volatile load would look like, and if the backend is going to try to use load-acquire semantics).

Build with this change applied BEFORE #140176 was reverted to demonstrate that there are no linking issues with either MSVC or MinGW: https://github.com/rust-lang/rust/actions/runs/15078657205

Incidentally, I fixed tests/run-make/no-alloc-shim to work with MSVC as I needed it to be able to test locally (FYI for #128602)

r? @bjorn3
cc @jieyouxu

@rustbot rustbot added A-testsuite Area: The testsuite used to check the correctness of rustc T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-infra Relevant to the infrastructure 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 May 15, 2025
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot added the A-run-make Area: port run-make Makefiles to rmake.rs label May 16, 2025
@rust-log-analyzer

This comment has been minimized.

@bjorn3
Copy link
Member

bjorn3 commented May 18, 2025

Do you have a link to the problems you are having?

@dpaoliello
Copy link
Contributor Author

Do you have a link to the problems you are having?

Yes, sorry, I was intending to add a full write-up to the description once I had done the PR builds to validate that this works with both MinGW and MSVC. I've updated the description now.

@dpaoliello dpaoliello marked this pull request as ready for review May 19, 2025 17:19
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 19, 2025
@rustbot
Copy link
Collaborator

rustbot commented May 19, 2025

Some changes occurred in compiler/rustc_codegen_gcc

cc @antoyo, @GuillaumeGomez

This PR modifies run-make tests.

cc @jieyouxu

Some changes occurred in compiler/rustc_codegen_cranelift

cc @bjorn3

Some changes occurred in compiler/rustc_codegen_ssa

cc @WaffleLapkin

@dpaoliello
Copy link
Contributor Author

YAML changes were for testing.
@rustbot label -T-infra

@rustbot rustbot removed the T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue. label May 19, 2025
Copy link
Member

@bjorn3 bjorn3 left a comment

Choose a reason for hiding this comment

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

How do we handle regular #[no_mangle] statics that doesn't cause those linker warnings/errors?

#[rustc_nounwind]
#[rustc_std_internal_symbol]
#[cfg(not(bootstrap))]
fn __rust_no_alloc_shim_is_unstable();
Copy link
Member

Choose a reason for hiding this comment

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

At the very least this symbol name will need to be changed to prevent UB when someone uses the old definition.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, I'll rename it.

core::ptr::read_volatile(&__rust_no_alloc_shim_is_unstable);
#[cfg(not(bootstrap))]
__rust_no_alloc_shim_is_unstable();
Copy link
Member

Choose a reason for hiding this comment

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

Would read_volatile(__rust_no_alloc_shim_is_unstable.addr().cast::<u8>()) (using the unstable FnPtr::addr method) work? Or maybe one of OpenBSD's exploit mitigations would break with that. Do we even care about that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That would work for most platforms.

I'm not sure about OpenBSD, but it would certainly cause issues in Xbox kernel-mode, as it loads binaries as Execute-Only (i.e., they are not readable).

Again, I suspect that the volatile read is more expensive than a tail call to empty function as it may generate load-acquire semantics.

I'm not sure if we could get away with just getting the address of the function and not reading from it? Backends might optimize that away though...

Copy link
Member

Choose a reason for hiding this comment

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

Maybe black_box(__rust_no_alloc_shim_is_unstable as fn())?

Copy link
Member

Choose a reason for hiding this comment

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

Would read_volatile(__rust_no_alloc_shim_is_unstable.addr().cast::()) (using the unstable FnPtr::addr method) work?

Miri would definitely complain about that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe black_box(__rust_no_alloc_shim_is_unstable as fn())?

Doesn't work: we get the correct behavior where it is required for linking to work, but then the codegen tests fail as the compiler is not able to optimize away allocations.

@jieyouxu jieyouxu added A-linkage Area: linking into static, shared libraries and binaries A-allocators Area: Custom and system allocators labels May 19, 2025
@dpaoliello
Copy link
Contributor Author

How do we handle regular #[no_mangle] statics that doesn't cause those linker warnings/errors?

If the static is exported by one crate and referenced by another, then the compiler knows whether that static will be statically linked or dynamically imported since it can see the dependency chain between the current crate using the static and the declaring crate.

If the static is referenced via an extern block, then it is up to the user to correctly decorate it with a #[link] attribute. If they get that attribute wrong (mark it as dynamically imported when it is statically linked AND the declaration is in an obj being linked in, not an rlib) then they will see the linker warning.

@rustbot
Copy link
Collaborator

rustbot commented May 19, 2025

The Miri subtree was changed

cc @rust-lang/miri

@rust-log-analyzer

This comment has been minimized.

@bjorn3
Copy link
Member

bjorn3 commented May 19, 2025

If the static is exported by one crate and referenced by another, then the compiler knows whether that static will be statically linked or dynamically imported since it can see the dependency chain between the current crate using the static and the declaring crate.

If the static is defined inside an rlib, and we are currently compiling an rlib, rustc can't know if the static will be statically linked or dynamically imported. Only when we are linking the current rlib into something do we know if the other rlib was statically linked or dynamically linked.

@dpaoliello
Copy link
Contributor Author

If the static is exported by one crate and referenced by another, then the compiler knows whether that static will be statically linked or dynamically imported since it can see the dependency chain between the current crate using the static and the declaring crate.

If the static is defined inside an rlib, and we are currently compiling an rlib, rustc can't know if the static will be statically linked or dynamically imported. Only when we are linking the current rlib into something do we know if the other rlib was statically linked or dynamically linked.

The warning is only emitted if something marked with dllimport is declared either in the current obj file or another obj file that is currently being linked: the MSVC linker doesn't complain if it's declared in a static library (.lib or .rlib).

@bors bors added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Jun 5, 2025
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Jun 7, 2025
Change __rust_no_alloc_shim_is_unstable to be a function

This fixes a long sequence of issues:

1. A customer reported that building for Arm64EC was broken: rust-lang#138541
2. This was caused by a bug in my original implementation of Arm64EC support, namely that only functions on Arm64EC need to be decorated with `#` but Rust was decorating statics as well.
3. Once I corrected Rust to only decorate functions, I started linking failures where the linker couldn't find statics exported by dylib dependencies. This was caused by the compiler not marking exported statics in the generated DEF file with `DATA`, thus they were being exported as functions not data.
4. Once I corrected the way that the DEF files were being emitted, the linker started failing saying that it couldn't find `__rust_no_alloc_shim_is_unstable`. This is because the MSVC linker requires the declarations of statics imported from other dylibs to be marked with `dllimport` (whereas it will happily link to functions imported from other dylibs whether they are marked `dllimport` or not).
5. I then made a change to ensure that `__rust_no_alloc_shim_is_unstable` was marked as `dllimport`, but the MSVC linker started emitting warnings that `__rust_no_alloc_shim_is_unstable` was marked as `dllimport` but was declared in an obj file. This is a harmless warning which is a performance hint: anything that's marked `dllimport` must be indirected via an `__imp` symbol so I added a linker arg in the target to suppress the warning.
6. A customer then reported a similar warning when using `lld-link` (<rust-lang#140176 (comment)>). I don't think it was an implementation difference between the two linkers but rather that, depending on the obj that the declaration versus uses of `__rust_no_alloc_shim_is_unstable` landed in we would get different warnings, so I suppressed that warning as well: rust-lang#140954.
7. Another customer reported that they weren't using the Rust compiler to invoke the linker, thus these warnings were breaking their build: <rust-lang#140176 (comment)>. At that point, my original change was reverted (rust-lang#141024) leaving Arm64EC broken yet again.

Taking a step back, a lot of these linker issues arise from the fact that `__rust_no_alloc_shim_is_unstable` is marked as `extern "Rust"` in the standard library and, therefore, assumed to be a foreign item from a different crate BUT the Rust compiler may choose to generate it either in the current crate, some other crate that will be statically linked in OR some other crate that will by dynamically imported.

Worse yet, it is impossible while building a given crate to know if `__rust_no_alloc_shim_is_unstable` will statically linked or dynamically imported: it might be that one of its dependent crates is the one with an allocator kind set and thus that crate (which is compiled later) will decide depending if it has any dylib dependencies or not to import `__rust_no_alloc_shim_is_unstable` or generate it. Thus, there is no way to know if the declaration of `__rust_no_alloc_shim_is_unstable` should be marked with `dllimport` or not.

There is a simple fix for all this: there is no reason `__rust_no_alloc_shim_is_unstable` must be a static. It needs to be some symbol that must be linked in; thus, it could easily be a function instead. As a function, there is no need to mark it as `dllimport` when dynamically imported which avoids the entire mess above.

There may be a perf hit for changing the `volatile load` to be a `tail call`, so I'm happy to change that part back (although I question what the codegen of a `volatile load` would look like, and if the backend is going to try to use load-acquire semantics).

Build with this change applied BEFORE rust-lang#140176 was reverted to demonstrate that there are no linking issues with either MSVC or MinGW: <https://github.com/rust-lang/rust/actions/runs/15078657205>

Incidentally, I fixed `tests/run-make/no-alloc-shim` to work with MSVC as I needed it to be able to test locally (FYI for rust-lang#128602)

r? `@bjorn3`
cc `@jieyouxu`
@RalfJung
Copy link
Member

RalfJung commented Jun 7, 2025

@bors r-

@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 Jun 7, 2025
@bjorn3
Copy link
Member

bjorn3 commented Jun 9, 2025

@bors r+

@bors
Copy link
Collaborator

bors commented Jun 9, 2025

📌 Commit cbdbd81 has been approved by bjorn3

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 Jun 9, 2025
workingjubilee added a commit to workingjubilee/rustc that referenced this pull request Jun 10, 2025
Change __rust_no_alloc_shim_is_unstable to be a function

This fixes a long sequence of issues:

1. A customer reported that building for Arm64EC was broken: rust-lang#138541
2. This was caused by a bug in my original implementation of Arm64EC support, namely that only functions on Arm64EC need to be decorated with `#` but Rust was decorating statics as well.
3. Once I corrected Rust to only decorate functions, I started linking failures where the linker couldn't find statics exported by dylib dependencies. This was caused by the compiler not marking exported statics in the generated DEF file with `DATA`, thus they were being exported as functions not data.
4. Once I corrected the way that the DEF files were being emitted, the linker started failing saying that it couldn't find `__rust_no_alloc_shim_is_unstable`. This is because the MSVC linker requires the declarations of statics imported from other dylibs to be marked with `dllimport` (whereas it will happily link to functions imported from other dylibs whether they are marked `dllimport` or not).
5. I then made a change to ensure that `__rust_no_alloc_shim_is_unstable` was marked as `dllimport`, but the MSVC linker started emitting warnings that `__rust_no_alloc_shim_is_unstable` was marked as `dllimport` but was declared in an obj file. This is a harmless warning which is a performance hint: anything that's marked `dllimport` must be indirected via an `__imp` symbol so I added a linker arg in the target to suppress the warning.
6. A customer then reported a similar warning when using `lld-link` (<rust-lang#140176 (comment)>). I don't think it was an implementation difference between the two linkers but rather that, depending on the obj that the declaration versus uses of `__rust_no_alloc_shim_is_unstable` landed in we would get different warnings, so I suppressed that warning as well: rust-lang#140954.
7. Another customer reported that they weren't using the Rust compiler to invoke the linker, thus these warnings were breaking their build: <rust-lang#140176 (comment)>. At that point, my original change was reverted (rust-lang#141024) leaving Arm64EC broken yet again.

Taking a step back, a lot of these linker issues arise from the fact that `__rust_no_alloc_shim_is_unstable` is marked as `extern "Rust"` in the standard library and, therefore, assumed to be a foreign item from a different crate BUT the Rust compiler may choose to generate it either in the current crate, some other crate that will be statically linked in OR some other crate that will by dynamically imported.

Worse yet, it is impossible while building a given crate to know if `__rust_no_alloc_shim_is_unstable` will statically linked or dynamically imported: it might be that one of its dependent crates is the one with an allocator kind set and thus that crate (which is compiled later) will decide depending if it has any dylib dependencies or not to import `__rust_no_alloc_shim_is_unstable` or generate it. Thus, there is no way to know if the declaration of `__rust_no_alloc_shim_is_unstable` should be marked with `dllimport` or not.

There is a simple fix for all this: there is no reason `__rust_no_alloc_shim_is_unstable` must be a static. It needs to be some symbol that must be linked in; thus, it could easily be a function instead. As a function, there is no need to mark it as `dllimport` when dynamically imported which avoids the entire mess above.

There may be a perf hit for changing the `volatile load` to be a `tail call`, so I'm happy to change that part back (although I question what the codegen of a `volatile load` would look like, and if the backend is going to try to use load-acquire semantics).

Build with this change applied BEFORE rust-lang#140176 was reverted to demonstrate that there are no linking issues with either MSVC or MinGW: <https://github.com/rust-lang/rust/actions/runs/15078657205>

Incidentally, I fixed `tests/run-make/no-alloc-shim` to work with MSVC as I needed it to be able to test locally (FYI for rust-lang#128602)

r? `@bjorn3`
cc `@jieyouxu`
bors added a commit that referenced this pull request Jun 10, 2025
Rollup of 13 pull requests

Successful merges:

 - #134442 (Specify the behavior of `file!`)
 - #134841 (Look at proc-macro attributes when encountering unknown attribute)
 - #140372 (Exhaustively handle parsed attributes in CheckAttr)
 - #140766 (Stabilize keylocker)
 - #141061 (Change __rust_no_alloc_shim_is_unstable to be a function)
 - #142042 (Make E0621 missing lifetime suggestion verbose)
 - #142101 (core::ptr: deduplicate more method docs)
 - #142176 (tests: Split dont-shuffle-bswaps along opt-levels and arches)
 - #142258 (platform-support.md: Mention specific Linux kernel version or later)
 - #142260 (Miri subtree update)
 - #142262 (Mark `core::slice::memchr` as `#[doc(hidden)]`)
 - #142272 (tests: Change ABIs in tests to more future-resilient ones)
 - #142275 (rustdoc: Refractor `clean_ty_generics`)

r? `@ghost`
`@rustbot` modify labels: rollup
workingjubilee added a commit to workingjubilee/rustc that referenced this pull request Jun 10, 2025
Change __rust_no_alloc_shim_is_unstable to be a function

This fixes a long sequence of issues:

1. A customer reported that building for Arm64EC was broken: rust-lang#138541
2. This was caused by a bug in my original implementation of Arm64EC support, namely that only functions on Arm64EC need to be decorated with `#` but Rust was decorating statics as well.
3. Once I corrected Rust to only decorate functions, I started linking failures where the linker couldn't find statics exported by dylib dependencies. This was caused by the compiler not marking exported statics in the generated DEF file with `DATA`, thus they were being exported as functions not data.
4. Once I corrected the way that the DEF files were being emitted, the linker started failing saying that it couldn't find `__rust_no_alloc_shim_is_unstable`. This is because the MSVC linker requires the declarations of statics imported from other dylibs to be marked with `dllimport` (whereas it will happily link to functions imported from other dylibs whether they are marked `dllimport` or not).
5. I then made a change to ensure that `__rust_no_alloc_shim_is_unstable` was marked as `dllimport`, but the MSVC linker started emitting warnings that `__rust_no_alloc_shim_is_unstable` was marked as `dllimport` but was declared in an obj file. This is a harmless warning which is a performance hint: anything that's marked `dllimport` must be indirected via an `__imp` symbol so I added a linker arg in the target to suppress the warning.
6. A customer then reported a similar warning when using `lld-link` (<rust-lang#140176 (comment)>). I don't think it was an implementation difference between the two linkers but rather that, depending on the obj that the declaration versus uses of `__rust_no_alloc_shim_is_unstable` landed in we would get different warnings, so I suppressed that warning as well: rust-lang#140954.
7. Another customer reported that they weren't using the Rust compiler to invoke the linker, thus these warnings were breaking their build: <rust-lang#140176 (comment)>. At that point, my original change was reverted (rust-lang#141024) leaving Arm64EC broken yet again.

Taking a step back, a lot of these linker issues arise from the fact that `__rust_no_alloc_shim_is_unstable` is marked as `extern "Rust"` in the standard library and, therefore, assumed to be a foreign item from a different crate BUT the Rust compiler may choose to generate it either in the current crate, some other crate that will be statically linked in OR some other crate that will by dynamically imported.

Worse yet, it is impossible while building a given crate to know if `__rust_no_alloc_shim_is_unstable` will statically linked or dynamically imported: it might be that one of its dependent crates is the one with an allocator kind set and thus that crate (which is compiled later) will decide depending if it has any dylib dependencies or not to import `__rust_no_alloc_shim_is_unstable` or generate it. Thus, there is no way to know if the declaration of `__rust_no_alloc_shim_is_unstable` should be marked with `dllimport` or not.

There is a simple fix for all this: there is no reason `__rust_no_alloc_shim_is_unstable` must be a static. It needs to be some symbol that must be linked in; thus, it could easily be a function instead. As a function, there is no need to mark it as `dllimport` when dynamically imported which avoids the entire mess above.

There may be a perf hit for changing the `volatile load` to be a `tail call`, so I'm happy to change that part back (although I question what the codegen of a `volatile load` would look like, and if the backend is going to try to use load-acquire semantics).

Build with this change applied BEFORE rust-lang#140176 was reverted to demonstrate that there are no linking issues with either MSVC or MinGW: <https://github.com/rust-lang/rust/actions/runs/15078657205>

Incidentally, I fixed `tests/run-make/no-alloc-shim` to work with MSVC as I needed it to be able to test locally (FYI for rust-lang#128602)

r? ``@bjorn3``
cc ``@jieyouxu``
bors added a commit that referenced this pull request Jun 10, 2025
Rollup of 12 pull requests

Successful merges:

 - #134442 (Specify the behavior of `file!`)
 - #134841 (Look at proc-macro attributes when encountering unknown attribute)
 - #140372 (Exhaustively handle parsed attributes in CheckAttr)
 - #140766 (Stabilize keylocker)
 - #141061 (Change __rust_no_alloc_shim_is_unstable to be a function)
 - #142042 (Make E0621 missing lifetime suggestion verbose)
 - #142101 (core::ptr: deduplicate more method docs)
 - #142258 (platform-support.md: Mention specific Linux kernel version or later)
 - #142260 (Miri subtree update)
 - #142262 (Mark `core::slice::memchr` as `#[doc(hidden)]`)
 - #142272 (tests: Change ABIs in tests to more future-resilient ones)
 - #142275 (rustdoc: Refractor `clean_ty_generics`)

r? `@ghost`
`@rustbot` modify labels: rollup
@RalfJung
Copy link
Member

@bors r-
failed in #142283

@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 Jun 10, 2025
@dpaoliello
Copy link
Contributor Author

@bjorn3 could you please help me understand how this test was passing before?

It's a linker failure in the tests/ui/sanitizer/dataflow.rs test.

   = note: /usr/bin/ld: /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/sanitizer/dataflow/a.dataflow.a934cfd234e75439-cgu.0.rcgu.o: in function `_ZN8dataflow4main17h053d7a3d932e2846E.dfsan':
           dataflow.a934cfd234e75439-cgu.0:(.text._ZN8dataflow4main17h053d7a3d932e2846E.dfsan+0x161): undefined reference to `_RNvCsi58mtoTmQEJ_7___rustc35___rust_no_alloc_shim_is_unstable_v2.dfsan'
           collect2: error: ld returned 1 exit status

Was the load previously being optimized out? Seems like some of the other tests would have caught that...

@dpaoliello
Copy link
Contributor Author

Oh, interesting, the symbol has a .dfsan suffix... so is this a name mangling issue? Or are we supposed to be generating a different symbol name for this case?

@bjorn3
Copy link
Member

bjorn3 commented Jun 10, 2025

I suspect this sanitizer mangles the names of functions, but not of globals. I think the issue here is that the version script for libstd.so only exported the non-.dfsan version, while the executable needs the .dfsan version.

@dpaoliello
Copy link
Contributor Author

Ugh, ok, so we need to generate the shim if the crate that would generate the shim has different sanitizers enabled? Or are there some sanitizers that don't change mangling?

@bjorn3
Copy link
Member

bjorn3 commented Jun 10, 2025

@rcvalle how is the dataflow sanitizer supposed to handle the case where the standard library is compiled without it enabled, but the main executable is compiled with it enabled. Is that supposed to work or does the minimal test that you added work by accident before this PR? And if it is supposed to work, is there a way to predict when the symbol mangling happens such that we can change the version script accordingly?

@dpaoliello
Copy link
Contributor Author

Looks like we could apply the DisableSanitizerInstrumentation attribute to it to disable dfsan from messing with it, but there's currently no Rust attribute which maps to that. Doesn't really work with the existing no_sanitize attribute since it disables a bunch of different sanitizers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-allocators Area: Custom and system allocators A-linkage Area: linking into static, shared libraries and binaries 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 A-testsuite Area: The testsuite used to check the correctness of rustc 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.

9 participants