rust/compiler
bors 6f935a044d Auto merge of #141061 - dpaoliello:shimasfn, r=bjorn3
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: #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` (<https://github.com/rust-lang/rust/pull/140176#issuecomment-2872448443>). 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: #140954.
7. Another customer reported that they weren't using the Rust compiler to invoke the linker, thus these warnings were breaking their build: <https://github.com/rust-lang/rust/pull/140176#issuecomment-2881867433>. At that point, my original change was reverted (#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`
2025-06-18 09:24:40 +00:00
..
rustc Revert "Use workspace lints for crates in compiler/ #138084" 2025-03-10 18:12:47 +08:00
rustc_abi add extern "custom" functions 2025-06-12 20:27:10 +02:00
rustc_arena Introduce Arena::try_alloc_from_iter. 2025-04-19 01:13:18 +00:00
rustc_ast Auto merge of #141061 - dpaoliello:shimasfn, r=bjorn3 2025-06-18 09:24:40 +00:00
rustc_ast_ir Use -Wunused_crate_dependencies for compiler crates. 2025-03-20 08:59:43 +11:00
rustc_ast_lowering Reject union default field values 2025-06-17 07:27:58 +08:00
rustc_ast_passes Fold unnecessary visit_struct_field_def in AstValidator 2025-06-16 17:48:21 +00:00
rustc_ast_pretty Rollup merge of #142069 - nnethercote:Zmacro-stats, r=petrochenkov 2025-06-13 05:16:56 +02:00
rustc_attr_data_structures fix clippy 2025-06-17 23:22:51 +02:00
rustc_attr_parsing make error codes reflect reality better 2025-06-17 23:22:51 +02:00
rustc_baked_icu_data Add unreachable_pub to RUSTC_LINT_FLAGS for compiler/ crates. 2025-03-11 13:14:21 +11:00
rustc_borrowck Handle same-crate macro for borrowck semicolon suggestion 2025-06-16 19:58:01 +02:00
rustc_builtin_macros Rollup merge of #142371 - fee1-dead-contrib:push-xqlkumzurkus, r=petrochenkov 2025-06-17 23:19:34 +02:00
rustc_codegen_cranelift Auto merge of #141061 - dpaoliello:shimasfn, r=bjorn3 2025-06-18 09:24:40 +00:00
rustc_codegen_gcc Auto merge of #141061 - dpaoliello:shimasfn, r=bjorn3 2025-06-18 09:24:40 +00:00
rustc_codegen_llvm Auto merge of #141061 - dpaoliello:shimasfn, r=bjorn3 2025-06-18 09:24:40 +00:00
rustc_codegen_ssa Auto merge of #141061 - dpaoliello:shimasfn, r=bjorn3 2025-06-18 09:24:40 +00:00
rustc_const_eval Rollup merge of #142405 - oli-obk:type-once, r=RalfJung 2025-06-13 20:59:17 -07:00
rustc_data_structures library/compiler: add PointeeSized bounds 2025-06-16 23:04:33 +00:00
rustc_driver Remove recursion_limit increases. 2025-04-02 16:25:27 +11:00
rustc_driver_impl Rollup merge of #141769 - bjorn3:codegen_metadata_module_rework, r=workingjubilee,saethlin 2025-06-15 23:51:54 +02:00
rustc_error_codes make error codes reflect reality better 2025-06-17 23:22:51 +02:00
rustc_error_messages Fix review comments 2025-06-06 14:20:48 +00:00
rustc_errors introduce new lint infra 2025-06-12 09:56:47 +02:00
rustc_expand Rollup merge of #142371 - fee1-dead-contrib:push-xqlkumzurkus, r=petrochenkov 2025-06-17 23:19:34 +02:00
rustc_feature fix bugs in inline/force_inline and diagnostics of all attr parsers 2025-06-17 23:19:31 +02:00
rustc_fluent_macro Remove all unused feature gates from the compiler 2025-06-08 14:50:42 +00:00
rustc_fs_util Retry if creating temp fails with access denied 2025-04-25 11:28:36 +00:00
rustc_graphviz Remove #![warn(unreachable_pub)] from all compiler/ crates. 2025-03-11 13:14:21 +11:00
rustc_hashes Revert "Use workspace lints for crates in compiler/ #138084" 2025-03-10 18:12:47 +08:00
rustc_hir trait_sel: {Meta,Pointee}Sized on Sized types 2025-06-16 15:00:22 +00:00
rustc_hir_analysis hir_analysis: add {Meta,Pointee}Sized bounds 2025-06-16 23:04:33 +00:00
rustc_hir_pretty Reduce precedence of expressions that have an outer attr 2025-06-13 18:09:13 -07:00
rustc_hir_typeck trait_sel: extend fast path with sized hierarchy 2025-06-16 23:04:35 +00:00
rustc_incremental Auto merge of #139758 - Zoxc:thread-local-graph, r=oli-obk 2025-05-07 12:39:54 +00:00
rustc_index index: add method for checking range on DenseBitSet 2025-06-04 00:47:12 +02:00
rustc_index_macros In rustc_mir_tranform, iterate over index newtypes instead of ints 2025-04-12 11:53:07 +00:00
rustc_infer Auto merge of #141763 - lcnr:fixme-gamer, r=BoxyUwU 2025-06-11 11:47:05 +00:00
rustc_interface Rollup merge of #141769 - bjorn3:codegen_metadata_module_rework, r=workingjubilee,saethlin 2025-06-15 23:51:54 +02:00
rustc_lexer rustc_lexer: typo fix + small cleanups 2025-06-06 13:08:16 +00:00
rustc_lint Auto merge of #138165 - jdonszelmann:inline, r=oli-obk 2025-06-18 06:25:21 +00:00
rustc_lint_defs Rollup merge of #141937 - WaffleLapkin:never-report-in-deps, r=oli-obk,traviscross 2025-06-15 23:51:55 +02:00
rustc_llvm rustc_llvm: add Windows system libs only when cross-compiling from Windows 2025-05-31 15:47:14 +02:00
rustc_log Add documentation for init_logger_with_additional_layer 2025-06-12 12:11:15 +02:00
rustc_macros Remove all unused feature gates from the compiler 2025-06-08 14:50:42 +00:00
rustc_metadata Rollup merge of #141769 - bjorn3:codegen_metadata_module_rework, r=workingjubilee,saethlin 2025-06-15 23:51:54 +02:00
rustc_middle Auto merge of #137944 - davidtwco:sized-hierarchy, r=oli-obk 2025-06-17 15:08:50 +00:00
rustc_mir_build Unimplement unsized_locals 2025-06-13 01:16:36 +02:00
rustc_mir_dataflow update cfg(bootstrap) 2025-05-12 15:33:37 +02:00
rustc_mir_transform Rollup merge of #142542 - cjgillot:invalidate-simplify-cfg, r=SparrowLii 2025-06-17 00:28:16 -07:00
rustc_monomorphize Remove all support for wasm's legacy ABI 2025-06-14 09:57:06 +00:00
rustc_next_trait_solver trait_sel: skip elaboration of sizedness supertrait 2025-06-16 23:04:36 +00:00
rustc_parse Auto merge of #138165 - jdonszelmann:inline, r=oli-obk 2025-06-18 06:25:21 +00:00
rustc_parse_format Add ParseMode::Diagnostic unit tests 2025-06-09 16:28:58 +02:00
rustc_passes make error codes reflect reality better 2025-06-17 23:22:51 +02:00
rustc_pattern_analysis Use builin_index instead of hand-rolling it 2025-05-28 10:03:01 +00:00
rustc_privacy Reorder fields in hir::ItemKind variants. 2025-05-30 02:23:20 +10:00
rustc_proc_macro Do not get proc_macro from the sysroot in rustc 2025-05-27 15:49:28 +00:00
rustc_query_impl Auto merge of #140145 - Zoxc:job-server-proxy, r=SparrowLii 2025-05-01 04:11:52 +00:00
rustc_query_system Do not clone Arc when hashing span. 2025-06-11 23:44:22 +00:00
rustc_resolve Fix PathSource lifetimes. 2025-06-16 10:33:00 +10:00
rustc_sanitizers Replace some Option<Span> with Span and use DUMMY_SP instead of None 2025-06-05 14:14:59 +00:00
rustc_serialize library/compiler: add PointeeSized bounds 2025-06-16 23:04:33 +00:00
rustc_session Temporarily add back -Zwasm-c-abi=spec 2025-06-17 17:15:01 +00:00
rustc_smir Auto merge of #137944 - davidtwco:sized-hierarchy, r=oli-obk 2025-06-17 15:08:50 +00:00
rustc_span trait_sel: {Meta,Pointee}Sized on Sized types 2025-06-16 15:00:22 +00:00
rustc_symbol_mangling Change __rust_no_alloc_shim_is_unstable to be a function 2025-06-16 10:54:07 -07:00
rustc_target Rollup merge of #142608 - workingjubilee:redescribe-rustc_target-more-accurately, r=wesleywiser 2025-06-17 23:19:37 +02:00
rustc_trait_selection trait_sel: skip nominal_obligations for Sized 2025-06-16 23:04:36 +00:00
rustc_traits FIXME(-Znext-solver) triage 2025-06-03 14:23:56 +02:00
rustc_transmute transmutability: shift abstraction boundary 2025-06-09 14:08:12 +00:00
rustc_ty_utils hir_analysis: add {Meta,Pointee}Sized bounds 2025-06-16 23:04:33 +00:00
rustc_type_ir Auto merge of #137944 - davidtwco:sized-hierarchy, r=oli-obk 2025-06-17 15:08:50 +00:00
rustc_type_ir_macros Split TypeFolder and FallibleTypeFolder 2025-04-15 18:30:35 +00:00
stable_mir Change rustc_driver dependency on stable_mir crate 2025-04-30 15:39:52 -07:00