Skip to content

Commit

Permalink
Add *-unwind* target specs
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Spinale <[email protected]>
  • Loading branch information
nspin committed Oct 31, 2024
1 parent 66c726d commit 878b179
Show file tree
Hide file tree
Showing 43 changed files with 700 additions and 17 deletions.
36 changes: 27 additions & 9 deletions crates/sel4-generate-target-specs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::fs;
use std::path::Path;

use rustc_target::json::ToJson;
use rustc_target::spec::{Cc, CodeModel, LinkerFlavor, Lld, Target, TargetTriple};
use rustc_target::spec::{Cc, CodeModel, LinkerFlavor, Lld, PanicStrategy, Target, TargetTriple};

use clap::{Arg, ArgAction, Command};

Expand All @@ -23,6 +23,7 @@ struct Config {
arch: Arch,
context: Context,
minimal: bool,
unwind: bool,
musl: bool,
}

Expand Down Expand Up @@ -107,7 +108,7 @@ impl Config {
let options = &mut target.options;
options.is_builtin = false;
options.exe_suffix = ".elf".into();
options.eh_frame_header = self.arch.unwinding_support() && !self.minimal;
options.eh_frame_header = self.unwinding_support();
}

if let Context::Microkit { resettable } = &self.context {
Expand All @@ -122,6 +123,10 @@ impl Config {

target.options.has_thread_local = !self.minimal;

if self.unwinding_support() {
target.options.panic_strategy = PanicStrategy::Unwind;
}

if self.musl {
let options = &mut target.options;
options.os = "linux".into();
Expand All @@ -134,10 +139,17 @@ impl Config {
target
}

fn unwinding_support(&self) -> bool {
self.arch.unwinding_support() && self.unwind
}

fn filter(&self) -> bool {
if self.context.is_microkit() && !self.arch.microkit_support() {
return false;
}
if self.unwinding_support() && self.minimal {
return false;
}
if self.musl && (self.minimal || self.context.is_microkit()) {
return false;
}
Expand All @@ -156,6 +168,9 @@ impl Config {
if self.minimal {
name.push_str("-minimal");
}
if self.unwind {
name.push_str("-unwind");
}
if self.musl {
name.push_str("-musl");
}
Expand All @@ -167,13 +182,16 @@ impl Config {
for arch in Arch::all() {
for context in Context::all() {
for minimal in [true, false] {
for musl in [true, false] {
all.push(Self {
arch,
context,
minimal,
musl,
});
for unwind in [true, false] {
for musl in [true, false] {
all.push(Self {
arch,
context,
minimal,
unwind,
musl,
});
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions hacking/nix/scope/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ superCallPackage ../rust-utils {} self //
{ microkit ? false
, resettable ? false
, minimal ? false
, unwind ? false
, musl ? false
}:
lib.concatStrings [
Expand All @@ -169,6 +170,7 @@ superCallPackage ../rust-utils {} self //
(lib.optionalString microkit "-microkit")
(lib.optionalString resettable "-resettable")
(lib.optionalString minimal "-minimal")
(lib.optionalString unwind "-unwind")
(lib.optionalString musl "-musl")
];

Expand Down
12 changes: 4 additions & 8 deletions hacking/nix/scope/world/instances/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ in rec {
orig = mkTask {
rootCrate = crates.tests-root-task-backtrace;
release = false;
targetTriple = mkSeL4RustTargetTriple { unwind = true; };
extraProfile = {
panic = "unwind";
opt-level = 2;
};
};
Expand Down Expand Up @@ -343,10 +343,8 @@ in rec {
threads = maybe (haveFullRuntime && haveCapDLInitializer) (mkInstance rec {
test = mkTask {
rootCrate = crates.tests-capdl-threads-components-test;
targetTriple = mkSeL4RustTargetTriple { unwind = true; };
release = true; # test optimizations
extraProfile = {
panic = "unwind";
};
};
rootTask = mkCapDLInitializer {
small = false;
Expand All @@ -367,10 +365,8 @@ in rec {
utcover = maybe (haveFullRuntime && haveCapDLInitializer) (mkInstance rec {
test = mkTask {
rootCrate = crates.tests-capdl-utcover-components-test;
targetTriple = mkSeL4RustTargetTriple { unwind = true; };
release = false;
extraProfile = {
panic = "unwind";
};
};
rootTask = mkCapDLInitializer {
small = true;
Expand Down Expand Up @@ -417,8 +413,8 @@ in rec {
example-root-task-without-runtime = maybe haveMinimalRuntime (mkInstance {
rootTask = mkTask {
rootCrate = crates.example-root-task-without-runtime;
release = false;
targetTriple = mkSeL4RustTargetTriple { minimal = true; };
release = false;
};
extraPlatformArgs = lib.optionalAttrs canSimulate {
canAutomateSimply = true;
Expand Down
3 changes: 3 additions & 0 deletions support/targets/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ your Rust toolchain.
The difference between the `*-minimal` targets and the non-minimal ones are that the minimal ones
have `"has-thread-local": false`.

The difference between the `*-unwind` targets and the non-unwind ones are that the unwind ones have
`"panic = "unwind"`.

The difference between the `*-sel4-microkit` targets and the `*-sel4` ones is that the
`*-sel4-microkit` targets include a linker script fragment to add the `__sel4_ipc_buffer_obj` symbol
required by the `microkit` tool.
Expand Down
35 changes: 35 additions & 0 deletions support/targets/aarch64-sel4-microkit-resettable-unwind.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"arch": "aarch64",
"crt-objects-fallback": "false",
"data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32",
"disable-redzone": true,
"exe-suffix": ".elf",
"features": "+v8a,+strict-align,+neon,+fp-armv8",
"has-thread-local": true,
"link-script": "SECTIONS {\n .persistent : {\n *(.persistent .persistent.*)\n }\n} INSERT BEFORE .data;\n\nASSERT(DEFINED(_reset), \"_reset is not defined\")\n\nENTRY(_reset)\n__sel4_ipc_buffer_obj = (__ehdr_start & ~(4096 - 1)) - 4096;",
"linker": "rust-lld",
"linker-flavor": "gnu-lld",
"llvm-target": "aarch64-unknown-none",
"max-atomic-width": 128,
"metadata": {
"description": null,
"host_tools": null,
"std": null,
"tier": null
},
"pre-link-args": {
"gnu-lld": [
"-z",
"max-page-size=4096"
]
},
"relocation-model": "static",
"stack-probes": {
"kind": "inline"
},
"supported-sanitizers": [
"kcfi",
"kernel-address"
],
"target-pointer-width": "64"
}
1 change: 1 addition & 0 deletions support/targets/aarch64-sel4-microkit-resettable.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"crt-objects-fallback": "false",
"data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32",
"disable-redzone": true,
"eh-frame-header": false,
"exe-suffix": ".elf",
"features": "+v8a,+strict-align,+neon,+fp-armv8",
"has-thread-local": true,
Expand Down
35 changes: 35 additions & 0 deletions support/targets/aarch64-sel4-microkit-unwind.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"arch": "aarch64",
"crt-objects-fallback": "false",
"data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32",
"disable-redzone": true,
"exe-suffix": ".elf",
"features": "+v8a,+strict-align,+neon,+fp-armv8",
"has-thread-local": true,
"link-script": "__sel4_ipc_buffer_obj = (__ehdr_start & ~(4096 - 1)) - 4096;",
"linker": "rust-lld",
"linker-flavor": "gnu-lld",
"llvm-target": "aarch64-unknown-none",
"max-atomic-width": 128,
"metadata": {
"description": null,
"host_tools": null,
"std": null,
"tier": null
},
"pre-link-args": {
"gnu-lld": [
"-z",
"max-page-size=4096"
]
},
"relocation-model": "static",
"stack-probes": {
"kind": "inline"
},
"supported-sanitizers": [
"kcfi",
"kernel-address"
],
"target-pointer-width": "64"
}
1 change: 1 addition & 0 deletions support/targets/aarch64-sel4-microkit.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"crt-objects-fallback": "false",
"data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32",
"disable-redzone": true,
"eh-frame-header": false,
"exe-suffix": ".elf",
"features": "+v8a,+strict-align,+neon,+fp-armv8",
"has-thread-local": true,
Expand Down
1 change: 1 addition & 0 deletions support/targets/aarch64-sel4-musl.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"crt-static-respected": true,
"data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32",
"disable-redzone": true,
"eh-frame-header": false,
"env": "musl",
"exe-suffix": ".elf",
"features": "+v8a,+strict-align,+neon,+fp-armv8",
Expand Down
41 changes: 41 additions & 0 deletions support/targets/aarch64-sel4-unwind-musl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"arch": "aarch64",
"crt-objects-fallback": "false",
"crt-static-default": true,
"crt-static-respected": true,
"data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32",
"disable-redzone": true,
"env": "musl",
"exe-suffix": ".elf",
"features": "+v8a,+strict-align,+neon,+fp-armv8",
"has-thread-local": true,
"linker": "rust-lld",
"linker-flavor": "gnu-lld",
"llvm-target": "aarch64-unknown-none",
"max-atomic-width": 128,
"metadata": {
"description": null,
"host_tools": null,
"std": null,
"tier": null
},
"os": "linux",
"pre-link-args": {
"gnu-lld": [
"-z",
"max-page-size=4096"
]
},
"relocation-model": "static",
"stack-probes": {
"kind": "inline"
},
"supported-sanitizers": [
"kcfi",
"kernel-address"
],
"target-family": [
"unix"
],
"target-pointer-width": "64"
}
34 changes: 34 additions & 0 deletions support/targets/aarch64-sel4-unwind.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"arch": "aarch64",
"crt-objects-fallback": "false",
"data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32",
"disable-redzone": true,
"exe-suffix": ".elf",
"features": "+v8a,+strict-align,+neon,+fp-armv8",
"has-thread-local": true,
"linker": "rust-lld",
"linker-flavor": "gnu-lld",
"llvm-target": "aarch64-unknown-none",
"max-atomic-width": 128,
"metadata": {
"description": null,
"host_tools": null,
"std": null,
"tier": null
},
"pre-link-args": {
"gnu-lld": [
"-z",
"max-page-size=4096"
]
},
"relocation-model": "static",
"stack-probes": {
"kind": "inline"
},
"supported-sanitizers": [
"kcfi",
"kernel-address"
],
"target-pointer-width": "64"
}
1 change: 1 addition & 0 deletions support/targets/aarch64-sel4.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"crt-objects-fallback": "false",
"data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32",
"disable-redzone": true,
"eh-frame-header": false,
"exe-suffix": ".elf",
"features": "+v8a,+strict-align,+neon,+fp-armv8",
"has-thread-local": true,
Expand Down
25 changes: 25 additions & 0 deletions support/targets/armv7a-sel4-minimal-unwind.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"abi": "eabi",
"arch": "arm",
"c-enum-min-bits": 8,
"crt-objects-fallback": "false",
"data-layout": "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64",
"disable-redzone": true,
"eh-frame-header": false,
"emit-debug-gdb-scripts": false,
"exe-suffix": ".elf",
"features": "+v7,+thumb2,+soft-float,-neon,+strict-align",
"linker": "rust-lld",
"linker-flavor": "gnu-lld",
"llvm-target": "armv7a-none-eabi",
"max-atomic-width": 64,
"metadata": {
"description": null,
"host_tools": null,
"std": null,
"tier": null
},
"panic-strategy": "abort",
"relocation-model": "static",
"target-pointer-width": "32"
}
33 changes: 33 additions & 0 deletions support/targets/armv7a-sel4-unwind-musl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"abi": "eabi",
"arch": "arm",
"c-enum-min-bits": 8,
"crt-objects-fallback": "false",
"crt-static-default": true,
"crt-static-respected": true,
"data-layout": "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64",
"disable-redzone": true,
"eh-frame-header": false,
"emit-debug-gdb-scripts": false,
"env": "musl",
"exe-suffix": ".elf",
"features": "+v7,+thumb2,+soft-float,-neon,+strict-align",
"has-thread-local": true,
"linker": "rust-lld",
"linker-flavor": "gnu-lld",
"llvm-target": "armv7a-none-eabi",
"max-atomic-width": 64,
"metadata": {
"description": null,
"host_tools": null,
"std": null,
"tier": null
},
"os": "linux",
"panic-strategy": "abort",
"relocation-model": "static",
"target-family": [
"unix"
],
"target-pointer-width": "32"
}
Loading

0 comments on commit 878b179

Please sign in to comment.