-
Notifications
You must be signed in to change notification settings - Fork 14
Copy globals from program memory into RAM #71
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
Comments
It looks like this function is implemented in I will check if we currently call this. If not, it's possible for us to emit a call to it. |
Which I'd like to be controllable, please :-) |
I compiled avr-rust/blink. The interrupt table is correctly there, as well as the This |
Neat, I missed that!
For reference, I have this as well. The key parts are setting the zero register and populating the stack size, then copying globals to RAM.
Which I have separately and it's all glued together with linker flags. |
I've looked into this a little further and I believe the I have confirmed this by taking a C program that reads a global, compiling it to an object file (which has not been linked with libgcc and so does not contain This generates an executable which does not copy data to RAM, and is therefore broken. I would like to make LLVM output code that triggers You will still be able to avoid the insertion of the |
I'm mostly just mirroring what I discovered GCC to do in my research. My true hope is to have a completely non-GCC reliant solution to allow for the flexibility to have competing solutions. I'm also interested in the possibility of using lld ;-) |
I'm definitely interested in |
There's a small skeleton for AVR support already in lld, which is neat. |
That's quite a surprising result! I wonder if there's an avr-ld flag that might control the setting...
I've heard discussion about some plans here, but I'm not 100% sure what the main motivation for the broader Rust community is. I think lld might be faster than ld or gold? Maybe it's just to avoid having to install a C compiler / linker to run Hello World? That being said, we already have to specify the specific linker now, so presumably specifying |
I've found this in AVR-gcc ( avr_need_copy_data_p = (STR_PREFIX_P (name, ".data")
|| STR_PREFIX_P (name, ".gnu.linkonce.d")); Note that I believe this is the logic which decides whether or not we need a copy_data section. When I disassemble Rust blink, I note that there are dozens of symbols in the output program, but there is only one variable inside a section starting with
I'm not sure why this function isn't triggering the When I modify the blink example to load from a constant static
So the constant is getting placed into When I change the constant static to a mutable static, the symbols do make it into the
And now for the moment of truth - does this generate No, it does not. |
Interestingly, it looks like |
I will message the avr-gcc mailing list |
I've looked into this more and I think I'm getting mixed up. The C compiler of AVR-GCC is declaring The only line required to trigger copying is |
Fixed in r312905, cherry-picked in 6092c82d02b2498b413cbdee5b8617186b70425d. |
Can you give me the TL;DR of how to opt-in to my own non-GCC-provided code? |
Alright, so It appears that if you declare the symbol, the CRT library will call it before it calls main. If you do not declare it, it isn't called and the function doesn't make it into the final object file. Thus, if you don't want to use it, then don't link the CRT. I believe this works well because you're trying to avoid libc/crt code, and so there's no issue there. In the case where no CRT is linked, it just means there is one extra symbol in the executable, but I imagine that it will get trimmed out as there are no references to it. For the other readers, linking with Now, if you link with |
Thanks!
I've been cheating and actually using |
I have a feeling that |
That wound be convenient as I'm already using that :-) |
It looks like avr-gcc generates a
__do_copy_data
function to do this.An example program.
Disassembly
The text was updated successfully, but these errors were encountered: