From b856928bf8d1c17073105fd79bffe39eadf21179 Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Fri, 4 Mar 2022 14:26:09 +0100 Subject: [PATCH 01/36] rust: target: factor out and disable `emit-debug-gdb-scripts` This option was added in `rustc` in order to disable GDB scripts for some no-`std` targets, see https://github.com/rust-lang/rust/issues/44993. Therefore, even though the default in the compiler for targets is `true`, we leave it as `false`. If, in the future, it gets enabled, then we should take into account the `CONFIG_GDB_SCRIPTS` option. Signed-off-by: Miguel Ojeda --- scripts/generate_rust_target.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/generate_rust_target.rs b/scripts/generate_rust_target.rs index b4605d5933b21f..0bb9f65d1e407c 100644 --- a/scripts/generate_rust_target.rs +++ b/scripts/generate_rust_target.rs @@ -211,7 +211,6 @@ fn main() { "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128", ); ts.push("disable-redzone", true); - ts.push("emit-debug-gdb-scripts", false); ts.push("features", "+strict-align,+neon,+fp-armv8"); ts.push("frame-pointer", "always"); ts.push("llvm-target", "aarch64-unknown-none"); @@ -254,7 +253,6 @@ fn main() { } ts.push("code-model", "medium"); ts.push("disable-redzone", true); - ts.push("emit-debug-gdb-scripts", false); let mut features = "+m,+a".to_string(); if cfg.has("RISCV_ISA_C") { features += ",+c"; @@ -274,7 +272,6 @@ fn main() { "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128", ); ts.push("disable-redzone", true); - ts.push("emit-debug-gdb-scripts", false); ts.push( "features", "-mmx,-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-3dnow,-3dnowa,-avx,-avx2,+soft-float", @@ -292,6 +289,7 @@ fn main() { panic!("Unsupported architecture"); } + ts.push("emit-debug-gdb-scripts", false); ts.push("env", "gnu"); ts.push("function-sections", false); ts.push("linker-is-gnu", true); From a37c0c23e8d3ddb45a464112d4c841eaf5f72eae Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Fri, 4 Mar 2022 14:27:24 +0100 Subject: [PATCH 02/36] rust: target: factor out and disable `stack-probes` Some months ago we disabled stack probes support due to a bug in LLVM, see commit 53bc4d452e2f ("rust: disable stack probes"). Until either the bug is solved or we decide to use other kind of probes, keep this disabled for all architectures. Signed-off-by: Miguel Ojeda --- scripts/generate_rust_target.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/scripts/generate_rust_target.rs b/scripts/generate_rust_target.rs index 0bb9f65d1e407c..e979057d60fdea 100644 --- a/scripts/generate_rust_target.rs +++ b/scripts/generate_rust_target.rs @@ -184,8 +184,6 @@ fn main() { ]), )]; - let stack_probes = vec![("kind".to_string(), Value::String("none".to_string()))]; - if cfg.has("ARM") { ts.push("arch", "arm"); ts.push( @@ -217,7 +215,6 @@ fn main() { ts.push("max-atomic-width", 128); ts.push("needs-plt", true); ts.push("pre-link-args", pre_link_args_64); - ts.push("stack-probes", stack_probes); ts.push("target-c-int-width", "32"); ts.push("target-pointer-width", "64"); ts.push("vendor", ""); @@ -261,7 +258,6 @@ fn main() { ts.push("frame-pointer", "always"); ts.push("needs-plt", true); ts.push("target-c-int-width", "32"); - ts.push("stack-probes", stack_probes); ts.push("vendor", ""); } else if cfg.has("X86") { ts.push("arch", "x86_64"); @@ -281,7 +277,6 @@ fn main() { ts.push("max-atomic-width", 64); ts.push("needs-plt", true); ts.push("pre-link-args", pre_link_args_64); - ts.push("stack-probes", stack_probes); ts.push("target-c-int-width", "32"); ts.push("target-pointer-width", "64"); ts.push("vendor", "unknown"); @@ -296,6 +291,10 @@ fn main() { ts.push("os", if cfg.has("ARM") { "linux" } else { "none" }); ts.push("position-independent-executables", true); ts.push("relocation-model", "static"); + ts.push( + "stack-probes", + vec![("kind".to_string(), Value::String("none".to_string()))], + ); if !cfg.has("ARM") { ts.push("linker-flavor", "gcc"); From f0bee97512d91f70744ed4423221b090b49e43b9 Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Fri, 4 Mar 2022 14:28:07 +0100 Subject: [PATCH 03/36] rust: target: factor out `frame-pointer` and use `may-omit` as default With `rustc`, we can use the `-Cforce-frame-pointers` option to force them to be emitted (so it should work like `always`). However, when the option is set to `n`, what happens depends on the target, thus we cannot control the option completely from the command-line. Therefore, to have as much control as possible from the command-line, we keep the default as `"may-omit"`, which allows us to force it when needed. Also includes a small comment in the `Makefile`. Signed-off-by: Miguel Ojeda --- Makefile | 2 ++ scripts/generate_rust_target.rs | 4 +--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 5612afc5bfa7f6..f5e8ac1a411379 100644 --- a/Makefile +++ b/Makefile @@ -887,6 +887,8 @@ else # select FRAME_POINTER. However, FUNCTION_TRACER adds -pg, and this is # incompatible with -fomit-frame-pointer with current GCC, so we don't use # -fomit-frame-pointer with FUNCTION_TRACER. +# In the Rust target specification, "frame-pointer" is set explicitly +# to "may-omit". ifndef CONFIG_FUNCTION_TRACER KBUILD_CFLAGS += -fomit-frame-pointer endif diff --git a/scripts/generate_rust_target.rs b/scripts/generate_rust_target.rs index e979057d60fdea..84e158ffb70b70 100644 --- a/scripts/generate_rust_target.rs +++ b/scripts/generate_rust_target.rs @@ -210,7 +210,6 @@ fn main() { ); ts.push("disable-redzone", true); ts.push("features", "+strict-align,+neon,+fp-armv8"); - ts.push("frame-pointer", "always"); ts.push("llvm-target", "aarch64-unknown-none"); ts.push("max-atomic-width", 128); ts.push("needs-plt", true); @@ -255,7 +254,6 @@ fn main() { features += ",+c"; } ts.push("features", features); - ts.push("frame-pointer", "always"); ts.push("needs-plt", true); ts.push("target-c-int-width", "32"); ts.push("vendor", ""); @@ -272,7 +270,6 @@ fn main() { "features", "-mmx,-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-3dnow,-3dnowa,-avx,-avx2,+soft-float", ); - ts.push("frame-pointer", "always"); ts.push("llvm-target", "x86_64-elf"); ts.push("max-atomic-width", 64); ts.push("needs-plt", true); @@ -286,6 +283,7 @@ fn main() { ts.push("emit-debug-gdb-scripts", false); ts.push("env", "gnu"); + ts.push("frame-pointer", "may-omit"); ts.push("function-sections", false); ts.push("linker-is-gnu", true); ts.push("os", if cfg.has("ARM") { "linux" } else { "none" }); From 2da9793226fc25e0796696a077f9fbea1fc79675 Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Fri, 4 Mar 2022 14:29:42 +0100 Subject: [PATCH 04/36] rust: target: remove `pre-link-args` Since we are not linking with `rustc`, we should not need these. Signed-off-by: Miguel Ojeda --- scripts/generate_rust_target.rs | 32 -------------------------------- 1 file changed, 32 deletions(-) diff --git a/scripts/generate_rust_target.rs b/scripts/generate_rust_target.rs index 84e158ffb70b70..8996c9ec06f229 100644 --- a/scripts/generate_rust_target.rs +++ b/scripts/generate_rust_target.rs @@ -158,32 +158,6 @@ fn main() { let cfg = KernelConfig::from_stdin(); let mut ts = TargetSpec::new(); - let pre_link_args = vec![( - "gcc".to_string(), - Value::Array(vec![ - Value::String("-Wl,--as-needed".to_string()), - Value::String("-Wl,-z,noexecstack".to_string()), - ]), - )]; - - let pre_link_args_32 = vec![( - "gcc".to_string(), - Value::Array(vec![ - Value::String("-Wl,--as-needed".to_string()), - Value::String("-Wl,-z,noexecstack".to_string()), - Value::String("-m32".to_string()), - ]), - )]; - - let pre_link_args_64 = vec![( - "gcc".to_string(), - Value::Array(vec![ - Value::String("-Wl,--as-needed".to_string()), - Value::String("-Wl,-z,noexecstack".to_string()), - Value::String("-m64".to_string()), - ]), - )]; - if cfg.has("ARM") { ts.push("arch", "arm"); ts.push( @@ -198,7 +172,6 @@ fn main() { ts.push("has-rpath", true); ts.push("llvm-target", "arm-unknown-linux-gnueabi"); ts.push("max-atomic-width", 64); - ts.push("pre-link-args", pre_link_args); ts.push("target-family", "unix"); ts.push("target-mcount", "\\u0001__gnu_mcount_nc"); ts.push("target-pointer-width", "32"); @@ -213,7 +186,6 @@ fn main() { ts.push("llvm-target", "aarch64-unknown-none"); ts.push("max-atomic-width", 128); ts.push("needs-plt", true); - ts.push("pre-link-args", pre_link_args_64); ts.push("target-c-int-width", "32"); ts.push("target-pointer-width", "64"); ts.push("vendor", ""); @@ -225,7 +197,6 @@ fn main() { ts.push("features", "-altivec,-vsx,-hard-float"); ts.push("llvm-target", "powerpc64le-elf"); ts.push("max-atomic-width", 64); - ts.push("pre-link-args", pre_link_args_64); ts.push("target-family", "unix"); ts.push("target-mcount", "_mcount"); ts.push("target-pointer-width", "64"); @@ -236,7 +207,6 @@ fn main() { ts.push("data-layout", "e-m:e-p:64:64-i64:64-i128:128-n64-S128"); ts.push("llvm-target", "riscv64"); ts.push("max-atomic-width", 64); - ts.push("pre-link-args", pre_link_args_64); ts.push("target-pointer-width", "64"); } else { ts.push("arch", "riscv32"); @@ -244,7 +214,6 @@ fn main() { ts.push("data-layout", "e-m:e-p:32:32-i64:64-n32-S128"); ts.push("llvm-target", "riscv32"); ts.push("max-atomic-width", 32); - ts.push("pre-link-args", pre_link_args_32); ts.push("target-pointer-width", "32"); } ts.push("code-model", "medium"); @@ -273,7 +242,6 @@ fn main() { ts.push("llvm-target", "x86_64-elf"); ts.push("max-atomic-width", 64); ts.push("needs-plt", true); - ts.push("pre-link-args", pre_link_args_64); ts.push("target-c-int-width", "32"); ts.push("target-pointer-width", "64"); ts.push("vendor", "unknown"); From a3b8a458ebb6c408dc86999c968c3788ef458061 Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Fri, 11 Mar 2022 19:27:25 +0100 Subject: [PATCH 05/36] scripts: generate_rust_target: `Array` is not needed anymore Signed-off-by: Miguel Ojeda --- scripts/generate_rust_target.rs | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/scripts/generate_rust_target.rs b/scripts/generate_rust_target.rs index 8996c9ec06f229..72568b2c502ee1 100644 --- a/scripts/generate_rust_target.rs +++ b/scripts/generate_rust_target.rs @@ -19,11 +19,9 @@ enum Value { Boolean(bool), Number(i32), String(String), - Array(Array), Object(Object), } -type Array = Vec; type Object = Vec<(String, Value)>; /// Minimal "almost JSON" generator (e.g. no `null`s, no escaping), enough @@ -34,16 +32,6 @@ impl Display for Value { Value::Boolean(boolean) => write!(formatter, "{}", boolean), Value::Number(number) => write!(formatter, "{}", number), Value::String(string) => write!(formatter, "\"{}\"", string), - Value::Array(array) => { - formatter.write_str("[")?; - if let [ref rest @ .., ref last] = array[..] { - for value in rest { - write!(formatter, "{},", value)?; - } - write!(formatter, "{}", last)?; - } - formatter.write_str("]") - } Value::Object(object) => { formatter.write_str("{")?; if let [ref rest @ .., ref last] = object[..] { From 8cb00ab475b3b9b3ac8399d53fb446967e131999 Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Fri, 4 Mar 2022 14:30:25 +0100 Subject: [PATCH 06/36] rust: target: remove `vendor` As far as I can see in the Rust repository, this is not used for anything we care about. It defaults to `unknown`, too, which should be fine. Signed-off-by: Miguel Ojeda --- scripts/generate_rust_target.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/scripts/generate_rust_target.rs b/scripts/generate_rust_target.rs index 72568b2c502ee1..22d4633079c759 100644 --- a/scripts/generate_rust_target.rs +++ b/scripts/generate_rust_target.rs @@ -176,7 +176,6 @@ fn main() { ts.push("needs-plt", true); ts.push("target-c-int-width", "32"); ts.push("target-pointer-width", "64"); - ts.push("vendor", ""); } else if cfg.has("PPC") { ts.push("arch", "powerpc64"); ts.push("code-model", "large"); @@ -213,7 +212,6 @@ fn main() { ts.push("features", features); ts.push("needs-plt", true); ts.push("target-c-int-width", "32"); - ts.push("vendor", ""); } else if cfg.has("X86") { ts.push("arch", "x86_64"); ts.push("code-model", "kernel"); @@ -232,7 +230,6 @@ fn main() { ts.push("needs-plt", true); ts.push("target-c-int-width", "32"); ts.push("target-pointer-width", "64"); - ts.push("vendor", "unknown"); } else { panic!("Unsupported architecture"); } From d9d57445843a6bab69d75893e70614e9f175991d Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Fri, 4 Mar 2022 14:31:16 +0100 Subject: [PATCH 07/36] rust: target: remove `panic-strategy` We are already using the stable flag, which overrides the target. Signed-off-by: Miguel Ojeda --- scripts/generate_rust_target.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/generate_rust_target.rs b/scripts/generate_rust_target.rs index 22d4633079c759..1dd7fdceae3627 100644 --- a/scripts/generate_rust_target.rs +++ b/scripts/generate_rust_target.rs @@ -249,7 +249,6 @@ fn main() { if !cfg.has("ARM") { ts.push("linker-flavor", "gcc"); - ts.push("panic-strategy", "abort"); ts.push("relro-level", "full"); if cfg.has("CPU_BIG_ENDIAN") { From dfd3d6663cc1fb9e77551527ce1a5604847cdaa3 Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Fri, 4 Mar 2022 14:31:35 +0100 Subject: [PATCH 08/36] rust: target: remove `linker-flavor` We are not linking with `rustc`, so we should not need this. And, if we do, we should use the CLI stable flag anyway. Signed-off-by: Miguel Ojeda --- scripts/generate_rust_target.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/generate_rust_target.rs b/scripts/generate_rust_target.rs index 1dd7fdceae3627..f9beaf9a258ed0 100644 --- a/scripts/generate_rust_target.rs +++ b/scripts/generate_rust_target.rs @@ -248,7 +248,6 @@ fn main() { ); if !cfg.has("ARM") { - ts.push("linker-flavor", "gcc"); ts.push("relro-level", "full"); if cfg.has("CPU_BIG_ENDIAN") { From c8c9b5b5fe34dcec82fc3663003d02104ad192b8 Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Fri, 4 Mar 2022 14:32:07 +0100 Subject: [PATCH 09/36] rust: target: remove `os` It defaults to `none`, which is the one we want. Note that some code in `rustc_middle/src/ty/layout.rs` (for `fn` ABI) checks it for `linux`, but not for ARM. Thus nothing should change. Signed-off-by: Miguel Ojeda --- scripts/generate_rust_target.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/generate_rust_target.rs b/scripts/generate_rust_target.rs index f9beaf9a258ed0..87db56f79a588b 100644 --- a/scripts/generate_rust_target.rs +++ b/scripts/generate_rust_target.rs @@ -239,7 +239,6 @@ fn main() { ts.push("frame-pointer", "may-omit"); ts.push("function-sections", false); ts.push("linker-is-gnu", true); - ts.push("os", if cfg.has("ARM") { "linux" } else { "none" }); ts.push("position-independent-executables", true); ts.push("relocation-model", "static"); ts.push( From 3b429a1438930cd1a4f25602f4f1dfe81533b350 Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Fri, 4 Mar 2022 14:35:48 +0100 Subject: [PATCH 10/36] rust: target: move `target-endian` to top-level Note that little endian is the default. Signed-off-by: Miguel Ojeda --- scripts/generate_rust_target.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/scripts/generate_rust_target.rs b/scripts/generate_rust_target.rs index 87db56f79a588b..5bc23ef58da081 100644 --- a/scripts/generate_rust_target.rs +++ b/scripts/generate_rust_target.rs @@ -246,16 +246,14 @@ fn main() { vec![("kind".to_string(), Value::String("none".to_string()))], ); + // Everything else is LE, whether `CPU_LITTLE_ENDIAN` + // is declared or not (e.g. x86). + if cfg.has("CPU_BIG_ENDIAN") { + ts.push("target-endian", "big"); + } + if !cfg.has("ARM") { ts.push("relro-level", "full"); - - if cfg.has("CPU_BIG_ENDIAN") { - ts.push("target-endian", "big"); - } else { - // Everything else is LE, whether `CPU_LITTLE_ENDIAN` - // is declared or not (e.g. x86). - ts.push("target-endian", "little"); - } } println!("{}", ts); From 94ec7f2f4c98dd386091694492d416aed89115bd Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Fri, 4 Mar 2022 14:39:25 +0100 Subject: [PATCH 11/36] rust: target: remove `linker-is-gnu` We are not linking with `rustc`, so we should not need this. In any case, the default is `true`. Signed-off-by: Miguel Ojeda --- scripts/generate_rust_target.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/generate_rust_target.rs b/scripts/generate_rust_target.rs index 5bc23ef58da081..8a258d2cdf00ec 100644 --- a/scripts/generate_rust_target.rs +++ b/scripts/generate_rust_target.rs @@ -238,7 +238,6 @@ fn main() { ts.push("env", "gnu"); ts.push("frame-pointer", "may-omit"); ts.push("function-sections", false); - ts.push("linker-is-gnu", true); ts.push("position-independent-executables", true); ts.push("relocation-model", "static"); ts.push( From bfd91c493d8243dc5788eea3d5bfa9b02ccbb41a Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Fri, 4 Mar 2022 14:46:09 +0100 Subject: [PATCH 12/36] rust: target: remove `executables` We are not producing executables, so we do not need this. It seems only used to set a different default target for iOS anyway. The default is `false`. Signed-off-by: Miguel Ojeda --- scripts/generate_rust_target.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/generate_rust_target.rs b/scripts/generate_rust_target.rs index 8a258d2cdf00ec..4c2b3d2e6d2b3a 100644 --- a/scripts/generate_rust_target.rs +++ b/scripts/generate_rust_target.rs @@ -154,7 +154,6 @@ fn main() { ); ts.push("dynamic-linking", true); ts.push("crt-static-respected", true); - ts.push("executables", true); ts.push("features", "+strict-align,+v6"); ts.push("has-elf-tls", true); ts.push("has-rpath", true); From 7e340602127400af04107abbea127e0381455444 Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Wed, 9 Mar 2022 21:26:34 +0100 Subject: [PATCH 13/36] rust: target: remove `has-rpath` and `rpath=n` We do not need `rpath`, thus remove from target and command-line, where we rely on the default (`n`). Signed-off-by: Miguel Ojeda --- Makefile | 2 +- scripts/generate_rust_target.rs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Makefile b/Makefile index f5e8ac1a411379..57c2eb9d30f6f3 100644 --- a/Makefile +++ b/Makefile @@ -553,7 +553,7 @@ KBUILD_CFLAGS := -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs \ KBUILD_CPPFLAGS := -D__KERNEL__ KBUILD_RUSTFLAGS := $(rust_common_flags) \ --target=$(objtree)/rust/target.json \ - -Cpanic=abort -Cembed-bitcode=n -Clto=n -Crpath=n \ + -Cpanic=abort -Cembed-bitcode=n -Clto=n \ -Cforce-unwind-tables=n -Ccodegen-units=1 \ -Csymbol-mangling-version=v0 \ -Dclippy::float_arithmetic diff --git a/scripts/generate_rust_target.rs b/scripts/generate_rust_target.rs index 4c2b3d2e6d2b3a..3c3bdf5d69b00b 100644 --- a/scripts/generate_rust_target.rs +++ b/scripts/generate_rust_target.rs @@ -156,7 +156,6 @@ fn main() { ts.push("crt-static-respected", true); ts.push("features", "+strict-align,+v6"); ts.push("has-elf-tls", true); - ts.push("has-rpath", true); ts.push("llvm-target", "arm-unknown-linux-gnueabi"); ts.push("max-atomic-width", 64); ts.push("target-family", "unix"); From 2a75bb2f7a431825f20f8713db4e4e721afe3d7d Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Wed, 9 Mar 2022 21:49:50 +0100 Subject: [PATCH 14/36] rust: target: remove `target-family` It is not needed. The default is the empty vector, which is fine. Signed-off-by: Miguel Ojeda --- scripts/generate_rust_target.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/scripts/generate_rust_target.rs b/scripts/generate_rust_target.rs index 3c3bdf5d69b00b..a19006c33934b4 100644 --- a/scripts/generate_rust_target.rs +++ b/scripts/generate_rust_target.rs @@ -158,7 +158,6 @@ fn main() { ts.push("has-elf-tls", true); ts.push("llvm-target", "arm-unknown-linux-gnueabi"); ts.push("max-atomic-width", 64); - ts.push("target-family", "unix"); ts.push("target-mcount", "\\u0001__gnu_mcount_nc"); ts.push("target-pointer-width", "32"); } else if cfg.has("ARM64") { @@ -182,7 +181,6 @@ fn main() { ts.push("features", "-altivec,-vsx,-hard-float"); ts.push("llvm-target", "powerpc64le-elf"); ts.push("max-atomic-width", 64); - ts.push("target-family", "unix"); ts.push("target-mcount", "_mcount"); ts.push("target-pointer-width", "64"); } else if cfg.has("RISCV") { From 16b22183e2c5dd8db9fc73d21da37f6d9f6cfce4 Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Wed, 9 Mar 2022 22:01:26 +0100 Subject: [PATCH 15/36] rust: target: remove `env` It does not look like there is anything in the `rustc` compiler or `core`/`alloc` that requires this being `gnu`. Therefore, just remove it and use its default (empty string: `""`). Signed-off-by: Miguel Ojeda --- scripts/generate_rust_target.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/generate_rust_target.rs b/scripts/generate_rust_target.rs index a19006c33934b4..1c48e4c204f51a 100644 --- a/scripts/generate_rust_target.rs +++ b/scripts/generate_rust_target.rs @@ -231,7 +231,6 @@ fn main() { } ts.push("emit-debug-gdb-scripts", false); - ts.push("env", "gnu"); ts.push("frame-pointer", "may-omit"); ts.push("function-sections", false); ts.push("position-independent-executables", true); From 5ed068421137c20fec9ff0e76931da4b0f70e162 Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Thu, 10 Mar 2022 14:40:22 +0100 Subject: [PATCH 16/36] rust: target: move x86 redzone option to command-line Signed-off-by: Miguel Ojeda --- arch/x86/Makefile | 1 + scripts/generate_rust_target.rs | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/Makefile b/arch/x86/Makefile index e84cdd409b6462..cad7aa2fe590c2 100644 --- a/arch/x86/Makefile +++ b/arch/x86/Makefile @@ -138,6 +138,7 @@ else KBUILD_CFLAGS += -mno-red-zone KBUILD_CFLAGS += -mcmodel=kernel + KBUILD_RUSTFLAGS += -Cno-redzone=y endif ifdef CONFIG_X86_X32 diff --git a/scripts/generate_rust_target.rs b/scripts/generate_rust_target.rs index 1c48e4c204f51a..7e58ccde85db85 100644 --- a/scripts/generate_rust_target.rs +++ b/scripts/generate_rust_target.rs @@ -216,7 +216,6 @@ fn main() { "data-layout", "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128", ); - ts.push("disable-redzone", true); ts.push( "features", "-mmx,-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-3dnow,-3dnowa,-avx,-avx2,+soft-float", From af47d53e32185c37375a5415e9443737427b7045 Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Thu, 10 Mar 2022 14:40:56 +0100 Subject: [PATCH 17/36] rust: target: move x86 code model option to command-line Signed-off-by: Miguel Ojeda --- arch/x86/Makefile | 1 + scripts/generate_rust_target.rs | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/Makefile b/arch/x86/Makefile index cad7aa2fe590c2..a8327975379b3b 100644 --- a/arch/x86/Makefile +++ b/arch/x86/Makefile @@ -139,6 +139,7 @@ else KBUILD_CFLAGS += -mno-red-zone KBUILD_CFLAGS += -mcmodel=kernel KBUILD_RUSTFLAGS += -Cno-redzone=y + KBUILD_RUSTFLAGS += -Ccode-model=kernel endif ifdef CONFIG_X86_X32 diff --git a/scripts/generate_rust_target.rs b/scripts/generate_rust_target.rs index 7e58ccde85db85..f8c1cb43836dfe 100644 --- a/scripts/generate_rust_target.rs +++ b/scripts/generate_rust_target.rs @@ -210,7 +210,6 @@ fn main() { ts.push("target-c-int-width", "32"); } else if cfg.has("X86") { ts.push("arch", "x86_64"); - ts.push("code-model", "kernel"); ts.push("cpu", "x86-64"); ts.push( "data-layout", From 2d2e1fd7a1bf3ab9cca9890788922536bb1d0278 Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Thu, 10 Mar 2022 22:47:13 +0100 Subject: [PATCH 18/36] rust: target: move x86 features to command-line Signed-off-by: Miguel Ojeda --- arch/x86/Makefile | 2 ++ scripts/generate_rust_target.rs | 4 ---- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/arch/x86/Makefile b/arch/x86/Makefile index a8327975379b3b..4bb4d55a6db037 100644 --- a/arch/x86/Makefile +++ b/arch/x86/Makefile @@ -61,6 +61,8 @@ export BITS # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53383 # KBUILD_CFLAGS += -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx +KBUILD_RUSTFLAGS += -Ctarget-feature=-mmx,-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2 +KBUILD_RUSTFLAGS += -Ctarget-feature=-3dnow,-3dnowa,-avx,-avx2,+soft-float # Intel CET isn't enabled in the kernel KBUILD_CFLAGS += $(call cc-option,-fcf-protection=none) diff --git a/scripts/generate_rust_target.rs b/scripts/generate_rust_target.rs index f8c1cb43836dfe..3636872621be50 100644 --- a/scripts/generate_rust_target.rs +++ b/scripts/generate_rust_target.rs @@ -215,10 +215,6 @@ fn main() { "data-layout", "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128", ); - ts.push( - "features", - "-mmx,-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-3dnow,-3dnowa,-avx,-avx2,+soft-float", - ); ts.push("llvm-target", "x86_64-elf"); ts.push("max-atomic-width", 64); ts.push("needs-plt", true); From acc574f8334ac8b87b728d103dd6b75e95096fdd Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Thu, 10 Mar 2022 22:49:09 +0100 Subject: [PATCH 19/36] rust: target: enable `retpoline-external-thunk` for x86 Signed-off-by: Miguel Ojeda --- arch/x86/Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/x86/Makefile b/arch/x86/Makefile index 4bb4d55a6db037..51c50343e46e84 100644 --- a/arch/x86/Makefile +++ b/arch/x86/Makefile @@ -21,6 +21,8 @@ ifdef CONFIG_CC_IS_CLANG RETPOLINE_CFLAGS := -mretpoline-external-thunk RETPOLINE_VDSO_CFLAGS := -mretpoline endif +RETPOLINE_RUSTFLAGS := -Ctarget-feature=+retpoline-external-thunk + export RETPOLINE_CFLAGS export RETPOLINE_VDSO_CFLAGS @@ -193,6 +195,7 @@ ifdef CONFIG_RETPOLINE ifndef CONFIG_CC_IS_CLANG KBUILD_CFLAGS += -fno-jump-tables endif + KBUILD_RUSTFLAGS += $(RETPOLINE_RUSTFLAGS) endif ifdef CONFIG_SLS From 883b79d78b25d3fb9c57a47a89b90a67885cf9e2 Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Wed, 9 Mar 2022 22:50:39 +0100 Subject: [PATCH 20/36] rust: target: move `relocation-model` to command-line flag Architectures may still override it. Signed-off-by: Miguel Ojeda --- Makefile | 1 + scripts/generate_rust_target.rs | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 57c2eb9d30f6f3..fb0aa77a3e9925 100644 --- a/Makefile +++ b/Makefile @@ -556,6 +556,7 @@ KBUILD_RUSTFLAGS := $(rust_common_flags) \ -Cpanic=abort -Cembed-bitcode=n -Clto=n \ -Cforce-unwind-tables=n -Ccodegen-units=1 \ -Csymbol-mangling-version=v0 \ + -Crelocation-model=static \ -Dclippy::float_arithmetic KBUILD_AFLAGS_KERNEL := diff --git a/scripts/generate_rust_target.rs b/scripts/generate_rust_target.rs index 3636872621be50..5043e4900986ce 100644 --- a/scripts/generate_rust_target.rs +++ b/scripts/generate_rust_target.rs @@ -228,7 +228,6 @@ fn main() { ts.push("frame-pointer", "may-omit"); ts.push("function-sections", false); ts.push("position-independent-executables", true); - ts.push("relocation-model", "static"); ts.push( "stack-probes", vec![("kind".to_string(), Value::String("none".to_string()))], From 7923d84d0ae92e5a23c06bf4b97be4cb426ed032 Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Fri, 11 Mar 2022 01:26:13 +0100 Subject: [PATCH 21/36] rust: target: remove `position-independent-executables` It is only used for linking to adjust the output kind, not for compilation. The default is `false`. Signed-off-by: Miguel Ojeda --- scripts/generate_rust_target.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/generate_rust_target.rs b/scripts/generate_rust_target.rs index 5043e4900986ce..4691c6b12810dd 100644 --- a/scripts/generate_rust_target.rs +++ b/scripts/generate_rust_target.rs @@ -227,7 +227,6 @@ fn main() { ts.push("emit-debug-gdb-scripts", false); ts.push("frame-pointer", "may-omit"); ts.push("function-sections", false); - ts.push("position-independent-executables", true); ts.push( "stack-probes", vec![("kind".to_string(), Value::String("none".to_string()))], From 4675d065893e12540f2b5bacb6e1d48802f79eb7 Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Sun, 13 Mar 2022 00:47:58 +0100 Subject: [PATCH 22/36] rust: target: remove `relro-level` Architectures may use `-Zrelro-level` to set the right value. Signed-off-by: Miguel Ojeda --- scripts/generate_rust_target.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/scripts/generate_rust_target.rs b/scripts/generate_rust_target.rs index 4691c6b12810dd..309eda79a6a335 100644 --- a/scripts/generate_rust_target.rs +++ b/scripts/generate_rust_target.rs @@ -238,9 +238,5 @@ fn main() { ts.push("target-endian", "big"); } - if !cfg.has("ARM") { - ts.push("relro-level", "full"); - } - println!("{}", ts); } From f028dee2d37e3f6913f402485b481c821fe5073b Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Sun, 13 Mar 2022 00:48:08 +0100 Subject: [PATCH 23/36] rust: target: remove `needs-plt` Architectures can use `-Zplt` to set the right value. Signed-off-by: Miguel Ojeda --- scripts/generate_rust_target.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/scripts/generate_rust_target.rs b/scripts/generate_rust_target.rs index 309eda79a6a335..966b58fe6958ae 100644 --- a/scripts/generate_rust_target.rs +++ b/scripts/generate_rust_target.rs @@ -170,7 +170,6 @@ fn main() { ts.push("features", "+strict-align,+neon,+fp-armv8"); ts.push("llvm-target", "aarch64-unknown-none"); ts.push("max-atomic-width", 128); - ts.push("needs-plt", true); ts.push("target-c-int-width", "32"); ts.push("target-pointer-width", "64"); } else if cfg.has("PPC") { @@ -206,7 +205,6 @@ fn main() { features += ",+c"; } ts.push("features", features); - ts.push("needs-plt", true); ts.push("target-c-int-width", "32"); } else if cfg.has("X86") { ts.push("arch", "x86_64"); @@ -217,7 +215,6 @@ fn main() { ); ts.push("llvm-target", "x86_64-elf"); ts.push("max-atomic-width", 64); - ts.push("needs-plt", true); ts.push("target-c-int-width", "32"); ts.push("target-pointer-width", "64"); } else { From 9b8a2126092a87c459811526d270590be3de4358 Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Sun, 13 Mar 2022 01:03:21 +0100 Subject: [PATCH 24/36] rust: target: remove `target-c-int-width` The default value is `"32"`. Signed-off-by: Miguel Ojeda --- scripts/generate_rust_target.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/scripts/generate_rust_target.rs b/scripts/generate_rust_target.rs index 966b58fe6958ae..a507a8f21c40bb 100644 --- a/scripts/generate_rust_target.rs +++ b/scripts/generate_rust_target.rs @@ -170,7 +170,6 @@ fn main() { ts.push("features", "+strict-align,+neon,+fp-armv8"); ts.push("llvm-target", "aarch64-unknown-none"); ts.push("max-atomic-width", 128); - ts.push("target-c-int-width", "32"); ts.push("target-pointer-width", "64"); } else if cfg.has("PPC") { ts.push("arch", "powerpc64"); @@ -205,7 +204,6 @@ fn main() { features += ",+c"; } ts.push("features", features); - ts.push("target-c-int-width", "32"); } else if cfg.has("X86") { ts.push("arch", "x86_64"); ts.push("cpu", "x86-64"); @@ -215,7 +213,6 @@ fn main() { ); ts.push("llvm-target", "x86_64-elf"); ts.push("max-atomic-width", 64); - ts.push("target-c-int-width", "32"); ts.push("target-pointer-width", "64"); } else { panic!("Unsupported architecture"); From bd32a109e10464542f8d147424e137205ddb448d Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Sun, 13 Mar 2022 01:05:07 +0100 Subject: [PATCH 25/36] rust: target: remove `max-atomic-width` where possible The default value is that of `target-pointer-width`, thus remove the cases where it is the same. Signed-off-by: Miguel Ojeda --- scripts/generate_rust_target.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/scripts/generate_rust_target.rs b/scripts/generate_rust_target.rs index a507a8f21c40bb..5ca169ad8ba8e2 100644 --- a/scripts/generate_rust_target.rs +++ b/scripts/generate_rust_target.rs @@ -187,14 +187,12 @@ fn main() { ts.push("cpu", "generic-rv64"); ts.push("data-layout", "e-m:e-p:64:64-i64:64-i128:128-n64-S128"); ts.push("llvm-target", "riscv64"); - ts.push("max-atomic-width", 64); ts.push("target-pointer-width", "64"); } else { ts.push("arch", "riscv32"); ts.push("cpu", "generic-rv32"); ts.push("data-layout", "e-m:e-p:32:32-i64:64-n32-S128"); ts.push("llvm-target", "riscv32"); - ts.push("max-atomic-width", 32); ts.push("target-pointer-width", "32"); } ts.push("code-model", "medium"); @@ -212,7 +210,6 @@ fn main() { "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128", ); ts.push("llvm-target", "x86_64-elf"); - ts.push("max-atomic-width", 64); ts.push("target-pointer-width", "64"); } else { panic!("Unsupported architecture"); From 02e1ab19da8f46d47c0517a87a4faa3447548b06 Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Sun, 13 Mar 2022 02:05:22 +0100 Subject: [PATCH 26/36] rust: target: use same target triple as `Makefile.clang` This allows us to be consistent. The triples are not normalized according to LLVM (e.g. vendor does not appear in the second position). Signed-off-by: Miguel Ojeda --- scripts/generate_rust_target.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/generate_rust_target.rs b/scripts/generate_rust_target.rs index 5ca169ad8ba8e2..a215f9fe22c790 100644 --- a/scripts/generate_rust_target.rs +++ b/scripts/generate_rust_target.rs @@ -156,7 +156,7 @@ fn main() { ts.push("crt-static-respected", true); ts.push("features", "+strict-align,+v6"); ts.push("has-elf-tls", true); - ts.push("llvm-target", "arm-unknown-linux-gnueabi"); + ts.push("llvm-target", "arm-linux-gnueabi"); ts.push("max-atomic-width", 64); ts.push("target-mcount", "\\u0001__gnu_mcount_nc"); ts.push("target-pointer-width", "32"); @@ -168,7 +168,7 @@ fn main() { ); ts.push("disable-redzone", true); ts.push("features", "+strict-align,+neon,+fp-armv8"); - ts.push("llvm-target", "aarch64-unknown-none"); + ts.push("llvm-target", "aarch64-linux-gnu"); ts.push("max-atomic-width", 128); ts.push("target-pointer-width", "64"); } else if cfg.has("PPC") { @@ -177,7 +177,7 @@ fn main() { ts.push("cpu", "ppc64le"); ts.push("data-layout", "e-m:e-i64:64-n32:64"); ts.push("features", "-altivec,-vsx,-hard-float"); - ts.push("llvm-target", "powerpc64le-elf"); + ts.push("llvm-target", "powerpc64le-linux-gnu"); ts.push("max-atomic-width", 64); ts.push("target-mcount", "_mcount"); ts.push("target-pointer-width", "64"); @@ -186,13 +186,13 @@ fn main() { ts.push("arch", "riscv64"); ts.push("cpu", "generic-rv64"); ts.push("data-layout", "e-m:e-p:64:64-i64:64-i128:128-n64-S128"); - ts.push("llvm-target", "riscv64"); + ts.push("llvm-target", "riscv64-linux-gnu"); ts.push("target-pointer-width", "64"); } else { ts.push("arch", "riscv32"); ts.push("cpu", "generic-rv32"); ts.push("data-layout", "e-m:e-p:32:32-i64:64-n32-S128"); - ts.push("llvm-target", "riscv32"); + ts.push("llvm-target", "riscv32-linux-gnu"); ts.push("target-pointer-width", "32"); } ts.push("code-model", "medium"); @@ -209,7 +209,7 @@ fn main() { "data-layout", "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128", ); - ts.push("llvm-target", "x86_64-elf"); + ts.push("llvm-target", "x86_64-linux-gnu"); ts.push("target-pointer-width", "64"); } else { panic!("Unsupported architecture"); From 07809b0ef431c5813ee1c6682f23e5df06cef63d Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Sun, 13 Mar 2022 02:11:57 +0100 Subject: [PATCH 27/36] rust: target: remove `has-elf-tls` By the way, it was renamed recently to `has-thread-local`. Signed-off-by: Miguel Ojeda --- scripts/generate_rust_target.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/generate_rust_target.rs b/scripts/generate_rust_target.rs index a215f9fe22c790..e3517dfaa4ae74 100644 --- a/scripts/generate_rust_target.rs +++ b/scripts/generate_rust_target.rs @@ -155,7 +155,6 @@ fn main() { ts.push("dynamic-linking", true); ts.push("crt-static-respected", true); ts.push("features", "+strict-align,+v6"); - ts.push("has-elf-tls", true); ts.push("llvm-target", "arm-linux-gnueabi"); ts.push("max-atomic-width", 64); ts.push("target-mcount", "\\u0001__gnu_mcount_nc"); From 732b3c386328a4c741897d0b95e40801ad20a60d Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Sun, 13 Mar 2022 02:25:54 +0100 Subject: [PATCH 28/36] rust: target: remove `cpu` Architectures may use `-Ctarget-cpu=` to set the right value. The default is `generic`, but LLVM does not support it for RISC-V, thus we need to override it in the `Makefile`. Signed-off-by: Miguel Ojeda --- arch/riscv/Makefile | 5 +++++ scripts/generate_rust_target.rs | 4 ---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile index 7d81102cffd48e..663ae53b55973a 100644 --- a/arch/riscv/Makefile +++ b/arch/riscv/Makefile @@ -26,6 +26,8 @@ ifeq ($(CONFIG_ARCH_RV64I),y) KBUILD_CFLAGS += -mabi=lp64 KBUILD_AFLAGS += -mabi=lp64 + KBUILD_RUSTFLAGS += -Ctarget-cpu=generic-rv64 + KBUILD_LDFLAGS += -melf64lriscv else BITS := 32 @@ -33,6 +35,9 @@ else KBUILD_CFLAGS += -mabi=ilp32 KBUILD_AFLAGS += -mabi=ilp32 + + KBUILD_RUSTFLAGS += -Ctarget-cpu=generic-rv32 + KBUILD_LDFLAGS += -melf32lriscv endif diff --git a/scripts/generate_rust_target.rs b/scripts/generate_rust_target.rs index e3517dfaa4ae74..5aa6681e53967a 100644 --- a/scripts/generate_rust_target.rs +++ b/scripts/generate_rust_target.rs @@ -173,7 +173,6 @@ fn main() { } else if cfg.has("PPC") { ts.push("arch", "powerpc64"); ts.push("code-model", "large"); - ts.push("cpu", "ppc64le"); ts.push("data-layout", "e-m:e-i64:64-n32:64"); ts.push("features", "-altivec,-vsx,-hard-float"); ts.push("llvm-target", "powerpc64le-linux-gnu"); @@ -183,13 +182,11 @@ fn main() { } else if cfg.has("RISCV") { if cfg.has("64BIT") { ts.push("arch", "riscv64"); - ts.push("cpu", "generic-rv64"); ts.push("data-layout", "e-m:e-p:64:64-i64:64-i128:128-n64-S128"); ts.push("llvm-target", "riscv64-linux-gnu"); ts.push("target-pointer-width", "64"); } else { ts.push("arch", "riscv32"); - ts.push("cpu", "generic-rv32"); ts.push("data-layout", "e-m:e-p:32:32-i64:64-n32-S128"); ts.push("llvm-target", "riscv32-linux-gnu"); ts.push("target-pointer-width", "32"); @@ -203,7 +200,6 @@ fn main() { ts.push("features", features); } else if cfg.has("X86") { ts.push("arch", "x86_64"); - ts.push("cpu", "x86-64"); ts.push( "data-layout", "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128", From 89234c468610b81efdc6292f92ee7c7c31f884a3 Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Sun, 13 Mar 2022 02:42:46 +0100 Subject: [PATCH 29/36] rust: target: x86: use `-Ctarget-cpu` and `-Ztune-cpu` Signed-off-by: Miguel Ojeda --- arch/x86/Makefile | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/x86/Makefile b/arch/x86/Makefile index 51c50343e46e84..5bfd4c83373248 100644 --- a/arch/x86/Makefile +++ b/arch/x86/Makefile @@ -140,6 +140,13 @@ else cflags-$(CONFIG_GENERIC_CPU) += -mtune=generic KBUILD_CFLAGS += $(cflags-y) + rustflags-$(CONFIG_MK8) += -Ctarget-cpu=k8 + rustflags-$(CONFIG_MPSC) += -Ctarget-cpu=nocona + rustflags-$(CONFIG_MCORE2) += -Ctarget-cpu=core2 + rustflags-$(CONFIG_MATOM) += -Ctarget-cpu=atom + rustflags-$(CONFIG_GENERIC_CPU) += -Ztune-cpu=generic + KBUILD_RUSTFLAGS += $(rustflags-y) + KBUILD_CFLAGS += -mno-red-zone KBUILD_CFLAGS += -mcmodel=kernel KBUILD_RUSTFLAGS += -Cno-redzone=y From d05b11f4fb895c22727aa30dd7e8e7af2cc252f9 Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Sun, 13 Mar 2022 02:45:26 +0100 Subject: [PATCH 30/36] rust: target: make output slightly more pretty Signed-off-by: Miguel Ojeda --- scripts/generate_rust_target.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/generate_rust_target.rs b/scripts/generate_rust_target.rs index 5aa6681e53967a..52bdda51c1c336 100644 --- a/scripts/generate_rust_target.rs +++ b/scripts/generate_rust_target.rs @@ -36,9 +36,9 @@ impl Display for Value { formatter.write_str("{")?; if let [ref rest @ .., ref last] = object[..] { for (key, value) in rest { - write!(formatter, "\"{}\":{},", key, value)?; + write!(formatter, "\"{}\": {},", key, value)?; } - write!(formatter, "\"{}\":{}", last.0, last.1)?; + write!(formatter, "\"{}\": {}", last.0, last.1)?; } formatter.write_str("}") } @@ -94,9 +94,9 @@ impl Display for TargetSpec { formatter.write_str("{\n")?; if let [ref rest @ .., ref last] = self.0[..] { for (key, value) in rest { - write!(formatter, "\"{}\":{},\n", key, value)?; + write!(formatter, " \"{}\": {},\n", key, value)?; } - write!(formatter, "\"{}\":{}\n", last.0, last.1)?; + write!(formatter, " \"{}\": {}\n", last.0, last.1)?; } formatter.write_str("}") } From abd417194758a6162ad3355937247ee53d85d2ca Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Sun, 13 Mar 2022 02:57:27 +0100 Subject: [PATCH 31/36] rust: target: move `function-sections` to command-line Note that `function-sections`'s default is `true`, thus we need to specify it. Signed-off-by: Miguel Ojeda --- Makefile | 1 + scripts/generate_rust_target.rs | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index fb0aa77a3e9925..d28c29dba9a2dd 100644 --- a/Makefile +++ b/Makefile @@ -557,6 +557,7 @@ KBUILD_RUSTFLAGS := $(rust_common_flags) \ -Cforce-unwind-tables=n -Ccodegen-units=1 \ -Csymbol-mangling-version=v0 \ -Crelocation-model=static \ + -Zfunction-sections=n \ -Dclippy::float_arithmetic KBUILD_AFLAGS_KERNEL := diff --git a/scripts/generate_rust_target.rs b/scripts/generate_rust_target.rs index 52bdda51c1c336..7c2daf1d894ef7 100644 --- a/scripts/generate_rust_target.rs +++ b/scripts/generate_rust_target.rs @@ -212,7 +212,6 @@ fn main() { ts.push("emit-debug-gdb-scripts", false); ts.push("frame-pointer", "may-omit"); - ts.push("function-sections", false); ts.push( "stack-probes", vec![("kind".to_string(), Value::String("none".to_string()))], From 423fdcac4f43e5e2f4b098273f9c12ac6648b2e6 Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Sun, 13 Mar 2022 03:02:05 +0100 Subject: [PATCH 32/36] Makefile: add `-Zfunction-sections` when supported Signed-off-by: Miguel Ojeda --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index d28c29dba9a2dd..de8b1d94e35ac0 100644 --- a/Makefile +++ b/Makefile @@ -955,8 +955,10 @@ ifdef CONFIG_DEBUG_SECTION_MISMATCH KBUILD_CFLAGS += -fno-inline-functions-called-once endif +# `rustc`'s `-Zfunction-sections` applies to data too (as of 1.59.0). ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION KBUILD_CFLAGS_KERNEL += -ffunction-sections -fdata-sections +KBUILD_RUSTFLAGS_KERNEL += -Zfunction-sections=y LDFLAGS_vmlinux += --gc-sections endif From ea19cabecebe46391138a9bda4678306b89dfcab Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Sun, 13 Mar 2022 03:19:28 +0100 Subject: [PATCH 33/36] rust: target: remove `dynamic-linking` We do not use `dylib`s, `cdylib`s nor cross-compiled proc macros. Signed-off-by: Miguel Ojeda --- scripts/generate_rust_target.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/generate_rust_target.rs b/scripts/generate_rust_target.rs index 7c2daf1d894ef7..dd4d1282c162a9 100644 --- a/scripts/generate_rust_target.rs +++ b/scripts/generate_rust_target.rs @@ -152,7 +152,6 @@ fn main() { "data-layout", "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64", ); - ts.push("dynamic-linking", true); ts.push("crt-static-respected", true); ts.push("features", "+strict-align,+v6"); ts.push("llvm-target", "arm-linux-gnueabi"); From a2942c455dc022c0870ff200033d709de7a90761 Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Sun, 13 Mar 2022 03:31:21 +0100 Subject: [PATCH 34/36] rust: target: remove `crt-static-respected` We do not deal with `libc`. Signed-off-by: Miguel Ojeda --- scripts/generate_rust_target.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/generate_rust_target.rs b/scripts/generate_rust_target.rs index dd4d1282c162a9..f385c1bbaa8797 100644 --- a/scripts/generate_rust_target.rs +++ b/scripts/generate_rust_target.rs @@ -152,7 +152,6 @@ fn main() { "data-layout", "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64", ); - ts.push("crt-static-respected", true); ts.push("features", "+strict-align,+v6"); ts.push("llvm-target", "arm-linux-gnueabi"); ts.push("max-atomic-width", 64); From d127d773650b4139175effe4e95a9c62d6ced536 Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Sun, 13 Mar 2022 20:55:18 +0100 Subject: [PATCH 35/36] rust: target: arm64: disable `neon` and `fp-armv8` The kernel is compiled with `-mgeneral-regs-only`, thus these should not be enabled. Signed-off-by: Miguel Ojeda --- scripts/generate_rust_target.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/generate_rust_target.rs b/scripts/generate_rust_target.rs index f385c1bbaa8797..413a9b6706ee92 100644 --- a/scripts/generate_rust_target.rs +++ b/scripts/generate_rust_target.rs @@ -164,7 +164,7 @@ fn main() { "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128", ); ts.push("disable-redzone", true); - ts.push("features", "+strict-align,+neon,+fp-armv8"); + ts.push("features", "+strict-align,-neon,-fp-armv8"); ts.push("llvm-target", "aarch64-linux-gnu"); ts.push("max-atomic-width", 128); ts.push("target-pointer-width", "64"); From 257d449085eecb038df3da515e79923ef66a9376 Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Sun, 13 Mar 2022 03:33:16 +0100 Subject: [PATCH 36/36] rust: target: improve a few comments Signed-off-by: Miguel Ojeda --- scripts/generate_rust_target.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/scripts/generate_rust_target.rs b/scripts/generate_rust_target.rs index 413a9b6706ee92..d823d51dc60d39 100644 --- a/scripts/generate_rust_target.rs +++ b/scripts/generate_rust_target.rs @@ -5,7 +5,8 @@ //! To configure a target from scratch, a JSON-encoded file has to be passed //! to `rustc` (introduced in [RFC 131]). These options and the file itself are //! unstable. Eventually, `rustc` should provide a way to do this in a stable -//! manner. For instance, via command-line arguments. +//! manner. For instance, via command-line arguments. Therefore, this file +//! should avoid using keys which can be set via `-C` or `-Z` options. //! //! [RFC 131]: https://rust-lang.github.io/rfcs/0131-target-specification.html @@ -24,8 +25,8 @@ enum Value { type Object = Vec<(String, Value)>; -/// Minimal "almost JSON" generator (e.g. no `null`s, no escaping), enough -/// for this purpose. +/// Minimal "almost JSON" generator (e.g. no `null`s, no arrays, no escaping), +/// enough for this purpose. impl Display for Value { fn fmt(&self, formatter: &mut Formatter<'_>) -> Result { match self { @@ -135,7 +136,7 @@ impl KernelConfig { /// /// The argument must be passed without the `CONFIG_` prefix. /// This avoids repetition and it also avoids `fixdep` making us - /// depending on it. + /// depend on it. fn has(&self, option: &str) -> bool { let option = "CONFIG_".to_owned() + option; self.0.contains_key(&option) @@ -215,8 +216,8 @@ fn main() { vec![("kind".to_string(), Value::String("none".to_string()))], ); - // Everything else is LE, whether `CPU_LITTLE_ENDIAN` - // is declared or not (e.g. x86). + // Everything else is LE, whether `CPU_LITTLE_ENDIAN` is declared or not + // (e.g. x86). It is also `rustc`'s default. if cfg.has("CPU_BIG_ENDIAN") { ts.push("target-endian", "big"); }