Skip to main content
Visitor II
September 9, 2025
Solved

L6218E: Undefined symbol errors with armlink on STM32G474x

  • September 9, 2025
  • 1 reply
  • 1056 views

MCU: STM32G474xx
IDE: VSCode
Toolchain: ARM Compiler 6 (armclang, armlink)
Question:

I'm a newcomer to using armclang and armlink for compiling and linking a project for an STM32G4 MCU. I've successfully compiled a minimal project and am trying to link it using armlink.

My scatter file is:

LR_IROM1 0x08000000 0x00080000 { ; load region size_region
 ER_IROM1 0x08000000 0x00080000 { ; load address = execution address
 *.o (.isr_vector, +First)
 *(InRoot$$Sections)
 .ANY (+RO)
 .ANY (+XO)
 }
 RW_IRAM1 0x20000000 0x00020000 { ; RW data
 .ANY (+RW +ZI)
 }
}

I use a startup script in GNU syntax generated from CubeMX.
The linker command I am using is: armlink --cpu=Cortex-M4.fp.sp *.o --scatter=STM32G474XX_FLASH.sct --map --info=summarysizes --load_addr_map_info --xref --callgraph --symbols --info=sizes --info=totals --info=unused --info=veneers

This setup results in the following linking errors:

Error: L6218E: Undefined symbol _sidata (referred from startup_stm32g474xx.o).
Error: L6218E: Undefined symbol _sdata (referred from startup_stm32g474xx.o).
Error: L6218E: Undefined symbol _edata (referred from startup_stm32g474xx.o).
Error: L6218E: Undefined symbol _sbss (referred from startup_stm32g474xx.o).
Error: L6218E: Undefined symbol _ebss (referred from startup_stm32g474xx.o).
Error: L6218E: Undefined symbol __libc_init_array (referred from startup_stm32g474xx.o).
Error: L6218E: Undefined symbol _estack (referred from startup_stm32g474xx.o).

I understand that the scatter file defines memory regions, but it seems I also need to define these specific symbols (_sidata, _sdata, _estack, etc.) for the linker. How do I properly define these symbols within the .sct file, and what is the correct way to resolve the missing __libc_init_array function?

    This topic has been closed for replies.
    Best answer by mƎALLEm

    Hello @amoehring99 and welcome to the community,

    It seems like your project is pointing to a wrong startup file from GCC (Drivers\CMSIS\Device\ST\STM32G4xx\Source\Templates\gcc\startup_stm32g474xx.s)

    _sidata, _sdata etc.. are located in the .s file of GCC.
    You need to link the .s file of arm.

    Try to link the file Drivers\CMSIS\Device\ST\STM32G4xx\Source\Templates\arm\startup_stm32g474xx.s to your project instead what you have.

     

    1 reply

    mƎALLEmAnswer
    Technical Moderator
    September 18, 2025

    Hello @amoehring99 and welcome to the community,

    It seems like your project is pointing to a wrong startup file from GCC (Drivers\CMSIS\Device\ST\STM32G4xx\Source\Templates\gcc\startup_stm32g474xx.s)

    _sidata, _sdata etc.. are located in the .s file of GCC.
    You need to link the .s file of arm.

    Try to link the file Drivers\CMSIS\Device\ST\STM32G4xx\Source\Templates\arm\startup_stm32g474xx.s to your project instead what you have.