From 3373ca62f155d4f65a7b78f916e41842813f2699 Mon Sep 17 00:00:00 2001 From: adamrk Date: Wed, 20 Jan 2021 09:29:20 +0100 Subject: [PATCH 1/4] export compiler_builtins symbols --- rust/Makefile | 5 +++++ rust/exports.c | 1 + 2 files changed, 6 insertions(+) diff --git a/rust/Makefile b/rust/Makefile index f6437ae5571144..268a5e27f51aa3 100644 --- a/rust/Makefile +++ b/rust/Makefile @@ -5,6 +5,7 @@ obj-$(CONFIG_RUST) += core.o compiler_builtins.o alloc.o kernel.o extra-$(CONFIG_RUST) += bindings_generated.rs libmodule.so extra-$(CONFIG_RUST) += exports_core_generated.h exports_alloc_generated.h extra-$(CONFIG_RUST) += exports_kernel_generated.h +extra-$(CONFIG_RUST) += exports_compiler_builtins_generated.h ifdef CONFIG_CC_IS_CLANG bindgen_c_flags = $(c_flags) @@ -62,6 +63,10 @@ $(objtree)/rust/exports_kernel_generated.h: exports_target_type := _RUST_GPL $(objtree)/rust/exports_kernel_generated.h: $(objtree)/rust/kernel.o FORCE $(call if_changed,exports) +$(objtree)/rust/exports_compiler_builtins_generated.h: exports_target_type := _RUST +$(objtree)/rust/exports_compiler_builtins_generated.h: $(objtree)/rust/compiler_builtins.o FORCE + $(call if_changed,exports) + quiet_cmd_rustc_procmacro = RUSTC P $@ cmd_rustc_procmacro = \ $(RUSTC) $(rustc_flags) --edition 2018 --extern proc_macro \ diff --git a/rust/exports.c b/rust/exports.c index 900dc3090dd617..ebb59ccc3d4ed7 100644 --- a/rust/exports.c +++ b/rust/exports.c @@ -16,3 +16,4 @@ #include "exports_core_generated.h" #include "exports_alloc_generated.h" #include "exports_kernel_generated.h" +#include "exports_compiler_builtins_generated.h" From 2485c2429eb544ea4863eb18253b63c9a926b65c Mon Sep 17 00:00:00 2001 From: adamrk Date: Tue, 19 Jan 2021 22:34:01 +0100 Subject: [PATCH 2/4] trigger __rust_probestack in example 3 --- drivers/char/rust_example_3.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/char/rust_example_3.rs b/drivers/char/rust_example_3.rs index c6b867e527e9a9..064e13fed890b0 100644 --- a/drivers/char/rust_example_3.rs +++ b/drivers/char/rust_example_3.rs @@ -36,6 +36,14 @@ impl KernelModule for RustExample3 { println!("[3] Parameters:"); println!("[3] my_bool: {}", my_bool.read()); println!("[3] my_i32: {}", my_i32.read()); + + // Including this large variable on the stack will trigger a call to + // `compiler_builtins::probestack::__rust_probestack` on x86_64. + // This will verify that we are able to link modules which call + // `__rust_probestack`. + let x: [u64; 1028] = [5; 1028]; + println!("Large array has length: {}", x.len()); + Ok(RustExample3 { message: "on the heap!".to_owned(), }) From ccbf76b614e8114cc95679a6dbc37f6177665e34 Mon Sep 17 00:00:00 2001 From: adamrk Date: Wed, 20 Jan 2021 21:06:07 +0100 Subject: [PATCH 3/4] include large stack test in all examples --- drivers/char/rust_example.rs | 7 +++++++ drivers/char/rust_example_2.rs | 8 ++++++++ drivers/char/rust_example_3.rs | 2 +- drivers/char/rust_example_4.rs | 8 ++++++++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/drivers/char/rust_example.rs b/drivers/char/rust_example.rs index 47c4a7f722ef80..4b107ec332b136 100644 --- a/drivers/char/rust_example.rs +++ b/drivers/char/rust_example.rs @@ -52,6 +52,13 @@ impl KernelModule for RustExample { println!(" my_bool: {}", my_bool.read()); println!(" my_i32: {}", my_i32.read()); + // Including this large variable on the stack will trigger a call to + // `compiler_builtins::probestack::__rust_probestack` on x86_64. + // This will verify that we are able to link modules which call + // `__rust_probestack`. + let x: [u64; 1028] = [5; 1028]; + println!("Large array has length: {}", x.len()); + Ok(RustExample { message: "on the heap!".to_owned(), _dev: miscdev::Registration::new_pinned::(cstr!("rust_miscdev"), None)?, diff --git a/drivers/char/rust_example_2.rs b/drivers/char/rust_example_2.rs index b5ffb92870d191..cf80dadbf5505d 100644 --- a/drivers/char/rust_example_2.rs +++ b/drivers/char/rust_example_2.rs @@ -36,6 +36,14 @@ impl KernelModule for RustExample2 { println!("[2] Parameters:"); println!("[2] my_bool: {}", my_bool.read()); println!("[2] my_i32: {}", my_i32.read()); + + // Including this large variable on the stack will trigger a call to + // `compiler_builtins::probestack::__rust_probestack` on x86_64. + // This will verify that we are able to link modules which call + // `__rust_probestack`. + let x: [u64; 1028] = [5; 1028]; + println!("Large array has length: {}", x.len()); + Ok(RustExample2 { message: "on the heap!".to_owned(), }) diff --git a/drivers/char/rust_example_3.rs b/drivers/char/rust_example_3.rs index 064e13fed890b0..50542da3da02f5 100644 --- a/drivers/char/rust_example_3.rs +++ b/drivers/char/rust_example_3.rs @@ -37,7 +37,7 @@ impl KernelModule for RustExample3 { println!("[3] my_bool: {}", my_bool.read()); println!("[3] my_i32: {}", my_i32.read()); - // Including this large variable on the stack will trigger a call to + // Including this large variable on the stack will trigger a call to // `compiler_builtins::probestack::__rust_probestack` on x86_64. // This will verify that we are able to link modules which call // `__rust_probestack`. diff --git a/drivers/char/rust_example_4.rs b/drivers/char/rust_example_4.rs index b658c55b4ba80b..73c56b2bf43113 100644 --- a/drivers/char/rust_example_4.rs +++ b/drivers/char/rust_example_4.rs @@ -36,6 +36,14 @@ impl KernelModule for RustExample4 { println!("[4] Parameters:"); println!("[4] my_bool: {}", my_bool.read()); println!("[4] my_i32: {}", my_i32.read()); + + // Including this large variable on the stack will trigger a call to + // `compiler_builtins::probestack::__rust_probestack` on x86_64. + // This will verify that we are able to link modules which call + // `__rust_probestack`. + let x: [u64; 1028] = [5; 1028]; + println!("Large array has length: {}", x.len()); + Ok(RustExample4 { message: "on the heap!".to_owned(), }) From 16c271c208380dfd03a6495c8d7b864be90f5595 Mon Sep 17 00:00:00 2001 From: adamrk Date: Wed, 20 Jan 2021 21:07:34 +0100 Subject: [PATCH 4/4] revert generating compiler_builtins --- rust/Makefile | 5 ----- rust/exports.c | 1 - 2 files changed, 6 deletions(-) diff --git a/rust/Makefile b/rust/Makefile index 268a5e27f51aa3..f6437ae5571144 100644 --- a/rust/Makefile +++ b/rust/Makefile @@ -5,7 +5,6 @@ obj-$(CONFIG_RUST) += core.o compiler_builtins.o alloc.o kernel.o extra-$(CONFIG_RUST) += bindings_generated.rs libmodule.so extra-$(CONFIG_RUST) += exports_core_generated.h exports_alloc_generated.h extra-$(CONFIG_RUST) += exports_kernel_generated.h -extra-$(CONFIG_RUST) += exports_compiler_builtins_generated.h ifdef CONFIG_CC_IS_CLANG bindgen_c_flags = $(c_flags) @@ -63,10 +62,6 @@ $(objtree)/rust/exports_kernel_generated.h: exports_target_type := _RUST_GPL $(objtree)/rust/exports_kernel_generated.h: $(objtree)/rust/kernel.o FORCE $(call if_changed,exports) -$(objtree)/rust/exports_compiler_builtins_generated.h: exports_target_type := _RUST -$(objtree)/rust/exports_compiler_builtins_generated.h: $(objtree)/rust/compiler_builtins.o FORCE - $(call if_changed,exports) - quiet_cmd_rustc_procmacro = RUSTC P $@ cmd_rustc_procmacro = \ $(RUSTC) $(rustc_flags) --edition 2018 --extern proc_macro \ diff --git a/rust/exports.c b/rust/exports.c index ebb59ccc3d4ed7..900dc3090dd617 100644 --- a/rust/exports.c +++ b/rust/exports.c @@ -16,4 +16,3 @@ #include "exports_core_generated.h" #include "exports_alloc_generated.h" #include "exports_kernel_generated.h" -#include "exports_compiler_builtins_generated.h"