diff --git a/Cargo.toml b/Cargo.toml index f12a10e..2da75d5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,12 +1,12 @@ [workspace] -resolver = "2" +resolver = "3" members = [ "linker-sections", "examples/*", ] [workspace.package] -edition = "2021" +edition = "2024" license = "MIT OR Apache-2.0" repository = "https://github.com/tlevora/linker-sections-init-rs" readme = "README.md" diff --git a/README.md b/README.md index 0699f8c..ba694c6 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ use {defmt_rtt as _, panic_probe as _}; const INITIAL_VALUE: u32 = 0xDEAD_BEEF; -#[link_section = ".custom_data"] +#[unsafe(link_section = ".custom_data")] static mut STATIC_VARIABLE: u32 = INITIAL_VALUE; #[cortex_m_rt::pre_init] diff --git a/examples/demo/src/main.rs b/examples/demo/src/main.rs index e68c986..431f293 100644 --- a/examples/demo/src/main.rs +++ b/examples/demo/src/main.rs @@ -12,7 +12,7 @@ const INITIAL_VALUE: u32 = 0xDEAD_BEEF; // - Using static mut just to force compiler not to optimize it out in // this simple example // - linker section gets initialized because of using `linker_sections` -#[link_section = ".custom_data_a"] +#[unsafe(link_section = ".custom_data_a")] static mut STATIC_ARRAY_A: u32 = INITIAL_VALUE; #[allow(unsafe_code)] @@ -20,7 +20,7 @@ static mut STATIC_ARRAY_A: u32 = INITIAL_VALUE; // - Using static mut just to force compiler not to optimize it out in // this simple example // - linker section gets initialized because of using `linker_sections` -#[link_section = ".custom_data_b"] +#[unsafe(link_section = ".custom_data_b")] static mut STATIC_ARRAY_B: [u32; 256] = [INITIAL_VALUE; 256]; #[cortex_m_rt::pre_init] diff --git a/examples/static-cell/src/main.rs b/examples/static-cell/src/main.rs index 45a8e74..d7e7db4 100644 --- a/examples/static-cell/src/main.rs +++ b/examples/static-cell/src/main.rs @@ -13,7 +13,7 @@ const INITIAL_VALUE: u32 = 0xDEAD_BEEF; // - Using static mut just to force compiler not to optimize it out in // this simple example // - linker section gets initialized because of using `linker_sections` -#[link_section = ".custom_data"] +#[unsafe(link_section = ".custom_data")] static STATIC_ARRAY_A: StaticCell = StaticCell::new(); #[allow(unsafe_code)] @@ -21,7 +21,7 @@ static STATIC_ARRAY_A: StaticCell = StaticCell::new(); // - Using static mut just to force compiler not to optimize it out in // this simple example // - linker section gets initialized because of using `linker_sections` -#[link_section = ".custom_data"] +#[unsafe(link_section = ".custom_data")] static STATIC_ARRAY_B: StaticCell<[u32; 256]> = StaticCell::new(); #[cortex_m_rt::pre_init] diff --git a/linker-sections/src/lib.rs b/linker-sections/src/lib.rs index 125383b..dda4abc 100644 --- a/linker-sections/src/lib.rs +++ b/linker-sections/src/lib.rs @@ -68,7 +68,7 @@ //! //! const INITIAL_VALUE: u32 = 0xDEAD_BEEF; //! -//! #[link_section = ".custom_data"] +//! #[unsafe(link_section = ".custom_data")] //! static mut STATIC_VARIABLE: u32 = INITIAL_VALUE; //! #[cortex_m_rt::pre_init] //! unsafe fn pre_init() { @@ -253,7 +253,7 @@ macro_rules! section_init_with_prefixes { #[doc(hidden)] macro_rules! pointer { ($name:ident) => { - extern "C" { + unsafe extern "C" { static $name: u32; } }; @@ -263,7 +263,7 @@ macro_rules! pointer { #[doc(hidden)] macro_rules! pointer_mut { ($name:ident) => { - extern "C" { + unsafe extern "C" { static mut $name: u32; } }; @@ -286,7 +286,7 @@ pub unsafe fn section_init(dst: *mut u32, end: *const u32, src: *const u32) { assert!(end as usize % 4 == 0); } - let len = end.offset_from(dst) as usize; + let len = unsafe { end.offset_from(dst) } as usize; #[cfg(feature = "asserts")] { @@ -297,5 +297,5 @@ pub unsafe fn section_init(dst: *mut u32, end: *const u32, src: *const u32) { assert!(src > dst + len || src + len < dst); } - core::ptr::copy_nonoverlapping(src, dst, len); + unsafe { core::ptr::copy_nonoverlapping(src, dst, len) }; }