GCC: KDS toolchain segfaults when dividing _Accum types

cancel
Showing results for 
Search instead for 
Did you mean: 

GCC: KDS toolchain segfaults when dividing _Accum types

232 Views
Contributor I

I use the gcc's fixed point extensions, which have been present in the gcc for Cortex-M since 2011.

 

The toolchain which is included in the current version of KDS (4.8.4 20140725 (release)) gives me a segmentation fault during compilation.

 

The segmentation fault happens when a long _Accum variable retVal is divided by an element of a referenced struct:

retVal = retVal / filter->numberOfElements;

 

Building file: ../Sources/drivers/filters.c

Invoking: Cross ARM C Compiler

arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -O3 -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -DKINETIS -DARM_MATH_CM4   -I"/opt/toolchain/CMSIS/CMSIS/Include" -I"/home/dominik/workspace.kds/test/Static_Code/PDD" -I"/home/dominik/workspace.kds/test/Static_Code/IO_Map" -I"/home/dominik/workspace.kds/test/Sources" -I"/home/dominik/workspace.kds/test/Generated_Code" -std=gnu99 -MMD -MP -MF"Sources/drivers/filters.d" -MT"Sources/drivers/filters.o" -c -o "Sources/drivers/filters.o" "../Sources/drivers/filters.c"

../Sources/drivers/filters.c: In function 'filters_updateMovingAverage':

../Sources/drivers/filters.c:172:1: internal compiler error: Segmentation fault

 

 

The current release of the toolchain (5.3.1 20160307 (release)) compiles without errors and works perfectly, hence it is not a big problem. It's still weird, though.

Compilation works flawlessly if I comment out the mentioned line.

Labels (1)
0 Kudos
3 Replies

6 Views
Contributor I

Hi Carlos!

Of course.

I attached a c file, to be compiled with the following command:

/opt/Freescale/KDS_3.0.0/toolchain/bin/arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -O3 -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -D__FPU_PRESENT -DARM_MATH_CM4 -MMD -MP -std=gnu99 -c -o fixpoint.o fixpoint.c

My environment:

Ubuntu 16.04

KDS 3.1, updated from 3.0

Trying to compile the attached c file with the given command throws the following error message:

fixpoint.c: In function 'filters_updateMovingAverageAngularFlip':

fixpoint.c:67:1: internal compiler error: Segmentation fault

}

^

Please submit a full bug report,

with preprocessed source if appropriate.

See <http://gcc.gnu.org/bugs.html> for instructions.

0 Kudos

6 Views
NXP Employee
NXP Employee

Hi Dominikus,

Thanks for the information.

It seems like the problem is caused by the optimizations, was the same optimization level (-O3) used when you tested the code in the toolchain 5.3.1? It seems like the retVal variable is being optimized causing the segmentation fault, this error does not happen if using the optimization level -O0. Please try using the volatile qualifier for this variable to prevent the compiler from optimizing it.

volatile long _Accum retVal = 0.0;

Hope it helps!

Best Regards,

Carlos Mendoza

Technical Support Engineer

0 Kudos

6 Views
NXP Employee
NXP Employee

Hi Dominikus,

Could you share a project where we can reproduce this error?

Thanks in advance!

Best Regards,

Carlos Mendoza

Technical Support Engineer

0 Kudos