From c6fd3cdd0a4e29c1e2d77c6e9107450a1bceed92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20G=C3=B3rski?= Date: Wed, 6 Jul 2022 17:43:38 +0200 Subject: [PATCH 1/3] Allow custom `link_section` attributes for late resources This commit makes RTIC aware of user-provided `link_section` attributes, letting user override default section mapping. --- macros/src/codegen/local_resources.rs | 9 ++++++++- macros/src/codegen/shared_resources.rs | 11 +++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/macros/src/codegen/local_resources.rs b/macros/src/codegen/local_resources.rs index 50621c32c0..087967f2a4 100644 --- a/macros/src/codegen/local_resources.rs +++ b/macros/src/codegen/local_resources.rs @@ -27,8 +27,15 @@ pub fn codegen( let mangled_name = util::static_local_resource_ident(name); let attrs = &res.attrs; + // late resources in `util::link_section_uninit` - let section = util::link_section_uninit(); + // unless user specifies custom link section + let section = if attrs.iter().any(|attr| attr.path.is_ident("link_section")) { + None + } + else { + Some(util::link_section_uninit()) + }; // For future use // let doc = format!(" RTIC internal: {}:{}", file!(), line!()); diff --git a/macros/src/codegen/shared_resources.rs b/macros/src/codegen/shared_resources.rs index 47f8faf08c..010b27aea0 100644 --- a/macros/src/codegen/shared_resources.rs +++ b/macros/src/codegen/shared_resources.rs @@ -23,10 +23,17 @@ pub fn codegen( let ty = &res.ty; let mangled_name = &util::static_shared_resource_ident(name); - // late resources in `util::link_section_uninit` - let section = util::link_section_uninit(); let attrs = &res.attrs; + // late resources in `util::link_section_uninit` + // unless user specifies custom link section + let section = if attrs.iter().any(|attr| attr.path.is_ident("link_section")) { + None + } + else { + Some(util::link_section_uninit()) + }; + // For future use // let doc = format!(" RTIC internal: {}:{}", file!(), line!()); mod_app.push(quote!( From b4cfc4db84d304f1fd6384a173d089544340b3e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20G=C3=B3rski?= Date: Wed, 27 Jul 2022 20:25:34 +0200 Subject: [PATCH 2/3] Fix missing formatting --- macros/src/codegen/local_resources.rs | 3 +-- macros/src/codegen/shared_resources.rs | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/macros/src/codegen/local_resources.rs b/macros/src/codegen/local_resources.rs index 087967f2a4..6e7c1daa72 100644 --- a/macros/src/codegen/local_resources.rs +++ b/macros/src/codegen/local_resources.rs @@ -32,8 +32,7 @@ pub fn codegen( // unless user specifies custom link section let section = if attrs.iter().any(|attr| attr.path.is_ident("link_section")) { None - } - else { + } else { Some(util::link_section_uninit()) }; diff --git a/macros/src/codegen/shared_resources.rs b/macros/src/codegen/shared_resources.rs index 010b27aea0..08d77cc326 100644 --- a/macros/src/codegen/shared_resources.rs +++ b/macros/src/codegen/shared_resources.rs @@ -29,8 +29,7 @@ pub fn codegen( // unless user specifies custom link section let section = if attrs.iter().any(|attr| attr.path.is_ident("link_section")) { None - } - else { + } else { Some(util::link_section_uninit()) }; From f15614e7cbba889462a22ae94b470e9a3c3dc817 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20G=C3=B3rski?= Date: Wed, 27 Jul 2022 20:29:14 +0200 Subject: [PATCH 3/3] Update CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 68af76937c..b131b30729 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ For each category, *Added*, *Changed*, *Fixed* add new entries at the top! ### Added +- Allow custom `link_section` attributes for late resources + ### Fixed ### Changed