Preventing gc-sections of one section

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

I am working on sharing code between an app and bootloader. I am locating a jump table at the end of the bootloader that is in its own named section and positioned with --section-start.

For consistency, I am calling through the jumptable pointers in both the app and bootloader. But the problem is that the linker will drop the jump table section when using --gc-sections if there is nothing explicitly calling on of those functions.

Is there a clean way to prevent this with another linker flags? Or will I be forced to make a direct call to a function in that section?

-Brad

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

This makes symbol appear undefined which should force the linker to include the compilation unit that contains it.

Quote:
-Wl,-u symbol

Or the 'used' function attribute might work also.

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

'used' would be perfect since I'd rather keep the deceleration with the source. Any idea how to apply an __attribute__((used)) to an asm only function or section?

Haven't found it using Google...

-Brad

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

schickb wrote:
'used' would be perfect since I'd rather keep the deceleration with the source. Any idea how to apply an __attribute__((used)) to an asm only function or section?

Haven't found it using Google...

I don't know much about the gnu assembler so I'm not sure if you can. I didn't see anything obvious in the gas manual (there is no .used directive).

You might be able to declare the asm function/variable in a C header file and attach the attribute to it.

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

Argg, I don't know if __attribute__((used)) even works. I tried sticking this in c file:

uint8_t bogosity(void) __attribute__((used));
uint8_t bogosity(void)
{
    volatile uint8_t a = 1 + 2;
    return a;
}

and it still gets dropped by the linker. If I add a call to it somewhere, however, it is kept.

So I tried the linker flag you suggested and that works. Since all of the functions are in one section I can just specify one of them and the entire table is preserved. Thanks a lot.

Either of the follow are correct syntax if passing through gcc:

-Wl,--undefined=function_name
-Wl,-u,function_name

-Brad

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

You can do this with a custom linker script. Take the default linker script for your architecture (*.x) and copy it into your project. Modify it by adding your custom section and use the KEEP() command. As an example, look in the linker script to see how it is done for the interrupt vector table:

KEEP(*(.vectors))

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

EW wrote:
You can do this with a custom linker script. Take the default linker script for your architecture (*.x) and copy it into your project....

Thanks, I'll keep that in mind. For now I think the --undefined linker flag is a simpler solution. Unless you know of some problem this that?

-Brad