如果指定了-flto(链接时间优化)选项,则GCC 8.0 for ARM链接将失败

时间:2019-03-13 19:53:19

标签: gcc cortex-m

我刚刚将我的gcc-arm-none-eabi从7.3.1(2018 q2)升级到8.2.1(2018 q4)。链接时发生错误。

编译命令是

arm-none-eabi-gcc -c -mcpu=cortex-m23 -mthumb   -Wall -Wextra -DARM_MATH_ARMV8MBL -D_DEBUG -Iinc1/ -Iinc2/ -Iinc3/ -fdata-sections -ffunction-sections -g3 -Os -flto -Wno-unused-parameter obj1.c -o obj1.o

链接命令是

arm-none-eabi-gcc  -mcpu=cortex-m23 -mthumb   --specs=nano.specs --specs=nosys.specs -Tlink_script.ld  -lc -lm -Wl,-Map=output.map,--cref -Wl,--gc-sections -g3 -Os -flto obj1.o obj2.o obj3.o -o output.elf

这些命令在7.3.1下可以很好地工作。但是对于8.2.1,链接时会出现以下错误:

../../../arm-none-eabi/bin/ld.exe: D:\cygwin64\tmp\cccsjco0debugobjtem: invalid string offset 131328 >= 22975072851460752 for section `(null)'
d:/gcc-arm-none-eabi-8.2.1/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld.exe: D:\cygwin64\tmp\cccsjco0debugobjtem: invalid string offset 145152 >= 22975072851460752 for section `(null)'
d:/gcc-arm-none-eabi-8.2.1/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld.exe: D:\cygwin64\tmp\cccsjco0debugobjtem: invalid string offset 145152 >= 22975072851460752 for section `(null)'
d:/gcc-arm-none-eabi-8.2.1/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld.exe: D:\cygwin64\tmp\cccsjco0debugobjtem: invalid string offset 40173580 >= 22975072851460752 for section `(null)'
d:/gcc-arm-none-eabi-8.2.1/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld.exe: D:\cygwin64\tmp\cccsjco0debugobjtem: invalid string offset 41287693 >= 22975072851460752 for section `(null)'
d:/gcc-arm-none-eabi-8.2.1/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld.exe: D:\cygwin64\tmp\cccsjco0debugobjtem: invalid string offset 41287680 >= 22975072851460752 for section `(null)'
d:/gcc-arm-none-eabi-8.2.1/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld.exe: warning: D:\cygwin64\tmp\ccfrv4PTdebugobjtem has a corrupt section with a size (a0d90) larger than the file size
d:/gcc-arm-none-eabi-8.2.1/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld.exe: warning: D:\cygwin64\tmp\ccfrv4PTdebugobjtem has a corrupt section with a size (a0d68) larger than the file size
d:/gcc-arm-none-eabi-8.2.1/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld.exe: warning: D:\cygwin64\tmp\ccfrv4PTdebugobjtem has a corrupt section with a size (a0d90) larger than the file size
d:/gcc-arm-none-eabi-8.2.1/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld.exe: warning: D:\cygwin64\tmp\ccfrv4PTdebugobjtem has a corrupt section with a size (a0d68) larger than the file size
d:/gcc-arm-none-eabi-8.2.1/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld.exe: warning: D:\cygwin64\tmp\ccfrv4PTdebugobjtem has a corrupt section with a size (a0d90) larger than the file size
d:/gcc-arm-none-eabi-8.2.1/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld.exe: warning: D:\cygwin64\tmp\ccfrv4PTdebugobjtem has a corrupt section with a size (a0d68) larger than the file size
d:/gcc-arm-none-eabi-8.2.1/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld.exe: warning: D:\cygwin64\tmp\ccfrv4PTdebugobjtem has a corrupt section with a size (a0d90) larger than the file size
d:/gcc-arm-none-eabi-8.2.1/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld.exe: warning: D:\cygwin64\tmp\ccfrv4PTdebugobjtem has a corrupt section with a size (a0d68) larger than the file size
d:/gcc-arm-none-eabi-8.2.1/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld.exe: warning: D:\cygwin64\tmp\ccfrv4PTdebugobjtem has a corrupt section with a size (a0d90) larger than the file size
d:/gcc-arm-none-eabi-8.2.1/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld.exe: warning: D:\cygwin64\tmp\ccfrv4PTdebugobjtem has a corrupt section with a size (a0d68) larger than the file size
d:/gcc-arm-none-eabi-8.2.1/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld.exe: warning: D:\cygwin64\tmp\ccfrv4PTdebugobjtem has a corrupt section with a size (a0d90) larger than the file size
d:/gcc-arm-none-eabi-8.2.1/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld.exe: warning: D:\cygwin64\tmp\ccfrv4PTdebugobjtem has a corrupt section with a size (a0d68) larger than the file size
D:\cygwin64\tmp\ccfrv4PTdebugobjtem: file not recognized: file format not recognized

我尝试删除“ -flto”,它按预期工作。此外,在https://gcc.gnu.org/gcc-8/changes.html中,我发现GCC 8的主要变化之一是“链接时优化改进”。因此很有可能是链接时间优化的问题。

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

在搜索了不同的关键字之后,我在https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89183中找到了答案。这是一个已知的错误,已在gcc 8.3中修复。