Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't initialize memory for late resources #52

Closed
japaric opened this issue Nov 22, 2017 · 5 comments
Closed

Don't initialize memory for late resources #52

japaric opened this issue Nov 22, 2017 · 5 comments

Comments

@japaric
Copy link
Collaborator

japaric commented Nov 22, 2017

Late resources are initialized at runtime so their memory doesn't need to be initialized before main / init. However, today, late resources are placed in the .data section so not only they get initialized (using memcpy) but they also use up FLASH memory (because everything in .data has some initial value stored in FLASH).

To fix this we'll have to create a new section, let's call it .uninit, in cortex-m-rt and then place the static variables that will be used with late resources in that section. The change in this repo is minimal; here's the patch (macros/src/trans.rs):

                 None => quote! {
                     // Resource initialized in `init`
-                    static mut #_name: #krate::UntaggedOption<#ty> = #krate::UntaggedOption { none: () };
+                    #[link_section = ".uninit"]
+                    static mut #_name: #krate::UntaggedOption<#ty> =
+                        #krate::UntaggedOption { none: () };
                 },

But this change requires updating cortex-m-rt, specially if rust-embedded/cortex-m-rt#43 lands. It's probably best to wait until rust-embedded/cortex-m-rt#43 lands.

@jonas-schievink
Copy link
Contributor

There is a rustc "bug" hidden in here: There's no need to put an UntaggedOption intialized with none into the .data section, rustc/LLVM can put it in .bss in all cases (or .uninit, of course, but that's not a standard section), which would also help in this case.

@jonas-schievink
Copy link
Contributor

The underlying rustc bug is rust-lang/rust#41315, which was fixed by rust-lang/rust#48908, so this should work now

@japaric
Copy link
Collaborator Author

japaric commented Nov 3, 2018

triage: blocked on rust-embedded/cortex-m-rt#116

@korken89
Copy link
Collaborator

Is this fixed with having the .uninit section?
If so can we close this?

@japaric
Copy link
Collaborator Author

japaric commented Jan 6, 2020

Yes, this has already been implemented.

@japaric japaric closed this as completed Jan 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants