rust-lang / compiler-team

A home for compiler team planning documents, meeting minutes, and other such things.
https://rust-lang.github.io/compiler-team/
Apache License 2.0
387 stars 69 forks source link

Tier 3 target proposal: x86_64-unknown-none (freestanding/bare-metal x86-64) #462

Closed joshtriplett closed 3 years ago

joshtriplett commented 3 years ago

This compiler MCP proposes a new target, x86_64-unknown-none, for standalone or "freestanding" x86-64 binaries with no operating system, using ELF as the object format. This target is intended for firmware, kernels, modules, and other software running without an operating system.

This target will not provide an implementation of std, since that would depend on an operating system. This target will not provide a default allocator, but can provide an implementation of alloc if the user of the target supplies an allocator.

The x86_64-unknown-none target will default to not allowing the use of any vector or floating-point registers, because kernels, modules, and similar software needs special care to use such registers. For instance, the Linux kernel normally optimizes the entry and exit of the kernel by not saving and restoring such registers; kernel code must explicitly request the use of such registers before running code that uses them, and once requested, the kernel must pay the additional overhead of saving the userspace registers to make way for the kernel usage. Users of the x86_64-unknown-none target can still opt into the use of such registers via the target-feature mechanism, either for an entire program or for individual functions.

This target has a lot in common with x86_64-unknown-none-linuxkernel, but is intended to be general enough to work for any standalone/freestanding software without requiring a specific target for each such environment.

I plan to work to get this target to tier 2, but the target needs to start out at tier 3 and work its way up.

Checking off the target tier policy requirements for tier 3:

Harald Hoyer harald@profian.com, https://github.com/haraldh Mike Leany, https://github.com/mikeleany

Standalone targets have had a variety of names in different compilers. Some compilers and embedded toolchains use the name x86_64-unknown-elf for such targets; in other toolchains, however, -elf may imply some minimal amount of C library support. Rust has several standalone targets for various architectures; RISC-V standalone targets use none-elf (e.g. riscv64gc-unknown-none-elf), while most other standalone targets use just none (e.g. aarch64-unknown-none, mipsel-unknown-none) or none with an unrelated suffix for the ABI (e.g. armv7r-none-eabi, armv7a-none-eabi). There is also precedent in the form of the x86_64-unknown-none-linuxkernel and x86_64-unknown-none-hermitkernel targets.

This target proposal chooses to use x86_64-unknown-none, to avoid any connotations of library support, for consistency with more existing Rust targets, and for consistency with the existing Rust x86_64 kernel-specific targets.

✅ The x86_64-unknown-none target will not introduce any legal issues or new legal terms.

✅ The x86_64-unknown-none target will not introduce any new dependencies or licenses at all.

✅ The pull requests adding and maintaining this target will of course be under the standard Rust license.

✅ This target adds no new dependencies of any kind.

✅ The target will not support host tools (nor does the target have any proprietary libraries, or any libraries at all).

✅ The target will use a normal toolchain.

✅ Understood.

I'm being paid to work on this target. I am not part of any approval decisions regarding the tier status of the target.

✅ The x86_64-unknown-none target will implement core, and will support users using alloc with their own memory allocator. The x86_64-unknown-none target will not support std, and will not provide a default memory allocator.

✅ Building for the target does not require any special considerations. However, for completeness, the PR adding the target will provide documentation to that effect.

The target does not support running tests.

✅ Understood.

✅ This target has some common functionality with the x86_64-unknown-none-linuxkernel target. After adding the x86_64-unknown-none target, a follow-up PR may coordinate with the maintainers of the Linux kernel target to share this functionality. The addition of x86_64-unknown-none will not knowingly break any other target.

Work sponsored by Profian.

Process

The main points of the Major Change Process are as follows:

You can read more about Major Change Proposals on forge.

Comments

This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.

rustbot commented 3 years ago

This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.

cc @rust-lang/compiler @rust-lang/compiler-contributors

joshtriplett commented 3 years ago

(Fixed the issue title, and the Zulip stream link.)

wesleywiser commented 3 years ago

@rustbot second

apiraino commented 3 years ago

@rustbot label -final-comment-period +major-change-accepted

bstrie commented 2 years ago

I plan to work to get this target to tier 2, but the target needs to start out at tier 3 and work its way up.

@joshtriplett , how can I help get this to Tier 2?

joshtriplett commented 2 years ago

@bstrie I think it needs a combination of an MCP that documents the target meeting the tier 2 requirements, and a draft PR to rust-lang/rust CI adding a build of it.