I am building FreeRTOSv202210.01-LTS Plus TCP for the SAME70. The code builds (in microchip studio using GCC) and I have many features up and running, but the code base has thousands of warnings. Most of the warnings come from the inclusion of pack_struct_end.h from portable/Compiler/GCC.
Warning packed attribute causes inefficient alignment for 'xxxx' [-Wpacked]
The file contains no code except for __attribute__( ( packed ) );, and it is included after the definition of every struct in the library.
I want to eliminate these warnings, but I don’t want to just silence them without verifying that there are no performance issues caused by misalignment of objects. For example, I want a network header struct to be packed so that it is correctly formatted, but I want the beginning of the struct to be word-aligned so that I don’t get any performance issues.
I tried __attribute__((packed, aligned(4))) in pack_struct_end.h but this did not help.
The pack_struct_start.h and pack_struct_end.h are used before and after structure definitions that define network packets where the compiler shouldn’t add any padding between the struct feilds, so that packets can be read and transmitted exactly as per the standard packet definitions.
The definition of pack_struct_start.h and pack_struct_end.h in portable/Compiler/GCC directory has been tested on GCC compilers without similar warnings as you listed.
I tried __attribute__((packed, aligned(4))) in pack_struct_end.h but this did not help.
The definition in portable/Compiler/GCC/pack_struct_end.h shoudn’t be changed to __attribute__((packed, aligned(4))) as it insists the compiler to use 4 bytes alignment and adds erroneous padding in between the fields of network packets.
I didn’t intend to have __attribute__((packed, aligned(4))) as a solution, I wanted to test if word-aligning the structs would affect the warnings, which it doesn’t.
-Wpacked warns when the packed attribute has no effect on struct layout. But this will cause warning to be emitted on fields in the packed structure that are already aligned by default as well on arm-none-eabi-gcc [(Atmel build: 508) 6.3.1 20170620 (release) [ARM/embedded-6-branch revision 249437]].
will emit the warnings for the feilds ch1 and ch2 as they are already aligned, but not for ch3 as padding will be added before ch3 if the struct was not packed. [./arm-none-eabi/bin/arm-none-eabi-gcc test.c -c -Wpacked]
Can you check the compilation after removing -Wpacked?