From 257dc2215887fe9a7a97b0b15a3b9a6df2a78302 Mon Sep 17 00:00:00 2001 From: Andrei Homescu Date: Thu, 31 Jan 2019 17:23:18 -0800 Subject: [PATCH 1/3] Add needs-plt option to target spec to prevent the compiler from using the GOT instead of the PLT --- x86_64-linux-kernel-module.json | 1 + 1 file changed, 1 insertion(+) diff --git a/x86_64-linux-kernel-module.json b/x86_64-linux-kernel-module.json index 93159324..fd5353af 100644 --- a/x86_64-linux-kernel-module.json +++ b/x86_64-linux-kernel-module.json @@ -24,6 +24,7 @@ }, "relocation-model": "static", "relro-level": "full", + "needs-plt": true, "target-c-int-width": "32", "target-endian": "little", "target-family": "unix", From a4609de40a29798768943c457ec209a415ef0928 Mon Sep 17 00:00:00 2001 From: Daniel Kolsoi Date: Thu, 31 Jan 2019 11:30:26 -0800 Subject: [PATCH 2/3] Switch modinfo from &str to &[u8] using const fn .as_bytes() --- hello-world/src/lib.rs | 3 ++- src/lib.rs | 6 +++--- tests/printk/src/lib.rs | 1 + tests/sysctl/src/lib.rs | 1 + 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/hello-world/src/lib.rs b/hello-world/src/lib.rs index 2413fe0a..e56de246 100644 --- a/hello-world/src/lib.rs +++ b/hello-world/src/lib.rs @@ -1,5 +1,5 @@ #![no_std] -#![feature(alloc)] +#![feature(alloc, const_str_as_bytes)] extern crate alloc; use alloc::borrow::ToOwned; @@ -27,6 +27,7 @@ impl Drop for HelloWorldModule { println!("Goodbye kernel module!"); } } + kernel_module!( HelloWorldModule, author: "Alex Gaynor and Geoffrey Thomas", diff --git a/src/lib.rs b/src/lib.rs index 3cba6a18..7e0383db 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -60,9 +60,9 @@ macro_rules! kernel_module { #[link_section = ".modinfo"] #[allow(non_upper_case_globals)] // TODO: Generate a name the same way the kernel's `__MODULE_INFO` does. - // TODO: This needs to be a `&'static [u8]`, since the kernel defines this as a - // `const char []`. - pub static $name: &'static str = concat!(stringify!($name), "=", $value); + // TODO: This needs to be a `[u8; _]`, since the kernel defines this as a `const char []`. + // See https://github.com/rust-lang/rfcs/pull/2545 + pub static $name: &'static [u8] = concat!(stringify!($name), "=", $value, '\0').as_bytes(); }; } diff --git a/tests/printk/src/lib.rs b/tests/printk/src/lib.rs index 3db1517a..dc0d8f4d 100644 --- a/tests/printk/src/lib.rs +++ b/tests/printk/src/lib.rs @@ -1,4 +1,5 @@ #![no_std] +#![feature(const_str_as_bytes)] #[macro_use] extern crate linux_kernel_module; diff --git a/tests/sysctl/src/lib.rs b/tests/sysctl/src/lib.rs index 45fbc871..84e9a052 100644 --- a/tests/sysctl/src/lib.rs +++ b/tests/sysctl/src/lib.rs @@ -1,4 +1,5 @@ #![no_std] +#![feature(const_str_as_bytes)] use core::sync::atomic::AtomicBool; From 27657abf06099adeae11e31398cec9d64b1dac61 Mon Sep 17 00:00:00 2001 From: Daniel Kolsoi Date: Fri, 3 May 2019 22:02:23 -0400 Subject: [PATCH 3/3] Disable trusty build in travis --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 8deb01c5..d86cd470 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,5 @@ matrix: include: - - dist: trusty - dist: xenial language: rust