This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

__init_array_start placed in RAM?

Hi, I'm just debugging, why global C++ object c'tor are not called when using gcc/newlib. I stombled over the fact that within the linker script, provided with the sdk 8.2, the .init_array sections of the objects are placed into RAM.

Why is this so? Why not placing this vector into flash?

kind regards, Torsten

Parents
  • .. let me try that answer again ..

    The AT( __etext ) means the actual addresses are placed into flash because that's where etext is pointing at the time that section is linked. I would expect gcc's crt0 to run the pre/init/post functions from flash using the symbols __preinit_array_start .. etc.

    However it does seem that those sections are also allocated space in RAM, much like initialised data which would be copied over, even though they aren't going to be copied over. That would seem to waste RAM although it should still work.

    I've always found it rather tricky to work out which crt0 gcc links in with various combinations of flags and libraries and usually end up looking at the ELF file to work out which it is.

  • There should be two parts to is, one piece allocated in RAM, the other piece allocated in flash which is where you'd expect to copy the pointers from to initialise them. Since these pointers are function pointers they don't need to be copied at all, they can be called from flash directly, so the RAM is at best wasted and at worse incorrect - depends what crt0 does.

Reply
  • There should be two parts to is, one piece allocated in RAM, the other piece allocated in flash which is where you'd expect to copy the pointers from to initialise them. Since these pointers are function pointers they don't need to be copied at all, they can be called from flash directly, so the RAM is at best wasted and at worse incorrect - depends what crt0 does.

Children
No Data
Related