iuradz
iuradz

Reputation: 1168

GCC 8.0 for ARM link failed if -flto(Link time optimization) option is given

I just upgrated my gcc-arm-none-eabi from 7.3.1(2018 q2) to 8.2.1(2018 q4). An error occured when linking.

The command for compiling is

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

The command for linking is

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

These commands work well with 7.3.1. But with 8.2.1, following error are raised when linking:

../../../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

I tried removing "-flto" and it work as expected. Further more, in https://gcc.gnu.org/gcc-8/changes.html , I found one of the major changes of GCC 8 is "Link-time optimization improvements". So it's very likely to be the problem of Link-time optimization.

How can I solve this problem?

Upvotes: 1

Views: 680

Answers (1)

iuradz
iuradz

Reputation: 1168

After googling with different keywords, I found the answer in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89183 . It's a known bug and has been fixed in gcc 8.3 .

Upvotes: 2

Related Questions