Skip to content

Commit 3d86a30

Browse files
no9264Dennisbonke
committed
compiler: Add x86_64-unknown-managarm-mlibc target
Co-authored-by: Matt Taylor <[email protected]> Co-authored-by: Dennis Bonke <[email protected]>
1 parent a8cfc83 commit 3d86a30

File tree

7 files changed

+70
-3
lines changed

7 files changed

+70
-3
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use crate::spec::{cvs, Cc, LinkArgs, LinkerFlavor, Lld, RelroLevel, TargetOptions};
2+
3+
pub fn opts() -> TargetOptions {
4+
let mut args = LinkArgs::new();
5+
args.insert(
6+
LinkerFlavor::Gnu(Cc::Yes, Lld::No),
7+
vec![
8+
// We want to be able to strip as much executable code as possible
9+
// from the linker command line, and this flag indicates to the
10+
// linker that it can avoid linking in dynamic libraries that don't
11+
// actually satisfy any symbols up to that point (as with many other
12+
// resolutions the linker does). This option only applies to all
13+
// following libraries so we're sure to pass it as one of the first
14+
// arguments.
15+
"-Wl,--as-needed".to_string().into(),
16+
// Always enable NX protection when it is available
17+
"-Wl,-z,noexecstack".to_string().into(),
18+
],
19+
);
20+
21+
TargetOptions {
22+
os: "managarm".to_string().into(),
23+
env: "mlibc".to_string().into(),
24+
dynamic_linking: true,
25+
executables: true,
26+
families: cvs!["unix"],
27+
has_rpath: true,
28+
pre_link_args: args,
29+
position_independent_executables: true,
30+
relro_level: RelroLevel::Full,
31+
has_thread_local: true,
32+
crt_static_respected: true,
33+
..Default::default()
34+
}
35+
}

compiler/rustc_target/src/spec/base/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub(crate) mod linux_gnu;
1717
pub(crate) mod linux_musl;
1818
pub(crate) mod linux_ohos;
1919
pub(crate) mod linux_uclibc;
20+
pub(crate) mod managarm_mlibc;
2021
pub(crate) mod msvc;
2122
pub(crate) mod netbsd;
2223
pub(crate) mod nto_qnx;

compiler/rustc_target/src/spec/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,6 +1539,8 @@ supported_targets! {
15391539
("aarch64-unknown-redox", aarch64_unknown_redox),
15401540
("x86_64-unknown-redox", x86_64_unknown_redox),
15411541

1542+
("x86_64-unknown-managarm-mlibc", x86_64_unknown_managarm_mlibc),
1543+
15421544
("i386-apple-ios", i386_apple_ios),
15431545
("x86_64-apple-ios", x86_64_apple_ios),
15441546
("aarch64-apple-ios", aarch64_apple_ios),
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use crate::spec::{base, Cc, LinkerFlavor, Lld, StackProbeType, Target, TargetMetadata};
2+
3+
pub fn target() -> Target {
4+
let mut base = base::managarm_mlibc::opts();
5+
base.cpu = "x86-64".to_string().into();
6+
base.max_atomic_width = Some(64);
7+
base.pre_link_args
8+
.get_mut(&LinkerFlavor::Gnu(Cc::Yes, Lld::No))
9+
.unwrap()
10+
.push("-m64".to_string().into());
11+
// don't use probe-stack=inline-asm until rust-lang/rust#83139 is resolved.
12+
base.stack_probes = StackProbeType::Call;
13+
14+
Target {
15+
llvm_target: "x86_64-unknown-managarm-mlibc".to_string().into(),
16+
pointer_width: 64,
17+
data_layout:
18+
"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
19+
.to_string()
20+
.into(),
21+
arch: "x86_64".to_string().into(),
22+
options: base,
23+
metadata: TargetMetadata { std: Some(false), tier: Some(3), ..Default::default() },
24+
}
25+
}

src/tools/build-manifest/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ static TARGETS: &[&str] = &[
166166
"x86_64-unknown-linux-gnux32",
167167
"x86_64-unknown-linux-musl",
168168
"x86_64-unknown-linux-ohos",
169+
"x86_64-unknown-managarm-mlibc",
169170
"x86_64-unknown-netbsd",
170171
"x86_64-unknown-none",
171172
"x86_64-unknown-redox",

tests/assembly/targets/targets-elf.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,9 @@
555555
//@ revisions: x86_64_unknown_linux_ohos
556556
//@ [x86_64_unknown_linux_ohos] compile-flags: --target x86_64-unknown-linux-ohos
557557
//@ [x86_64_unknown_linux_ohos] needs-llvm-components: x86
558+
//@ revisions: x86_64_unknown_managarm_mlibc
559+
//@ [x86_64_unknown_managarm_mlibc] compile-flags: --target x86_64-unknown-managarm-mlibc
560+
//@ [x86_64_unknown_managarm_mlibc] needs-llvm-components: x86
558561
//@ revisions: x86_64_unknown_netbsd
559562
//@ [x86_64_unknown_netbsd] compile-flags: --target x86_64-unknown-netbsd
560563
//@ [x86_64_unknown_netbsd] needs-llvm-components: x86

tests/ui/check-cfg/well-known-values.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
136136
LL | target_env = "_UNEXPECTED_VALUE",
137137
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
138138
|
139-
= note: expected values for `target_env` are: ``, `gnu`, `msvc`, `musl`, `newlib`, `nto70`, `nto71`, `ohos`, `p2`, `psx`, `relibc`, `sgx`, `uclibc`
139+
= note: expected values for `target_env` are: ``, `gnu`, `mlibc`, `msvc`, `musl`, `newlib`, `nto70`, `nto71`, `ohos`, `p2`, `psx`, `relibc`, `sgx`, `uclibc`
140140
= note: see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration
141141

142142
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
@@ -190,7 +190,7 @@ warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
190190
LL | target_os = "_UNEXPECTED_VALUE",
191191
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
192192
|
193-
= 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`
193+
= 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`
194194
= note: see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration
195195

196196
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
@@ -263,7 +263,7 @@ LL | #[cfg(target_os = "linuz")] // testing that we suggest `linux`
263263
| |
264264
| help: there is a expected value with a similar name: `"linux"`
265265
|
266-
= 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`
266+
= 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`
267267
= note: see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration
268268

269269
warning: 27 warnings emitted

0 commit comments

Comments
 (0)