-flto removes const vector

Asked by Sebastian Perta

LTO algorithm removes HardwareVectors from the following test case even though KEEP is used in the linker script
Test case:
void _PowerON_Reset (void)
{
 __asm("");
}

#define FVECT_SECT __attribute__ ((section (".fvectors")))

const void *HardwareVectors[] FVECT_SECT = {
    _PowerON_Reset,
};

int main()
{
 return 0;
}

Invocation:
Option1
arm-none-eabi-gcc -Os test.c -c -flto
arm-none-eabi-gcc -Os -flto test.o -specs=nosys.specs -Wl,-Tscript.ld

Option2:
arm-none-eabi-gcc -Os -flto -specs=nosys.specs test.c -Wl,-Tscript.ld

 Linker script:
SECTIONS
{
 .fvectors 0x20020000 : AT (0x20020000)
 {
  KEEP(*(.fvectors))
 }
 .text 0x20020100 : AT (0x20020100)
 {
  *(.text)
 }
 .rvectors :
 {
  _rvectors_start = .;
  KEEP(*(.rvectors))
  _rvectors_end = .;
 }
 .init :
 {
  *(.init)
  PROVIDE_HIDDEN (__exidx_start = .);
  PROVIDE_HIDDEN (__exidx_end = .);
 }
 .fini :
 {
  *(.fini)
 }
 .got :
 {
  *(.got)
  *(.got.plt)
 }
 .rodata :
 {
  *(.rodata)
  *(.rodata.*)
  _erodata = .;
 }
 .eh_frame_hdr :
 {
  *(.eh_frame_hdr)
 }
 .eh_frame :
 {
  *(.eh_frame)
 }
 .jcr :
 {
  *(.jcr)
 }
 .tors :
 {
  __CTOR_LIST__ = .;
  . = ALIGN(2);
  __ctors = .;
  *(.ctors)
  __ctors_end = .;
  __CTOR_END__ = .;
  __DTOR_LIST__ = .;
  ___dtors = .;
  *(.dtors)
  ___dtors_end = .;
  __DTOR_END__ = .;
  . = ALIGN(2);
  _mdata = .;
 }
 .data 0x20060100 : AT (_mdata)
 {
  _data = .;
  *(.data)
  _edata = .;
 }
 .bss :
 {
  PROVIDE(__bss_start__ = .);
  _bss = .;
  *(.bss)
  *(.bss.**)
  *(COMMON)
  PROVIDE(__bss_end__ = .);
  _ebss = .;
  _end = .;
  PROVIDE(end = .);
 }
 .stack 0x20061100 (NOLOAD) : AT (0x20061100)
 {
  _stack = .;
 }
}

OBS. using __attribute__((used)) works.

Checked with several releases including the latest 5-2016-q2-update, it's reproducible with all of them.

Is this a bug in the compiler, or is there a problem with my invocation? Thank you!

Question information

Language:
English Edit question
Status:
Answered
For:
GNU Arm Embedded Toolchain Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Thomas Preud'homme (thomas-preudhomme) said :
#1

Hi Sebastian,

I have not reproduced your testcase but note that KEEP is a linker directive and only guarantees that the vector will be kept at link time. It could very well be removed at compile time or after link at LTO compile time (when all source are merged together and the compiler invokved again).

You would need to tell GCC somehow that the vector table is used despite not having any reference in the source code. Try using the "used" attribute when declaring the vector.

Best regards.

Can you help with this problem?

Provide an answer of your own, or ask Sebastian Perta for more information if necessary.

To post a message you must log in.