I try find answer long time. Sorry but I really can't find it.
I use gcc,ld,gcc(for assembler compilation).
I wrote ld script:
SECTIONS
{
.text : *{.text}
}
LS_size = (SIZEOF(.text) + 2048 ) & ( 0xF800 ) >> 9 ;
I try use LS_size from assembler:
_rom_size:
.byte LS_size
Its work fine, but on C code I can't set value to variable:
struct my_struct vari = {
.codesize = LS_size,
}
If I extern LS_size, I got:
error: initializer element is not constant
How can I set default value for my constant C variables from variables, which are produced in ld scripts?
LS_sizeisn't known at compile time, since it's a linker script variable. You could try adding anextern const size_t LS_size;declaration in your C code, and move the initialization ofvari.codesizeto some function.