78
78
//! // This `static` must never be directly dereferenced/accessed!
79
79
//! // So a `let data: u8 = P_BYTE;` is **undefined behavior**!!!
80
80
//! /// Static byte stored in progmem!
81
- //! #[link_section = ".progmem"]
81
+ //! #[link_section = ".progmem.data "]
82
82
//! static P_BYTE: u8 = b'A';
83
83
//!
84
84
//! // Load the byte from progmem
104
104
//! (it has to be a macro), which will create a static variable in program
105
105
//! memory for you and wrap it in the `ProgMem` struct. It will ensure that the
106
106
//! `static` will be stored in the program memory by defining the
107
- //! `#[link_section = ".progmem"]` attribute on it. This makes the load
107
+ //! `#[link_section = ".progmem.data "]` attribute on it. This makes the load
108
108
//! functions on that struct sound and additionally prevents users to
109
109
//! accidentally access that `static` directly, which, since it is in progmem,
110
110
//! would be fundamentally unsound.
116
116
//!
117
117
//! // It will be wrapped in the ProgMem struct and expand to:
118
118
//! // ```
119
- //! // #[link_section = ".progmem"]
119
+ //! // #[link_section = ".progmem.data "]
120
120
//! // static P_BYTE: ProgMem<u8> = unsafe { ProgMem::new(b'A') };
121
121
//! // ```
122
122
//! // Thus it is impossible for safe Rust to directly dereference/access it!
@@ -199,7 +199,7 @@ use cfg_if::cfg_if;
199
199
/// 'best-effort' notation).
200
200
///
201
201
/// However, there is a rather simple way to make is sound, and that is defining
202
- /// the `#[link_section = ".progmem"]` (or `".text"`) on a static that contains
202
+ /// the `#[link_section = ".progmem.data "]` (or `".text"`) on a static that contains
203
203
/// this struct. And since its that simple, a macro `progmem!` is provided that
204
204
/// will ensure this and should be always used to obtain a `ProgMem` instance
205
205
/// in the first place.
@@ -252,7 +252,7 @@ impl<T> ProgMem<T> {
252
252
///
253
253
/// That means that this function is only sound to call, if the value is
254
254
/// stored in a static that is for instance attributed with
255
- /// `#[link_section = ".progmem"]`.
255
+ /// `#[link_section = ".progmem.data "]`.
256
256
///
257
257
/// However, the above requirement only applies to the AVR architecture
258
258
/// (`#[cfg(target_arch = "avr")]`), because otherwise normal data access
@@ -401,7 +401,7 @@ macro_rules! progmem_internal {
401
401
} => {
402
402
// ProgMem must be stored in the progmem or text section!
403
403
// The link_section lets us define it.
404
- #[ cfg_attr( target_arch = "avr" , link_section = ".progmem" ) ]
404
+ #[ cfg_attr( target_arch = "avr" , link_section = ".progmem.data " ) ]
405
405
// User attributes
406
406
$( #[ $attr] ) *
407
407
// The actual static definition
@@ -493,7 +493,7 @@ macro_rules! progmem {
493
493
/// // This static must never be directly dereferenced/accessed!
494
494
/// // So a `let data: u8 = P_BYTE;` is Undefined Behavior!!!
495
495
/// /// Static byte stored in progmem!
496
- /// #[link_section = ".progmem"]
496
+ /// #[link_section = ".progmem.data "]
497
497
/// static P_BYTE: u8 = b'A';
498
498
///
499
499
/// // Load the byte from progmem
@@ -512,7 +512,7 @@ macro_rules! progmem {
512
512
/// Typically only function pointers (which make no sense here) and pointer to
513
513
/// or into statics that are defined to be stored into progmem are valid.
514
514
/// For instance, a valid progmem statics would be one, that is attributed with
515
- /// `#[link_section = ".progmem"]`.
515
+ /// `#[link_section = ".progmem.data "]`.
516
516
///
517
517
/// Also general Rust pointer dereferencing constraints apply, i.e. it must not
518
518
/// be dangling.
@@ -584,6 +584,7 @@ pub unsafe fn read_byte(p_addr: *const u8) -> u8 {
584
584
/// However alignment is not strictly required for AVR, since the read/write is
585
585
/// done byte-wise.
586
586
///
587
+ #[ allow( dead_code) ]
587
588
unsafe fn read_byte_loop_raw < T > ( p_addr : * const T , out : * mut T , len : u8 )
588
589
where T : Sized + Copy {
589
590
@@ -778,7 +779,7 @@ unsafe fn read_value_raw<T>(p_addr: *const T, out: *mut T, len: u8)
778
779
/// // Also notice the `*` in front of the string, because we want to store the
779
780
/// // data, not just a reference!
780
781
/// /// Static bytes stored in progmem!
781
- /// #[link_section = ".progmem"]
782
+ /// #[link_section = ".progmem.data "]
782
783
/// static P_ARRAY: [u8;11] = *b"Hello World";
783
784
///
784
785
/// // Notice since we use a sub-slice the data better is pre-initialized even
@@ -864,7 +865,7 @@ pub unsafe fn read_slice(p: &[u8], out: &mut [u8]) {
864
865
/// // Also notice the `*` in front of the string, because we want to store the
865
866
/// // data, not just a reference!
866
867
/// /// Static bytes stored in progmem!
867
- /// #[link_section = ".progmem"]
868
+ /// #[link_section = ".progmem.data "]
868
869
/// static P_ARRAY: [u8;11] = *b"Hello World";
869
870
///
870
871
/// // Load the bytes from progmem
@@ -881,7 +882,7 @@ pub unsafe fn read_slice(p: &[u8], out: &mut [u8]) {
881
882
/// use avr_progmem::read_value;
882
883
///
883
884
/// /// Static bytes stored in progmem!
884
- /// #[link_section = ".progmem"]
885
+ /// #[link_section = ".progmem.data "]
885
886
/// static P_ARRAY: [u8;11] = *b"Hello World";
886
887
///
887
888
/// // Get a sub-array reference without dereferencing it
0 commit comments