3

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.

  • What do you mean with 'place a flag'? Do you have to define a C variable at a specific location, so that it can be accessed by another process? Like some kind of version information, or a boot option? – parvus Nov 6 '13 at 19:35
2

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.

  • Thanks for the help parvus. Your solution worked except for the "KEEP" directive gave me a linker error. Perhaps it is because of the toolset I'm working with. Once I removed it then I was in business. – ejwipp Nov 15 '13 at 15:22
1

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.

  • There was nothing wrong with your answer, but parvus gave example code. Thanks for the link to the document! – ejwipp Nov 15 '13 at 15:23

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.