用于Newlib-Nano的Cortex-M3(EFM 32 GG)- ARM-GCC连接器标志

wf82jlnq  于 2023-06-30  发布在  其他
关注(0)|答案(1)|浏览(147)

我分析了Simplicity Studio(Silicon Labs的Eclipse IDE变体,用于其微控制器)生成的项目。
我使用了基于arm-none-eabi-gcc工具链的ASM/C/C项目的默认设置。
对于G
-Linker-Flags,他们做了一些在我看来非常奇怪的事情:他们打算链接到newlib-nano(标准库的小版本)。
然而,通常你需要决定你是否打算使用重定向,从而链接到nosys.specs,这也会使你的二进制文件更大,或者最小的一个是nano. specs。
然而,他们确实列出了两个选项,这对我来说没有意义。因此,我检查了另一个项目设置(这是在一个CM 3从STM32),他们显然做了同样的事情。这是为什么呢?
如果我不打算使用重定向(比如文件系统,printf/_write等),我需要列出nosys.specs吗?
补充问题:这些标志的顺序是否重要,或者这只是您要添加的所有选项的列表?

-g3 -gdwarf-2 -mcpu=cortex-m3 -mthumb -T "${BuildArtifactFileBaseName}.ld" --specs=nosys.specs -Xlinker --gc-sections -Xlinker -Map="${BuildArtifactFileBaseName}.map" --specs=nano.specs
klh5stk1

klh5stk11#

然而,他们确实列出了两个选项,这对我来说没有意义。
很有道理。如果没有nosys,你需要提供大量函数的定义,或者使用另一个库,例如semihostig。
简单示例:(main.c是hello world程序)

piotr@PiotrLaptop02:~$ arm-none-eabi-gcc --specs=nano.specs main.c
/usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/lib/libc_nano.a(lib_a-exit.o): in function `exit':
/build/newlib-CVVEyx/newlib-3.3.0/build_nano/arm-none-eabi/newlib/libc/stdlib/../../../../../newlib/libc/stdlib/exit.c:64: undefined reference to `_exit'
/usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/lib/libc_nano.a(lib_a-sbrkr.o): in function `_sbrk_r':
/build/newlib-CVVEyx/newlib-3.3.0/build_nano/arm-none-eabi/newlib/libc/reent/../../../../../newlib/libc/reent/sbrkr.c:51: undefined reference to `_sbrk'
/usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/lib/libc_nano.a(lib_a-writer.o): in function `_write_r':
/build/newlib-CVVEyx/newlib-3.3.0/build_nano/arm-none-eabi/newlib/libc/reent/../../../../../newlib/libc/reent/writer.c:49: undefined reference to `_write'
/usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/lib/libc_nano.a(lib_a-closer.o): in function `_close_r':
/build/newlib-CVVEyx/newlib-3.3.0/build_nano/arm-none-eabi/newlib/libc/reent/../../../../../newlib/libc/reent/closer.c:47: undefined reference to `_close'
/usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/lib/libc_nano.a(lib_a-fstatr.o): in function `_fstat_r':
/build/newlib-CVVEyx/newlib-3.3.0/build_nano/arm-none-eabi/newlib/libc/reent/../../../../../newlib/libc/reent/fstatr.c:55: undefined reference to `_fstat'
/usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/lib/libc_nano.a(lib_a-isattyr.o): in function `_isatty_r':
/build/newlib-CVVEyx/newlib-3.3.0/build_nano/arm-none-eabi/newlib/libc/reent/../../../../../newlib/libc/reent/isattyr.c:52: undefined reference to `_isatty'
/usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/lib/libc_nano.a(lib_a-lseekr.o): in function `_lseek_r':
/build/newlib-CVVEyx/newlib-3.3.0/build_nano/arm-none-eabi/newlib/libc/reent/../../../../../newlib/libc/reent/lseekr.c:49: undefined reference to `_lseek'
/usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/lib/libc_nano.a(lib_a-readr.o): in function `_read_r':
/build/newlib-CVVEyx/newlib-3.3.0/build_nano/arm-none-eabi/newlib/libc/reent/../../../../../newlib/libc/reent/readr.c:49: undefined reference to `_read'
collect2: error: ld returned 1 exit status
piotr@PiotrLaptop02:~$ arm-none-eabi-gcc --specs=nano.specs --specs=nosys.specs main.c
piotr@PiotrLaptop02:~$

正如你所看到的,没有nosys,它不会链接。

相关问题