I’ve wrote a function that writes file-info into another file (in bin-format).
I’ve built it for WINDOWS executable, in two different environments:
eclipse, using mingw gcc:
GCC: (MinGW.org GCC-6.3.0-1) 6.3.0
linux, using cross-compiler (x86_64-w64-mingw32-gcc-win32):
GCC: (GNU) 10-win32 20220113
The file info is a packed struct, sized 128bytes, as follows:
#define STR_SIZE 32
typedef char string_t[STR_SIZE];
typedef union
{
struct
{
uint32_t a : 15;
uint32_t b : 1;
uint32_t c : 8;
uint32_t d : 8;
} __attribute__((packed)) fields;
uint32_t raw;
} general_t;
typedef struct
{
uint8_t hour;
uint8_t minutes;
uint8_t day;
uint8_t month;
uint16_t year;
} __attribute__((packed)) full_date_t;
typedef struct
{
general_t general;
uint32_t size;
} __attribute__((packed)) info_t;
typedef struct
{ /* starting from offset 4 */
full_date_t date; /* 6 bytes - offset 4: 9 */
string_t my_str; /* 32 bytes - offset 10:41 */
info_t v1; /* 8 bytes - offset 42:49 */
info_t v2; /* 8 bytes - offset 50:57 */
info_t v3; /* 8 bytes - offset 58:65 */
info_t v4; /* 8 bytes - offset 66:73 */
info_t v5; /* 8 bytes - offset 74:81 */
uint32_t crc; /* 4 bytes - offset 82:85 */
} __attribute__((packed)) fields_t;
typedef union
{
struct
{
uint32_t crc1;
fields_t fields;
uint8_t reserved[TOTAL_SIZE - sizeof(fields_t) - sizeof(uint32_t)];
} __attribute__((packed)) fields;
uint8_t raw[TOTAL_SIZE];
} full_info_t;
After building the code, and running it to build the info-file, I get different results in the bin file (besides the date – I hardcoded it all to 0x12345678).
the last CRC field, inside the ‘fields_t’ type, is located differently:
on the left you can see the linux built result, and on the right the windows built result (both built for exe executable in windows).
The correct offset of the CRC, if the linux built executable, while the windows built adds 2 bytes of padding.
What can cause the difference?