如果给出 -flto(Link 时间优化) 选项,ARM link 的 GCC 8.0 失败
GCC 8.0 for ARM link failed if -flto(Link time optimization) option is given
我刚刚将我的 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 的主要变化之一是 "Link-time optimization improvements"。所以很有可能是Link-时间优化的问题
我该如何解决这个问题?
使用不同的关键字进行谷歌搜索后,我在 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89183 中找到了答案。这是一个已知错误,已在 gcc 8.3 中修复。
我刚刚将我的 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 的主要变化之一是 "Link-time optimization improvements"。所以很有可能是Link-时间优化的问题
我该如何解决这个问题?
使用不同的关键字进行谷歌搜索后,我在 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89183 中找到了答案。这是一个已知错误,已在 gcc 8.3 中修复。