Skip to content
This repository has been archived by the owner on Mar 7, 2021. It is now read-only.

modinfo needs a const char [], not a const char * #80

Closed
geofft opened this issue May 6, 2019 · 1 comment
Closed

modinfo needs a const char [], not a const char * #80

geofft opened this issue May 6, 2019 · 1 comment
Labels
bug Something isn't working

Comments

@geofft
Copy link
Collaborator

geofft commented May 6, 2019

We use this (from src/lib.rs) to set modinfo:

#[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 `[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();

This (likely) stores a pointer to a string in the modinfo section instead of storing the string directly.

@geofft
Copy link
Collaborator Author

geofft commented May 6, 2019

I'm having a real hard time turning the output of str::as_bytes into a [u8; N]. If I compile

#[link_section = ".modinfo"]
pub static FOO: [u8; 11] = b"Hello world";

with rustc --crate-type=dylib and do an objdump -s -j .modinfo on it, it works great. And I can even type it as [u8; b"Hello world".len()] (with #![feature(const_slice_len)]). If I try to do anything involving "Hello world".as_bytes() I get into endless difficulty trying to coerce a [u8] to a [u8; N]. So even if we got rust-lang/rfcs#2545 it wouldn't help that much. :(

Maybe the right strategy is to tackle this and #16 at the same time, switch to bytes instead of strings as input, and adopt e.g. https://github.com/danielhenrymantilla/byte-strings-rs which uses proc macros to implement concat_bytes!etc. Then the macro is probably something like

pub static $name: [u8; c_str!(as_bytes!(stringify!($name), b"=", as_bytes!($value)).len()]
                     = c_str!(as_bytes!(stringify!($name), b"=", as_bytes!($value));

geofft added a commit that referenced this issue May 6, 2019
@alex alex added the bug Something isn't working label Sep 1, 2019
geofft added a commit that referenced this issue Aug 9, 2020
geofft added a commit that referenced this issue Aug 9, 2020
geofft added a commit that referenced this issue Aug 9, 2020
geofft added a commit that referenced this issue Aug 9, 2020
geofft added a commit that referenced this issue Aug 10, 2020
@geofft geofft closed this as completed in 86a8004 Aug 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants