Skip to content

Commit b45475a

Browse files
joshtriplettmikeleany
authored andcommitted
x86_64-unknown-none: Add target documentation
In particular, document the default properties and assumptions of code built for the target. (Work on this target sponsored by Profian.)
1 parent 689d0af commit b45475a

File tree

2 files changed

+77
-1
lines changed

2 files changed

+77
-1
lines changed

src/doc/rustc/src/platform-support.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ target | std | host | notes
280280
`x86_64-unknown-haiku` | ✓ | ✓ | 64-bit Haiku
281281
`x86_64-unknown-hermit` | ? | |
282282
`x86_64-unknown-l4re-uclibc` | ? | |
283-
`x86_64-unknown-none` | * | | Freestanding/bare-metal x86_64, softfloat
283+
[`x86_64-unknown-none`](platform-support/x86_64-unknown-none.md) | * | | Freestanding/bare-metal x86_64, softfloat
284284
`x86_64-unknown-none-hermitkernel` | ? | | HermitCore kernel
285285
`x86_64-unknown-none-linuxkernel` | * | | Linux kernel modules
286286
`x86_64-unknown-openbsd` | ✓ | ✓ | 64-bit OpenBSD
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# `x86_64-unknown-none`
2+
3+
**Tier: 3**
4+
5+
Freestanding/bare-metal x86-64 binaries in ELF format: firmware, kernels, etc.
6+
7+
## Target maintainers
8+
9+
Harald Hoyer <[email protected]>, https://github.com/haraldh
10+
Mike Leany, https://github.com/mikeleany
11+
12+
## Requirements
13+
14+
This target is cross-compiled. There is no support for `std`. There is no
15+
default allocator, but it's possible to use `alloc` by supplying an allocator.
16+
17+
By default, Rust code generated for this target does not use any vector or
18+
floating-point registers (e.g. SSE, AVX). This allows the generated code to run
19+
in environments, such as kernels, which may need to avoid the use of such
20+
registers or which may have special considerations about the use of such
21+
registers (e.g. saving and restoring them to avoid breaking userspace code
22+
using the same registers). You can change code generation to use additional CPU
23+
features via the `-C target-feature=` codegen options to rustc, or via the
24+
`#[target_feature]` mechanism within Rust code.
25+
26+
By default, code generated with this target should run on any `x86_64`
27+
hardware; enabling additional target features may raise this baseline.
28+
29+
Code generated with this target will use the `kernel` code model by default.
30+
You can change this using the `-C code-model=` option to rustc.
31+
32+
On `x86_64-unknown-none`, `extern "C"` uses the [standard System V calling
33+
convention](https://gitlab.com/x86-psABIs/x86-64-ABI), without red zones.
34+
35+
This target generated binaries in the ELF format. Any alternate formats or
36+
special considerations for binary layout will require linker options or linker
37+
scripts.
38+
39+
## Building the target
40+
41+
You can build Rust with support for the target by adding it to the `target`
42+
list in `config.toml`:
43+
44+
```toml
45+
[build]
46+
build-stage = 1
47+
target = ["x86_64-unknown-none"]
48+
```
49+
50+
## Building Rust programs
51+
52+
Rust does not yet ship pre-compiled artifacts for this target. To compile for
53+
this target, you will either need to build Rust with the target enabled (see
54+
"Building the target" above), or build your own copy of `core` by using
55+
`build-std` or similar.
56+
57+
## Testing
58+
59+
As `x86_64-unknown-none` supports a variety of different environments and does
60+
not support `std`, this target does not support running the Rust testsuite.
61+
62+
## Cross-compilation toolchains and C code
63+
64+
If you want to compile C code along with Rust (such as for Rust crates with C
65+
dependencies), you will need an appropriate `x86_64` toolchain.
66+
67+
Rust *may* be able to use an `x86_64-linux-gnu-` toolchain with appropriate
68+
standalone flags to build for this toolchain (depending on the assumptions of
69+
that toolchain, see below), or you may wish to use a separate
70+
`x86_64-unknown-none` (or `x86_64-elf-`) toolchain.
71+
72+
On some `x86_64` hosts that use ELF binaries, you *may* be able to use the host
73+
C toolchain, if it does not introduce assumptions about the host environment
74+
that don't match the expectations of a standalone environment. Otherwise, you
75+
may need a separate toolchain for standalone/freestanding development, just as
76+
when cross-compiling from a non-`x86_64` platform.

0 commit comments

Comments
 (0)