This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Alignment issue between debug and release builds on windows

Hello,

I am storing a structure in the flash of my cortex M0+ MCU.

I have been trying this with gcc 9-2020-q2-update and 8-2019-q3-update (8.3.1) on Windows and the debug build linking fails. Building and linking on linux using gcc 8-2019-q3-update everything works fine.

Linker script:

MEMORY
{
  boot      (rx)  : ORIGIN = 0x00000000, LENGTH = 0x00001EEA
  blHeader  (rx)  : ORIGIN = 0x00001EEA, LENGTH = 0x00000016
  blBootInfo (rx) : ORIGIN = 0x00001F00, LENGTH = 0x00000100

}

Stored structure size 22 in the blHeader section

struct __attribute__((packed, aligned(1))) BlHeader 
{
    uint32_t u32_headerId;        /**< identifier (4 bytes) - "BOOT" */
    uint16_t u16_versionMajor;    /**< Product version major */
    uint16_t u16_versionMinor;    /**< Product version minor */
    uint16_t u16_versionPatch;    /**< Product version patch */
    uint32_t u32_buildType;        /**< Build type DBG or REL*/
    uint8_t  u8_sha[8];    /**< Build commit short sha */
};

It seems that the aligned(1) attribute is not taken into account in the windows debug build, the section size ends up 24  instead of 22 (so the blHeader section overflows because of those 2 bytes alignment) . I suppose that some flag in the release build fixes that (I use -Os). Though I know that there is no difference in the optimization flags between linux and windows gcc 8.3.1.

So I am a bit stuck by this different behavior and I am not sure where to report it.