How to use size of linker segment?
How to use size of linker segment?
I try to use this
for (bytes_copied = 0; bytes_copied < __secsize(“PFRAM”); bytes_copied++)
with GCC for RX.
How can I get the segment size?
How can I get the size of section “.PFRAM.A” “.PFRAM.B” … ?
My script is like this
.RamSection :
{
* (RamSection*)
} >RAM2
and I want the size of RamSectionList1, RamSectionList2 … .
Hello,
Thank for reaching out to us.
You can find out the section size several ways, by modifying the linker script. In e2studio 6.2, the linker script can be found in the project generate folder.
The first will be to add _SizeOfSection = SIZEOF(.PFRAM); after the section is declared.
.PFRAM : { *(.PFRAM) *(.PFRAM.*) } > ROM _SizeOfSection = SIZEOF(.PFRAM); To use it in the C file, declare it as follows:
extern char SizeOfSection[];
int main() { uint8_t Section_Size = (uint8_t)SizeOfSection;
//your code here }
Another way to compute the section size requires 2 additional variables to be declared in your project’s linker script: _Section_Start and _Section_End at the beginning, respectively at the end of your PFRAM section, as follows:
.PFRAM : { _Section_Start = .; /* create symbol for start of section */ *(.PFRAM) *(.PFRAM.*) _Section_End = .; /* create symbol for end of section */ } > ROM
Then, in your project’s C source file:
#include <stdint.h> extern const void *Section_Start; extern const void *Section_End;
int main() { uint8_t *start, *end; start = (uint8_t *)&Section_Start; end = (uint8_t)&Section_End; uint8_t Section_Size = end – start; //your code here }
Please let us know if we can be of further assistance.
—
Thank you,
The GNU Tools Team