RX GCC linker bug

I'm experiencing the problem mentioned in the FAQ number 3000668:

Program Built with --gc-sections Option Does Not Run in GCC Project | Renesas Customer Hub

This bug is easily reproducible just by creating a new GCC project for the microcontroller R5F5671EHxFB with C++ and FreeRTOS.

By default, the compiler option --gc-sections is beeing enabled. If you disable it, the code works as expected.

The program is breaking inside 'vTaskStartScheduler', when it tries to call some static privileged fuctions.

I've tried to add KEEP to the .ctors and .dtors sections in the linker file  as mentioned here: 8.3.7 Gc-sections Option (microchip.com), but it does not solve the problem. There must be something else missconfigured.

I do not want to disable this option, because it reduces the size of the final binary file.

Can you check what's the cause of the failure?

Parents
  • KEEP directive with ctors/dtors, init_array and vector tables are commonly seen in GCC projects and you should know why.
    cf. https://blog.thea.codes/the-most-thoroughly-commented-linker-script/
    Also see this FAQ:
    https://en-support.renesas.com/knowledgeBase/20746269

  • Hi Okra, thanks for replying.

    I understand the functionality of the 'KEEP' keyword, I've spent some time reading documentation about it.

    The problem is that I can reproduce this issue, with an empty project (created from a template with e2 studio), and an auto-generated linker script.

    I haven't managed to solve it on my own, and that's why I'm requesting some help.

    This is the linker script, in case you have any clue about the failure:

    MEMORY
    {
    	RAM : ORIGIN = 0x4, LENGTH = 0x5fffc
    	ROM : ORIGIN = 0xFFE00000, LENGTH = 2097152
    	OFS : ORIGIN = 0xFE7F5D00, LENGTH = 128
    }
    SECTIONS
    {
    	.exvectors 0xFFFFFF80: AT(0xFFFFFF80)
    	{
    		"_exvectors_start" = .;
    		KEEP(*(.exvectors))
    	"_exvectors_end" = .;
    	} >ROM
    	.fvectors 0xFFFFFFFC: AT(0xFFFFFFFC)
    	{
    		KEEP(*(.fvectors))
    	} > ROM
    	.text 0xFFE00000: AT(0xFFE00000)
    	{
    		*(.text)
    		*(.text.*)
    		*(P)
    		etext = .;
    	} > ROM
    	.rvectors ALIGN(4):
    	{
    		_rvectors_start = .;
    		INCLUDE ../src/smc_gen/r_bsp/mcu/all/linker_script_rvectors.inc
    		_rvectors_end = .;
    	} > ROM
    	.init :
    	{
    		KEEP(*(.init))
    		__preinit_array_start = .;
    		KEEP(*(.preinit_array))
    		__preinit_array_end = .;
    		__init_array_start = (. + 3) & ~ 3;
    		KEEP(*(.init_array))
    		KEEP(*(SORT(.init_array.*)))
    		__init_array_end = .;
    		__fini_array_start = .;
    		KEEP(*(.fini_array))
    		KEEP(*(SORT(.fini_array.*)))
    		__fini_array_end = .;
    	} > ROM
    	.fini :
    	{
    		KEEP(*(.fini))
    	} > ROM
    	.got :
    	{
    		*(.got)
    		*(.got.plt)
    	} > ROM
    	.rodata :
    	{
    		*(.rodata)
    		*(.rodata.*)
    		*(C_1)
    		*(C_2)
    		*(C)
    		_erodata = .;
    	} > ROM
    	gcc_exceptions_table :
    	{
    	    KEEP (*(.gcc_except_table))
    	    *(.gcc_except_table.*)
    	} > ROM
    	.eh_frame_hdr :
    	{
    		*(.eh_frame_hdr)
    	} > ROM
    	.eh_frame :
    	{
    		*(.eh_frame)
    	} > ROM
    	.jcr :
    	{
    		*(.jcr)
    	} > ROM
    	.tors :
    	{
    		__CTOR_LIST__ = .;
    		. = ALIGN(2);
    		___ctors = .;
    		*(.ctors)
    		___ctors_end = .;
    		__CTOR_END__ = .;
    		__DTOR_LIST__ = .;
    		___dtors = .;
    		*(.dtors)
    		___dtors_end = .;
    		__DTOR_END__ = .;
    		. = ALIGN(2);
    		_mdata = .;
    	} > ROM
    	.data : AT(_mdata)
    	{
    		_data = .;
    		*(.data)
    		*(.data.*)
    		*(D)
    		*(D_1)
    		*(D_2)
    		_edata = .;
    	} > RAM
    	.bss :
    	{
    		_bss = .;
    		*(.bss)
    		*(.bss.**)
    		*(COMMON)
    		*(B)
    		*(B_1)
    		*(B_2)
    		_ebss = .;
    		. = ALIGN(128);
    		_end = .;
    	} > RAM AT>RAM
    	.ofs1 0xFE7F5D00: AT(0xFE7F5D00)
    	{
    		KEEP(*(.ofs1))
    	} > OFS
    	.ofs2 0xFE7F5D10: AT(0xFE7F5D10)
    	{
    		KEEP(*(.ofs2))
    	} > OFS
    	.ofs3 0xFE7F5D20: AT(0xFE7F5D20)
    	{
    		KEEP(*(.ofs3))
    	} > OFS
    	.ofs4 0xFE7F5D40: AT(0xFE7F5D40)
    	{
    		KEEP(*(.ofs4))
    	} > OFS
    	.ofs5 0xFE7F5D48: AT(0xFE7F5D48)
    	{
    		KEEP(*(.ofs5))
    	} > OFS
    	.ofs6 0xFE7F5D50: AT(0xFE7F5D50)
    	{
    		KEEP(*(.ofs6))
    	} > OFS
    	.ofs7 0xFE7F5D64: AT(0xFE7F5D64)
    	{
    		KEEP(*(.ofs7))
    	} > OFS
    	.ofs8 0xFE7F5D70: AT(0xFE7F5D70)
    	{
    		KEEP(*(.ofs8))
    	} > OFS
    .r_bsp_NULL :
    	{
    		. += 0x100;
    		"_r_bsp_NULL_end" = .;
    	} >RAM AT>RAM
    .r_bsp_istack ALIGN(0x4) (NOLOAD) :
    	{
    		KEEP(*(.r_bsp_istack))
    	} >RAM AT>RAM
    .istack :
    	{
    		"_istack" = .;
    	} >RAM
    .r_bsp_ustack ALIGN(0x4) (NOLOAD) :
    	{
    		KEEP(*(.r_bsp_ustack))
    	} >RAM AT>RAM
    .ustack :
    	{
    		"_ustack" = .;
    	} >RAM
    }
    

    Regards,

    Viviana

    PS: I've already read that Renesas FAQ, just check the second line of my post.

Reply Children
No Data