我正在尝试使用 clang 为 Cortex-M0 构建固件。gcc 构建当然可以正常工作。链接期间构建失败
ld.lld: error: baremetal.ld:72: ( expected, but got )
>>> KEEP(*.init_array)
>>> ^
clang-12: error: ld.lld command failed with exit code 1 (use -v to see invocation)
链接器脚本是相当标准的(并且违规行也在 CMSIS 提供的脚本中)。相关部分:
.rodata : ALIGN(4)
{
*(.rodata .rodata.* .gnu.linkonce.r.*)
. = ALIGN(4);
KEEP(*(.init))
. = ALIGN(4);
__preinit_array_start = . ;
KEEP(*(.preinit_array))
__preinit_array_end = . ;
. = ALIGN(4);
__init_array_start = . ;
KEEP(*(SORT(.init_array.*)))
KEEP(*.init_array) <<======== error here
__init_array_end = . ;
. = ALIGN(4);
KEEP(*(.fini))
. = ALIGN(4);
__fini_array_start = . ;
KEEP(*(.fini_array))
KEEP(*(SORT(.fini_array.*)))
__fini_array_end = . ;
. = ALIGN(4);
KEEP (*crtbegin.o(.ctors))
KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*crtend.o(.ctors))
. = ALIGN(0x4);
KEEP (*crtbegin.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
KEEP (*(SORT(.dtors.*)))
KEEP (*crtend.o(.dtors))
*(.init .init.*)
*(.fini .fini.*)
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array))
PROVIDE_HIDDEN (__init_array_end = .);
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(.fini_array))
KEEP (*(SORT(.fini_array.*)))
PROVIDE_HIDDEN (__fini_array_end = .);
. = ALIGN (8);
*(.rom)
*(.rom.b)
_etext = . ;
_sidata = _etext; /* first address of initialized data in FLASH */
} >FLASH
我的 LLD 版本
$ ld.lld -V
LLD 13.0.0 (compatible with GNU linkers)
如何修复链接?