Variable in custom section not linked

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am trying to place uint32_t variable in my custom linker section (GCC), which is located after interrupt vectors. On ATmega32u4, this address seems to be 0xAC. The purpose of this section is to store application length. I've extended linker script like this:

 

*(.vectors)
KEEP(*(.vectors))
*(.applen)
KEEP(*(.applen)) /* not sure i need this */

I've also defined global variable like this:

 

const uint32_t ProgramLength __attribute__ ((section (".applen"))) = 0;

So, after compilation, when I look at .map file, I see this:

 

.text           0x0000000000000000     0x6066
 *(.vectors)
 .vectors       0x0000000000000000       0xac /usr/lib/gcc/avr/4.9.2/../../../avr/lib/avr5/crtatmega32u4.o
                0x0000000000000000                __vectors
                0x0000000000000000                __vector_default
 *(.vectors)
 *(.applen)
 *(.applen)
 *(.progmem.gcc*)
                0x00000000000000ac                . = ALIGN (0x2)
                0x00000000000000ac                __trampolines_start = .
 *(.trampolines)
 .trampolines   0x00000000000000ac        0x0 linker stubs
 *(.trampolines*)
                0x00000000000000ac                __trampolines_end = .
 *libprintf_flt.a:*(.progmem.data)
 *libc.a:*(.progmem.data)
 *(.progmem*)
 .progmem.data.ProductString
                0x00000000000000ac       0x14 build/firmware/board/avr/usb/Descriptors.o
                0x00000000000000ac                ProductString

As you can see, there is no ProgramLength variable there, and also, string descriptors used by LUFA library actually start where my variable should. What exactly am I doing wrong here?

Last Edited: Sat. Jan 27, 2018 - 06:17 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is the variable used (referenced) at all in the code? The KEEP in the linker script won't stop the optimizing phase of the compiler to optimize out an unused variable. Try adding another attribute to the variable:

__attribute__((used))

 

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It was not - adding

__attribute__((used))

fixed it - thanks a lot!