Linker crash with fixed-point types and LTO

Asked by Andreas Fried on 2013-09-11

I would like to file the following bug, but have been told to ask here first:

When compiling a program that uses the fixed-point types (as defined in the Embedded C extension) with LTO, the linker segfaults. To reproduce, compile the following with "arm-none-eabi-gcc -flto fixedpoint.c":

/* File fixedpoint.c */
_Accum foo = 42.42k;

void main()
        _Accum x = foo;
/* EOF */

There are no further errors or warning messages. Note that there is a linker error message when compiling without -flto, namely that "_exit" is not found, but this is expected.

I have not rebuilt the toolchain from source.

Version information:
$ arm-none-eabi-gcc -v
Using built-in specs.
Target: arm-none-eabi
Configured with: /home/build/work/GCC-4-7-build/src/gcc/configure --target=arm-none-eabi --prefix=/home/build/work/GCC-4-7-build/install-native --libexecdir=/home/build/work/GCC-4-7-build/install-native/lib --infodir=/home/build/work/GCC-4-7-build/install-native/share/doc/gcc-arm-none-eabi/info --mandir=/home/build/work/GCC-4-7-build/install-native/share/doc/gcc-arm-none-eabi/man --htmldir=/home/build/work/GCC-4-7-build/install-native/share/doc/gcc-arm-none-eabi/html --pdfdir=/home/build/work/GCC-4-7-build/install-native/share/doc/gcc-arm-none-eabi/pdf --enable-languages=c,c++ --disable-decimal-float --disable-libffi --disable-libgomp --disable-libmudflap --disable-libquadmath --disable-libssp --disable-libstdcxx-pch --disable-nls --disable-shared --disable-threads --disable-tls --with-gnu-as --with-gnu-ld --with-newlib --with-headers=yes --with-python-dir=share/gcc-arm-none-eabi --with-sysroot=/home/build/work/GCC-4-7-build/install-native/arm-none-eabi --build=i686-linux-gnu --host=i686-linux-gnu --with-gmp=/home/build/work/GCC-4-7-build/build-native/host-libs/usr --with-mpfr=/home/build/work/GCC-4-7-build/build-native/host-libs/usr --with-mpc=/home/build/work/GCC-4-7-build/build-native/host-libs/usr --with-ppl=/home/build/work/GCC-4-7-build/build-native/host-libs/usr --with-cloog=/home/build/work/GCC-4-7-build/build-native/host-libs/usr --with-libelf=/home/build/work/GCC-4-7-build/build-native/host-libs/usr --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' --with-pkgversion='GNU Tools for ARM Embedded Processors' --with-multilib-list=armv6-m,armv7-m,armv7e-m,armv7-r
Thread model: single
gcc version 4.7.4 20130613 (release) [ARM/embedded-4_7-branch revision 200083] (GNU Tools for ARM Embedded Processors)

$ uname -a
Linux huluvu 3.10.10-1-ARCH #1 SMP PREEMPT Fri Aug 30 11:30:06 CEST 2013 x86_64 GNU/Linux

Question information

English Edit question
GNU Arm Embedded Toolchain Edit question
No assignee Edit question
Solved by:
Terry Guo
Last query:
Last reply:
Terry Guo (terry.guo) said : #1

Asking here first is a recommended way. Thank you for doing that.

I can reproduce the issue and am looking into it.

Best Terry Guo (terry.guo) said : #2

Issue is caused by gcc bug at and already fixed in 4.8 and trunk.

Here is a brief explanation:

Tree node for fixed constant has below field:
struct GTY(()) tree_fixed_cst {
  struct tree_typed typed;
  struct fixed_value * fixed_cst_ptr;

At LTO stage, a new tree node will be created for fixed constant. Right after the creation, the filed fixed_cst_ptr is initialized to zero. Then a struct fixed_value is built to represent the fixed constant. Then we reach offending code like:

*(fixed_cst_ptr) = fixed_value // just like *(0) = fixed_value.

A correct way is to allocate struct through malloc and then do a pointer assignment.

Andreas Fried (bugreports-s) said : #3

OK, I will wait for the release then. Thank you.