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

-Zregparm=3 support in rustc #116972

Closed
ojeda opened this issue Oct 20, 2023 · 3 comments
Closed

-Zregparm=3 support in rustc #116972

ojeda opened this issue Oct 20, 2023 · 3 comments
Labels
A-ABI Area: Concerning the application binary interface (ABI) C-feature-request Category: A feature request, i.e: not implemented / a PR. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@ojeda
Copy link
Contributor

ojeda commented Oct 20, 2023

i.e. the equivalent of Clang's/GCC's -mregparm=3. The kernel needs it to support the x86 32-bit architecture, together with -Zreg-struct-return.

It could potentially be a "global target feature", i.e. a target feature that is required to be set the same way for all compilation units.

https://gcc.gnu.org/onlinedocs/gcc/x86-Function-Attributes.html#index-regparm-function-attribute_002c-x86
https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-mregparm

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 20, 2023
@bjorn3 bjorn3 added the A-ABI Area: Concerning the application binary interface (ABI) label Oct 20, 2023
@Noratrieb Noratrieb added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-feature-request Category: A feature request, i.e: not implemented / a PR. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Oct 21, 2023
intel-lab-lkp pushed a commit to intel-lab-lkp/linux that referenced this issue Jun 4, 2024
At present, Rust in the kernel only supports 64-bit x86, so UML has
followed suit. However, it's significantly easier to support 32-bit i386
on UML than on bare metal, as UML does not use the -mregparm option
(which alters the ABI), which is not yet supported by rustc[1].

Add support for CONFIG_RUST on um/i386, by adding a new target config to
generate_rust_target, and replacing various checks on CONFIG_X86_64 to
also support CONFIG_X86_32.

We still use generate_rust_target, rather than a built-in rustc target,
in order to match x86_64, provide a future place for -mregparm, and more
easily disable floating point instructions.

With these changes, the KUnit tests pass with:
kunit.py run --make_options LLVM=1 --kconfig_add CONFIG_RUST=y
--kconfig_add CONFIG_64BIT=n --kconfig_add CONFIG_FORTIFY_SOURCE=n

An earlier version of these changes was proposed on the Rust-for-Linux
github[2].

[1]: rust-lang/rust#116972
[2]: Rust-for-Linux#966

Signed-off-by: David Gow <[email protected]>
intel-lab-lkp pushed a commit to intel-lab-lkp/linux that referenced this issue Jul 5, 2024
At present, Rust in the kernel only supports 64-bit x86, so UML has
followed suit. However, it's significantly easier to support 32-bit i386
on UML than on bare metal, as UML does not use the -mregparm option
(which alters the ABI), which is not yet supported by rustc[1].

Add support for CONFIG_RUST on um/i386, by adding a new target config to
generate_rust_target, and replacing various checks on CONFIG_X86_64 to
also support CONFIG_X86_32.

We still use generate_rust_target, rather than a built-in rustc target,
in order to match x86_64, provide a future place for -mregparm, and more
easily disable floating point instructions.

With these changes, the KUnit tests pass with:
kunit.py run --make_options LLVM=1 --kconfig_add CONFIG_RUST=y
--kconfig_add CONFIG_64BIT=n --kconfig_add CONFIG_FORTIFY_SOURCE=n

An earlier version of these changes was proposed on the Rust-for-Linux
github[2].

[1]: rust-lang/rust#116972
[2]: Rust-for-Linux#966

Signed-off-by: David Gow <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Johannes Berg <[email protected]>
@RalfJung
Copy link
Member

It could potentially be a #121970 (comment), i.e. a target feature that is required to be set the same way for all compilation units.

Indeed, something like this has to be done for stabilization -- we have to make sure we detect linking crates that use different values for this flag.

(Also, that means without stable -Zbuild-std, this can't actually be used on stable.)

@vincenzopalazzo
Copy link
Member

Indeed, something like this has to be done for stabilization -- we have to make sure we detect linking crates that use different values for this flag.

Thanks @RalfJung and yes I think we can go through a stabilization process, I have some draft code for just llvm here vincenzopalazzo@84945fd

fmease added a commit to fmease/rust that referenced this issue Oct 22, 2024
…jubilee,pnkfelix

rust_for_linux: -Zregparm=<N> commandline flag for X86 (rust-lang#116972)

Command line flag `-Zregparm=<N>` for X86 (32-bit) for rust-for-linux: rust-lang#116972
Implemented in the similar way as fastcall/vectorcall support (args are marked InReg if fit).
bors added a commit to rust-lang-ci/rust that referenced this issue Oct 22, 2024
Rollup of 6 pull requests

Successful merges:

 - rust-lang#129935 (make unsupported_calling_conventions a hard error)
 - rust-lang#130432 (rust_for_linux: -Zregparm=<N> commandline flag for X86 (rust-lang#116972))
 - rust-lang#131697 (`rt::Argument`: elide lifetimes)
 - rust-lang#131954 (shave 150ms off bootstrap)
 - rust-lang#131982 (Represent `hir::TraitBoundModifiers` as distinct parts in HIR)
 - rust-lang#132017 (Update triagebot.toml)

r? `@ghost`
`@rustbot` modify labels: rollup
workingjubilee added a commit to workingjubilee/rustc that referenced this issue Oct 22, 2024
…jubilee,pnkfelix

rust_for_linux: -Zregparm=<N> commandline flag for X86 (rust-lang#116972)

Command line flag `-Zregparm=<N>` for X86 (32-bit) for rust-for-linux: rust-lang#116972
Implemented in the similar way as fastcall/vectorcall support (args are marked InReg if fit).
bors added a commit to rust-lang-ci/rust that referenced this issue Oct 22, 2024
…kingjubilee

Rollup of 6 pull requests

Successful merges:

 - rust-lang#130432 (rust_for_linux: -Zregparm=<N> commandline flag for X86 (rust-lang#116972))
 - rust-lang#131697 (`rt::Argument`: elide lifetimes)
 - rust-lang#131807 (Always specify `llvm_abiname` for RISC-V targets)
 - rust-lang#131954 (shave 150ms off bootstrap)
 - rust-lang#132015 (Move const trait tests from `ui/rfcs/rfc-2632-const-trait-impl` to `ui/traits/const-traits`)
 - rust-lang#132017 (Update triagebot.toml)

r? `@ghost`
`@rustbot` modify labels: rollup
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Oct 22, 2024
Rollup merge of rust-lang#130432 - azhogin:azhogin/regparm, r=workingjubilee,pnkfelix

rust_for_linux: -Zregparm=<N> commandline flag for X86 (rust-lang#116972)

Command line flag `-Zregparm=<N>` for X86 (32-bit) for rust-for-linux: rust-lang#116972
Implemented in the similar way as fastcall/vectorcall support (args are marked InReg if fit).
@ojeda
Copy link
Contributor Author

ojeda commented Nov 18, 2024

See #131749.

@ojeda ojeda closed this as completed Nov 18, 2024
antoyo pushed a commit to rust-lang/rustc_codegen_gcc that referenced this issue Dec 11, 2024
…nkfelix

rust_for_linux: -Zregparm=<N> commandline flag for X86 (#116972)

Command line flag `-Zregparm=<N>` for X86 (32-bit) for rust-for-linux: rust-lang/rust#116972
Implemented in the similar way as fastcall/vectorcall support (args are marked InReg if fit).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ABI Area: Concerning the application binary interface (ABI) C-feature-request Category: A feature request, i.e: not implemented / a PR. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants