I'm developing a c application on an embedded processor with a gcc-based toolchain. In my application I need to place a flag at a specific memory location. I need help with the linker command file syntax to accomplish this.
In your C file write something like:
static int flag __attribute__ ((section (".flag"))) __attribute__ ((__used__)) = 6;
In your custom linker script, add .flag to the desired section:
_flag_start = 0x00001234;
.flag _flag_start :
{
KEEP(*(.flag)) ;
}
Be sure to add this on the correct place, as the location pointer can only grow The location pointer will be set to _flag_start + [size of your flag]
after this block, meaning that all subsequent sections will be placed at that address or higher.
And of course, read and use the manual David Grayson provided.
I had to do this on a Cortex-M3 one time. My linker script is long, complicated, and private but this page helped me to write it and you might find it useful too:
http://www.linuxselfhelp.com/gnu/ld/html_chapter/ld_3.html
I would recommend finding the existing linker script that your compiler is using by default, and then modifying that by adding a special section at a specific address, and putting your flag in that section in the source code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With