Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,6 @@ pub fn timestamp(ts: TokenStream) -> TokenStream {
)
.into()
} else {
let section = {
if cfg!(target_os = "macos") {
".defmt,end_timestamp"
} else {
".defmt.end.timestamp"
}
};
quote!(
const _: () = {
#[export_name = "_defmt_timestamp"]
Expand All @@ -204,7 +197,8 @@ pub fn timestamp(ts: TokenStream) -> TokenStream {
// Unique symbol name to prevent multiple `timestamp!` invocations in the crate graph.
// Uses `#symname` to ensure it is not discarded by the linker.
#[no_mangle]
#[link_section = #section]
#[cfg_attr(target_os = "macos", link_section = ".defmt,end_timestamp")]
#[cfg_attr(not(target_os = "macos"), link_section = ".defmt.end_timestamp")]
Comment thread
jonas-schievink marked this conversation as resolved.
Outdated
static __DEFMT_MARKER_TIMESTAMP_WAS_DEFINED: &u8 = &#symname;
};
)
Expand Down Expand Up @@ -995,13 +989,15 @@ pub fn internp(ts: TokenStream) -> TokenStream {

let sym = symbol::Symbol::new("prim", &ls).mangle();

let section = mksection("prim.", &sym);
let section = mksection(false, "prim.", &sym);
let section_macos = mksection(true, "prim.", &sym);

if cfg!(feature = "unstable-test") {
quote!({ defmt::export::fetch_add_string_index() as u8 })
} else {
quote!({
#[link_section = #section]
#[cfg_attr(target_os = "macos", link_section = #section_macos)]
#[cfg_attr(not(target_os = "macos"), link_section = #section)]
#[export_name = #sym]
static S: u8 = 0;
&S as *const u8 as u8
Expand Down Expand Up @@ -1054,10 +1050,10 @@ pub fn write(ts: TokenStream) -> TokenStream {
/// returns (note the comma character for macos):
/// under macos: ".defmt," + 16 character hex digest of symbol's hash
/// otherwise: ".defmt." + prefix + symbol
fn mksection(prefix: &str, symbol: &str) -> String {
fn mksection(macos: bool, prefix: &str, symbol: &str) -> String {
let mut sub_section = format!(".{}{}", prefix, symbol);

if cfg!(target_os = "macos") {
if macos {
let mut hasher = DefaultHasher::new();
sub_section.hash(&mut hasher);
sub_section = format!(",{:x}", hasher.finish());
Expand All @@ -1068,10 +1064,12 @@ fn mksection(prefix: &str, symbol: &str) -> String {

fn mkstatic(varname: Ident2, string: &str, tag: &str) -> TokenStream2 {
let sym = symbol::Symbol::new(tag, string).mangle();
let section = mksection("", &sym);
let section = mksection(false, "", &sym);
let section_macos = mksection(true, "", &sym);

quote!(
#[link_section = #section]
#[cfg_attr(target_os = "macos", link_section = #section_macos)]
#[cfg_attr(not(target_os = "macos"), link_section = #section)]
#[export_name = #sym]
static #varname: u8 = 0;
)
Expand Down