Linker does not honor section attribute or linker script sections
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
GNU Arm Embedded Toolchain |
Invalid
|
Undecided
|
Terry Guo |
Bug Description
I have observed that when compiling and linking with link time optimization, linker is not honoring the __attribute_
I am using following flags to enable LTO:
CFLAGS += -flto -ffat-lto-objects
LDFLAGS += -flto
I have also tried to add -fuse-linker-plugin to both CFLAGS and LDFLAGS but results are unchanged.
Functions are defined as:
__attribute_
{
/* some code here */
}
Additionally some object files are entirely put in different sections using linker script:
SECTIONS
{
.section2 (__ram_start):
{
*file2.o (.text .text.* .rodata .rodata.*)
}
.text (__flash_
{
*(.text .text.*)
}
}
In both cases, instead of code/data going into respective sections, it goes to .text or .bss or .data. In my case, .section1/2 goes into RAM whereas .text section goes into flash from where it is executed in place. So, putting .section1/2 in .text and therefore in flash is totally unacceptable.
I have found work-around for both cases like this:
__attribute_
{
/* some code here */
}
and compiling file2.c without LTO flags. However these are more like work-arounds and do not seem like proper fixes.
My question is: Is this the intended behavior of LTO or a bug? And if not bug, why and is there any better solution than mentioned above?
Thanks
Changed in gcc-arm-embedded: | |
assignee: | nobody → Terry Guo (terry.guo) |
Maybe your function func() is inlined. If I define function as below:
terguo01@ terry-pc01: minimum$ cat foo.c
void __attribute_ _((section( ".section1" ))) _((noinline) )
__attribute_
foo ()
{
volatile int x;
x = 10;
}
The foo() can be kept in section .section1.