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

Add managarm as a tier 3 target #123319

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions compiler/rustc_target/src/spec/base/managarm_mlibc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use crate::spec::{cvs, RelroLevel, TargetOptions};

pub fn opts() -> TargetOptions {
TargetOptions {
os: "managarm".to_string().into(),
env: "mlibc".to_string().into(),
dynamic_linking: true,
executables: true,
families: cvs!["unix"],
has_rpath: true,
position_independent_executables: true,
relro_level: RelroLevel::Full,
has_thread_local: true,
crt_static_respected: true,
..Default::default()
}
}
1 change: 1 addition & 0 deletions compiler/rustc_target/src/spec/base/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub(crate) mod linux_gnu;
pub(crate) mod linux_musl;
pub(crate) mod linux_ohos;
pub(crate) mod linux_uclibc;
pub(crate) mod managarm_mlibc;
pub(crate) mod msvc;
pub(crate) mod netbsd;
pub(crate) mod nto_qnx;
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1539,6 +1539,8 @@ supported_targets! {
("aarch64-unknown-redox", aarch64_unknown_redox),
("x86_64-unknown-redox", x86_64_unknown_redox),

("x86_64-unknown-managarm-mlibc", x86_64_unknown_managarm_mlibc),

("i386-apple-ios", i386_apple_ios),
("x86_64-apple-ios", x86_64_apple_ios),
("aarch64-apple-ios", aarch64_apple_ios),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use crate::spec::{base, Cc, LinkerFlavor, Lld, StackProbeType, Target, TargetMetadata};

pub fn target() -> Target {
let mut base = base::managarm_mlibc::opts();
base.cpu = "x86-64".to_string().into();
base.max_atomic_width = Some(64);
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64"]);
base.stack_probes = StackProbeType::Inline;

Target {
llvm_target: "x86_64-unknown-managarm-mlibc".to_string().into(),
pointer_width: 64,
data_layout:
"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
.to_string()
.into(),
arch: "x86_64".to_string().into(),
options: base,
metadata: TargetMetadata { std: Some(false), tier: Some(3), ..Default::default() },
}
}
1 change: 1 addition & 0 deletions src/doc/rustc/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
- [\*-nto-qnx-\*](platform-support/nto-qnx.md)
- [*-unikraft-linux-musl](platform-support/unikraft-linux-musl.md)
- [*-unknown-hermit](platform-support/hermit.md)
- [\*-unknown-managarm-mlibc](platform-support/managarm.md)
- [\*-unknown-netbsd\*](platform-support/netbsd.md)
- [*-unknown-openbsd](platform-support/openbsd.md)
- [\*-unknown-uefi](platform-support/unknown-uefi.md)
Expand Down
1 change: 1 addition & 0 deletions src/doc/rustc/src/platform-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ target | std | host | notes
`x86_64-unknown-haiku` | ✓ | ✓ | 64-bit Haiku
[`x86_64-unknown-hermit`](platform-support/hermit.md) | ✓ | | x86_64 Hermit
`x86_64-unknown-l4re-uclibc` | ? | |
[`x86_64-unknown-managarm-mlibc`](platform-support/managarm.md) | | | x86_64 managarm
[`x86_64-unknown-openbsd`](platform-support/openbsd.md) | ✓ | ✓ | 64-bit OpenBSD
`x86_64-uwp-windows-gnu` | ✓ | |
`x86_64-uwp-windows-msvc` | ✓ | |
Expand Down
53 changes: 53 additions & 0 deletions src/doc/rustc/src/platform-support/managarm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# `*-unknown-managarm-mlibc`

**Tier: 3**

## Target Maintainers

- [@no92](https://github.com/no92)
- [@64](https://github.com/64)
- [@Dennisbonke](https://github.com/Dennisbonke)

## Requirements

This target is cross-compiled. There is currently no support for `std` yet. It generates binaries in the ELF format.

## Building the target

For now, building a patched LLVM with [our patches located here](https://github.com/managarm/bootstrap-managarm/tree/master/patches/llvm) is necessary.
Copy link
Member

Choose a reason for hiding this comment

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

@wesleywiser do we have any other targets which need a patched LLVM? I think we might want this to wait for support to exist in LLVM?

Copy link
Member

Choose a reason for hiding this comment

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

I don't think any other targets currently need a patched LLVM to build (of course, newer LLVMs might work better). If I remember correctly, the loongarch targets waited until we had updated to a version of LLVM with sufficient support to link libcore before being merged.

@no92 is there urgency to land this PR now or can we wait until an LLVM release picks up support for managarm?

Copy link

@64 64 Apr 5, 2024

Choose a reason for hiding this comment

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

There's no urgency, so we're happy to merge our changes into LLVM first if that makes more sense.

But it would be nice if we could get this merged fairly soon after our changes hit LLVM master, because it blocks us upstreaming our changes to other Rust crates, and that's the bulk of the maintenance effort on our end: supporting locally patched crates (and sometimes multiple versions thereof!) has proved quite tricky to manage

Anyway, we'll check back once our LLVM changes are merged and see how people feel :)


Once that is done, set up your `config.toml` like this:

```toml
change-id = 102579

[llvm]
targets = "X86"
download-ci-llvm = false

[build]
target = ["x86_64-unknown-managarm-mlibc", "x86_64-unknown-linux-gnu"]

[target.x86_64-unknown-linux-gnu]
llvm-config = "/path/to/your/llvm/bin/llvm-config"

[target.x86_64-unknown-managarm-mlibc]
llvm-config = "/path/to/your/llvm/bin/llvm-config"
```

## Building Rust programs

Build a `x86_64-managarm-gcc` using our [gcc fork](https://github.com/managarm/gcc).
Copy link
Member

Choose a reason for hiding this comment

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

Does lld not work for this target?

Copy link
Author

Choose a reason for hiding this comment

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

Using lld is not a supported and tested option for us right now.


```toml
[build]
rustc = "/path/to/the/rust-prefix/bin/rustc"
target = "x86_64-unknown-managarm-mlibc"

[target.x86_64-unknown-managarm-mlibc]
linker = "/path/to/the/managarm-gcc/bin/x86_64-managarm-gcc"
```

## Testing

This target does not support running the Rust testsuite yet.
1 change: 1 addition & 0 deletions src/tools/build-manifest/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ static TARGETS: &[&str] = &[
"x86_64-unknown-linux-gnux32",
"x86_64-unknown-linux-musl",
"x86_64-unknown-linux-ohos",
"x86_64-unknown-managarm-mlibc",
"x86_64-unknown-netbsd",
"x86_64-unknown-none",
"x86_64-unknown-redox",
Expand Down
3 changes: 3 additions & 0 deletions tests/assembly/targets/targets-elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,9 @@
//@ revisions: x86_64_unknown_linux_ohos
//@ [x86_64_unknown_linux_ohos] compile-flags: --target x86_64-unknown-linux-ohos
//@ [x86_64_unknown_linux_ohos] needs-llvm-components: x86
//@ revisions: x86_64_unknown_managarm_mlibc
//@ [x86_64_unknown_managarm_mlibc] compile-flags: --target x86_64-unknown-managarm-mlibc
//@ [x86_64_unknown_managarm_mlibc] needs-llvm-components: x86
//@ revisions: x86_64_unknown_netbsd
//@ [x86_64_unknown_netbsd] compile-flags: --target x86_64-unknown-netbsd
//@ [x86_64_unknown_netbsd] needs-llvm-components: x86
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/check-cfg/well-known-values.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
LL | target_env = "_UNEXPECTED_VALUE",
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: expected values for `target_env` are: ``, `gnu`, `msvc`, `musl`, `newlib`, `nto70`, `nto71`, `ohos`, `p2`, `psx`, `relibc`, `sgx`, `uclibc`
= note: expected values for `target_env` are: ``, `gnu`, `mlibc`, `msvc`, `musl`, `newlib`, `nto70`, `nto71`, `ohos`, `p2`, `psx`, `relibc`, `sgx`, `uclibc`
= note: see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration

warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
Expand Down Expand Up @@ -190,7 +190,7 @@ warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
LL | target_os = "_UNEXPECTED_VALUE",
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: expected values for `target_os` are: `aix`, `android`, `cuda`, `dragonfly`, `emscripten`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `hermit`, `horizon`, `hurd`, `illumos`, `ios`, `l4re`, `linux`, `macos`, `netbsd`, `none`, `nto`, `openbsd`, `psp`, `redox`, `solaris`, `solid_asp3`, `teeos`, `tvos`, `uefi`, `unknown`, `vita`, `vxworks`, `wasi`, `watchos`, `windows`, `xous`, `zkvm`
= note: expected values for `target_os` are: `aix`, `android`, `cuda`, `dragonfly`, `emscripten`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `hermit`, `horizon`, `hurd`, `illumos`, `ios`, `l4re`, `linux`, `macos`, `managarm`, `netbsd`, `none`, `nto`, `openbsd`, `psp`, `redox`, `solaris`, `solid_asp3`, `teeos`, `tvos`, `uefi`, `unknown`, `vita`, `vxworks`, `wasi`, `watchos`, `windows`, `xous`, `zkvm`
= note: see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration

warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
Expand Down Expand Up @@ -263,7 +263,7 @@ LL | #[cfg(target_os = "linuz")] // testing that we suggest `linux`
| |
| help: there is a expected value with a similar name: `"linux"`
|
= note: expected values for `target_os` are: `aix`, `android`, `cuda`, `dragonfly`, `emscripten`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `hermit`, `horizon`, `hurd`, `illumos`, `ios`, `l4re`, `linux`, `macos`, `netbsd`, `none`, `nto`, `openbsd`, `psp`, `redox`, `solaris`, `solid_asp3`, `teeos`, `tvos`, `uefi`, `unknown`, `vita`, `vxworks`, `wasi`, `watchos`, `windows`, `xous`, `zkvm`
= note: expected values for `target_os` are: `aix`, `android`, `cuda`, `dragonfly`, `emscripten`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `hermit`, `horizon`, `hurd`, `illumos`, `ios`, `l4re`, `linux`, `macos`, `managarm`, `netbsd`, `none`, `nto`, `openbsd`, `psp`, `redox`, `solaris`, `solid_asp3`, `teeos`, `tvos`, `uefi`, `unknown`, `vita`, `vxworks`, `wasi`, `watchos`, `windows`, `xous`, `zkvm`
= note: see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration

warning: 27 warnings emitted
Expand Down
Loading