| 1 |
//! Windows: alignment markers at section bounds. |
| 2 |
|
| 3 |
/// On Windows platforms we don't have start/end symbols, but we do have |
| 4 |
/// section sorting so we drop a minimum-sized type with the same alignment |
| 5 |
/// as T at the start and end of the section. |
| 6 |
#[doc(hidden)] |
| 7 |
#[macro_export] |
| 8 |
macro_rules! __get_section_windows { |
| 9 |
// Movable sections have an additional backref section. |
| 10 |
(movable, name=$name:tt, type=$generic_ty:ty) => { |
| 11 |
{ |
| 12 |
use $crate::__support::Alignment; |
| 13 |
use $crate::__support::PtrBounds; |
| 14 |
use $crate::__support::add_section_link_attribute; |
| 15 |
use core::mem; |
| 16 |
use $crate::__support::SyncUnsafeCell; |
| 17 |
|
| 18 |
if cfg!(miri) { |
| 19 |
// Miri doesn't support link section sorting |
| 20 |
$crate::__support::MovableBounds::new( |
| 21 |
PtrBounds::new(::core::ptr::null(), ::core::ptr::null()), |
| 22 |
PtrBounds::new(::core::ptr::null(), ::core::ptr::null()), |
| 23 |
) |
| 24 |
} else { |
| 25 |
add_section_link_attribute!( |
| 26 |
item data start $name |
| 27 |
#[link_section = __] |
| 28 |
static __START: SyncUnsafeCell<Alignment<$generic_ty>> = SyncUnsafeCell::new(Alignment::new()); |
| 29 |
); |
| 30 |
add_section_link_attribute!( |
| 31 |
item data end $name |
| 32 |
#[link_section = __] |
| 33 |
static __END: SyncUnsafeCell<Alignment<$generic_ty>> = SyncUnsafeCell::new(Alignment::new()); |
| 34 |
); |
| 35 |
add_section_link_attribute!( |
| 36 |
backref data start $name |
| 37 |
#[link_section = __] |
| 38 |
static __REF_START: SyncUnsafeCell<Alignment<$crate::MovableBackref<$generic_ty>>> = |
| 39 |
SyncUnsafeCell::new(Alignment::new()); |
| 40 |
); |
| 41 |
add_section_link_attribute!( |
| 42 |
backref data end $name |
| 43 |
#[link_section = __] |
| 44 |
static __REF_END: SyncUnsafeCell<Alignment<$crate::MovableBackref<$generic_ty>>> = |
| 45 |
SyncUnsafeCell::new(Alignment::new()); |
| 46 |
); |
| 47 |
|
| 48 |
let start = unsafe { &raw const __START as *const () }; |
| 49 |
let start = unsafe { |
| 50 |
start.cast::<u8>().add(mem::size_of::<Alignment<$generic_ty>>()) as *const() |
| 51 |
}; |
| 52 |
let end = unsafe { &raw const __END as *const () }; |
| 53 |
|
| 54 |
let ref_start = unsafe { &raw const __REF_START as *const () }; |
| 55 |
let ref_start = unsafe { |
| 56 |
ref_start.cast::<u8>().add(mem::size_of::<Alignment<$crate::MovableBackref<$generic_ty>>>()) as *const () |
| 57 |
}; |
| 58 |
let ref_end = unsafe { &raw const __REF_END as *const () }; |
| 59 |
|
| 60 |
$crate::__support::MovableBounds::new( |
| 61 |
PtrBounds::new(start, end), |
| 62 |
PtrBounds::new(ref_start, ref_end), |
| 63 |
) |
| 64 |
} |
| 65 |
} |
| 66 |
}; |
| 67 |
// Mutable sections must use UnsafeCell to match items |
| 68 |
(mutable, name=$ident:tt, type=$generic_ty:ty) => { |
| 69 |
{ |
| 70 |
use $crate::__support::Alignment; |
| 71 |
use $crate::__support::PtrBounds; |
| 72 |
use $crate::__support::add_section_link_attribute; |
| 73 |
use core::mem; |
| 74 |
use $crate::__support::SyncUnsafeCell; |
| 75 |
|
| 76 |
if cfg!(miri) { |
| 77 |
// Miri doesn't support link section sorting |
| 78 |
PtrBounds::new(::core::ptr::null(), ::core::ptr::null()) |
| 79 |
} else { |
| 80 |
add_section_link_attribute!( |
| 81 |
item data start $ident |
| 82 |
#[link_section = __] |
| 83 |
static __START: SyncUnsafeCell<Alignment<$generic_ty>> = SyncUnsafeCell::new(Alignment::new()); |
| 84 |
); |
| 85 |
let start = unsafe { |
| 86 |
let start = &raw const __START; |
| 87 |
start.cast::<u8>().add(mem::size_of::<Alignment<$generic_ty>>()) as *const() |
| 88 |
}; |
| 89 |
add_section_link_attribute!( |
| 90 |
item data end $ident |
| 91 |
#[link_section = __] |
| 92 |
static __END: SyncUnsafeCell<Alignment<$generic_ty>> = SyncUnsafeCell::new(Alignment::new()); |
| 93 |
); |
| 94 |
let end = unsafe { &raw const __END as *const () }; |
| 95 |
|
| 96 |
PtrBounds::new(start, end) |
| 97 |
} |
| 98 |
} |
| 99 |
}; |
| 100 |
($section_type:ident, name=$ident:tt, type=$generic_ty:ty) => { |
| 101 |
{ |
| 102 |
use $crate::__support::Alignment; |
| 103 |
use $crate::__support::PtrBounds; |
| 104 |
use $crate::__support::add_section_link_attribute; |
| 105 |
use core::mem; |
| 106 |
|
| 107 |
if cfg!(miri) { |
| 108 |
// Miri doesn't support link section sorting |
| 109 |
PtrBounds::new(::core::ptr::null(), ::core::ptr::null()) |
| 110 |
} else { |
| 111 |
add_section_link_attribute!( |
| 112 |
item data start $ident |
| 113 |
#[link_section = __] |
| 114 |
static __START: Alignment<$generic_ty> = Alignment::new(); |
| 115 |
); |
| 116 |
let start = unsafe { |
| 117 |
let start = &raw const __START; |
| 118 |
start.cast::<u8>().add(mem::size_of::<Alignment<$generic_ty>>()) as *const() |
| 119 |
}; |
| 120 |
add_section_link_attribute!( |
| 121 |
item data end $ident |
| 122 |
#[link_section = __] |
| 123 |
static __END: Alignment<$generic_ty> = Alignment::new(); |
| 124 |
); |
| 125 |
let end = unsafe { &raw const __END as *const () }; |
| 126 |
|
| 127 |
PtrBounds::new(start, end) |
| 128 |
} |
| 129 |
} |
| 130 |
} |
| 131 |
} |
| 132 |
|
| 133 |
pub use crate::__get_section_windows as get_section; |
| 134 |
|
| 135 |
crate::__def_section_name! { |
| 136 |
__section_name_windows, |
| 137 |
{ |
| 138 |
data bare => (".data" "$") __ (); |
| 139 |
data section => (".data" "$") __ ("$b"); |
| 140 |
data start => (".data" "$") __ ("$a"); |
| 141 |
data end => (".data" "$") __ ("$c"); |
| 142 |
code bare => (".text" "$") __ (); |
| 143 |
code section => (".text" "$") __ ("$b"); |
| 144 |
code start => (".text" "$") __ ("$a"); |
| 145 |
code end => (".text" "$") __ ("$c"); |
| 146 |
} |
| 147 |
AUXILIARY = "$d$"; |
| 148 |
REFS = "$r$"; |
| 149 |
MAX_LENGTH = 64; |
| 150 |
HASH_LENGTH = 10; |
| 151 |
VALID_SECTION_CHARS = "_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; |
| 152 |
} |