FreeRTOS plus TCP GCC warning: [Wattributes] packed struct attribute

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.


Hi @mtut,

What exact compiler and version are you using?

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.

Hi @tony-josi-aws ,

I am using the following compiler version:
arm-none-eabi-gcc (Atmel build: 508) 6.3.1 20170620 (release) [ARM/embedded-6-branch revision 249437]

With the following options (includes omitted)

-x c -mthumb -D__SAME70Q21B__ -DDEBUG -DBOARD=SAME70_XPLAINED -DARM_MATH_CM7=true -Dprintf=iprintf -D__SAME70Q21B__ -Dscanf=iscanf <includes_omitted> -O0 -fdata-sections -ffunction-sections -mlong-calls -g3 -Wall -mcpu=cortex-m7 -c -pipe -fno-strict-aliasing -Wall -Wstrict-prototypes -Wmissing-prototypes -Werror-implicit-function-declaration -Wpointer-arith -std=gnu99 -ffunction-sections -fdata-sections -Wchar-subscripts -Wcomment -Wformat=2 -Wimplicit-int -Wmain -Wparentheses -Wsequence-point -Wreturn-type -Wswitch -Wtrigraphs -Wunused -Wuninitialized -Wunknown-pragmas -Wfloat-equal -Wundef -Wshadow -Wbad-function-cast -Wwrite-strings -Wsign-compare -Waggregate-return -Wmissing-declarations -Wformat -Wmissing-format-attribute -Wno-deprecated-declarations -Wpacked -Wredundant-decls -Wnested-externs -Wlong-long -Wunreachable-code -Wcast-align --param max-inline-insns-single=500 -mfloat-abi=softfp -mfpu=fpv5-sp-d16 -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)"

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.

Thank you!

Hi @mtut,

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

For example the below structure:

struct CHN_test 
    uint32_t ch1;
    uint16_t ch2;
    uint32_t ch3;
__attribute__( ( packed ) );

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?