Skip to content

Commit aabc669

Browse files
committed
feat: add aarch64-hyperlight-none target support
- Add aarch64-hyperlight-none target spec derived from aarch64-unknown-none with hyperlight customizations - Select correct musl arch headers (aarch64 vs x86_64) - Use appropriate clang --target for aarch64 - Make -mno-red-zone x86_64-only (aarch64 has no red zone) - Fix get_spec to pass --target as CLI arg instead of env var Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
1 parent 2723f3b commit aabc669

File tree

2 files changed

+43
-12
lines changed

2 files changed

+43
-12
lines changed

src/sysroot.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,27 @@ pub fn build(args: &Args) -> Result<()> {
4545
spec.remove("rustc-abi");
4646
spec
4747
}
48+
"aarch64-hyperlight-none" => {
49+
let mut spec = get_spec(args, "aarch64-unknown-none")?;
50+
let Value::Object(custom) = json!({
51+
"code-model": "small",
52+
"linker": "rust-lld",
53+
"linker-flavor": "gnu-lld",
54+
"pre-link-args": {
55+
"gnu-lld": ["-znostart-stop-gc"],
56+
},
57+
}) else {
58+
unreachable!()
59+
};
60+
spec.extend(custom);
61+
spec.remove("rustc-abi");
62+
spec
63+
}
4864
triplet => bail!(
4965
"Unsupported target triple: {triplet:?}
5066
Supported values are:
51-
* x86_64-hyperlight-none"
67+
* x86_64-hyperlight-none
68+
* aarch64-hyperlight-none"
5269
),
5370
};
5471

@@ -180,7 +197,8 @@ fn get_spec(args: &Args, triplet: impl AsRef<str>) -> Result<Map<String, Value>>
180197
.envs(args.env.iter())
181198
.current_dir(&args.current_dir)
182199
.arg("rustc")
183-
.target(triplet)
200+
.arg("--target")
201+
.arg(triplet.as_ref())
184202
.manifest_path(&args.manifest_path)
185203
.arg("-Zunstable-options")
186204
.arg("--print=target-spec-json")

src/toolchain.rs

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,21 @@ pub fn prepare(args: &Args) -> Result<()> {
5353
std::fs::create_dir_all(&include_dst_dir)
5454
.context("Failed to create sysroot include directory")?;
5555

56-
const INCLUDE_DIRS: &[&str] = &[
56+
let arch_dir = if args.target.starts_with("aarch64") {
57+
"third_party/musl/arch/aarch64"
58+
} else {
59+
"third_party/musl/arch/x86_64"
60+
};
61+
62+
let include_dirs: &[&str] = &[
5763
"third_party/printf/",
5864
"third_party/musl/include",
5965
"third_party/musl/arch/generic",
60-
"third_party/musl/arch/x86_64",
66+
arch_dir,
6167
"third_party/musl/src/internal",
6268
];
6369

64-
for dir in INCLUDE_DIRS {
70+
for dir in include_dirs {
6571
let include_src_dir = hyperlight_guest_bin_dir.join(dir);
6672
let files = glob::glob(&format!("{}/**/*.h", include_src_dir.display()))
6773
.context("Failed to read include source directory")?;
@@ -81,19 +87,21 @@ pub fn prepare(args: &Args) -> Result<()> {
8187
}
8288

8389
pub fn cflags(args: &Args) -> OsString {
84-
const FLAGS: &[&str] = &[
85-
// terrible hack, see
86-
// https://github.com/hyperlight-dev/hyperlight/blob/main/src/hyperlight_guest_bin/build.rs#L80
87-
"--target=x86_64-unknown-linux-none",
90+
let clang_target = if args.target.starts_with("aarch64") {
91+
"--target=aarch64-unknown-linux-none"
92+
} else {
93+
"--target=x86_64-unknown-linux-none"
94+
};
95+
96+
let common_flags: &[&str] = &[
97+
clang_target,
8898
"-U__linux__",
89-
// Our rust target also has this set since it based off "x86_64-unknown-none"
9099
"-fPIC",
91100
// We don't support stack protectors at the moment, but Arch Linux clang
92101
// auto-enables them for -linux platforms, so explicitly disable them.
93102
"-fno-stack-protector",
94103
"-fstack-clash-protection",
95104
"-mstack-probe-size=4096",
96-
"-mno-red-zone",
97105
"-nostdinc",
98106
// Define HYPERLIGHT as we use this to conditionally enable/disable code
99107
// in the libc headers
@@ -102,10 +110,15 @@ pub fn cflags(args: &Args) -> OsString {
102110
];
103111

104112
let mut flags = OsString::new();
105-
for flag in FLAGS {
113+
for flag in common_flags {
106114
flags.push(flag);
107115
flags.push(" ");
108116
}
117+
118+
// x86_64-specific flags
119+
if args.target.starts_with("x86_64") {
120+
flags.push("-mno-red-zone ");
121+
}
109122
flags.push(" ");
110123
flags.push("-isystem");
111124
flags.push(" ");

0 commit comments

Comments
 (0)