Skip to content

Commit 043159f

Browse files
authored
Rollup merge of rust-lang#64051 - alex:linux-kernel-module-target, r=joshtriplett
Add x86_64-linux-kernel target This adds a target specification for Linux kernel modules on x86_64, as well as base code that can be shared with other architectures. I wasn't totally sure about what the best name for this was. There's one open question on whether we should use the LLVM generic x86_64-elf target, or the same one used for the Linux userspace. r? @joshtriplett
2 parents fd46f6e + 5e933b4 commit 043159f

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use crate::spec::{LinkArgs, LinkerFlavor, PanicStrategy, RelroLevel, TargetOptions};
2+
use std::default::Default;
3+
4+
pub fn opts() -> TargetOptions {
5+
let mut pre_link_args = LinkArgs::new();
6+
pre_link_args.insert(
7+
LinkerFlavor::Gcc,
8+
vec!["-Wl,--as-needed".to_string(), "-Wl,-z,noexecstack".to_string()],
9+
);
10+
11+
TargetOptions {
12+
disable_redzone: true,
13+
panic_strategy: PanicStrategy::Abort,
14+
stack_probes: true,
15+
eliminate_frame_pointer: false,
16+
linker_is_gnu: true,
17+
position_independent_executables: true,
18+
needs_plt: true,
19+
relro_level: RelroLevel::Full,
20+
relocation_model: "static".to_string(),
21+
target_family: Some("unix".to_string()),
22+
pre_link_args,
23+
24+
..Default::default()
25+
}
26+
}

src/librustc_target/spec/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ mod freebsd_base;
5353
mod haiku_base;
5454
mod hermit_base;
5555
mod linux_base;
56+
mod linux_kernel_base;
5657
mod linux_musl_base;
5758
mod openbsd_base;
5859
mod netbsd_base;
@@ -386,6 +387,8 @@ supported_targets! {
386387
("thumbv7neon-linux-androideabi", thumbv7neon_linux_androideabi),
387388
("aarch64-linux-android", aarch64_linux_android),
388389

390+
("x86_64-linux-kernel", x86_64_linux_kernel),
391+
389392
("aarch64-unknown-freebsd", aarch64_unknown_freebsd),
390393
("armv6-unknown-freebsd", armv6_unknown_freebsd),
391394
("armv7-unknown-freebsd", armv7_unknown_freebsd),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// This defines the amd64 target for the Linux Kernel. See the linux-kernel-base module for
2+
// generic Linux kernel options.
3+
4+
use crate::spec::{LinkerFlavor, Target, TargetResult};
5+
6+
pub fn target() -> TargetResult {
7+
let mut base = super::linux_kernel_base::opts();
8+
base.cpu = "x86-64".to_string();
9+
base.max_atomic_width = Some(64);
10+
base.features =
11+
"-mmx,-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-3dnow,-3dnowa,-avx,-avx2,+soft-float"
12+
.to_string();
13+
base.code_model = Some("kernel".to_string());
14+
base.pre_link_args.get_mut(&LinkerFlavor::Gcc).unwrap().push("-m64".to_string());
15+
16+
Ok(Target {
17+
// FIXME: Some dispute, the linux-on-clang folks think this should use "Linux"
18+
llvm_target: "x86_64-elf".to_string(),
19+
target_endian: "little".to_string(),
20+
target_pointer_width: "64".to_string(),
21+
target_c_int_width: "32".to_string(),
22+
data_layout: "e-m:e-i64:64-f80:128-n8:16:32:64-S128".to_string(),
23+
target_os: "none".to_string(),
24+
target_env: "gnu".to_string(),
25+
target_vendor: "unknown".to_string(),
26+
arch: "x86_64".to_string(),
27+
linker_flavor: LinkerFlavor::Gcc,
28+
29+
options: base,
30+
})
31+
}

0 commit comments

Comments
 (0)