Pour ce code :
struct S { unsigned char ch[2]; }; int main(void) { _Static_assert( sizeof(struct S) == 2, "size was not 2"); }
En utilisant GCC (différentes versions) pour ARM avec ABI apcs-gnu
(alias. OABI ou EABI version 0), l’assertion échoue. Il s’avère que la taille de la structure est 4
.
Je peux contourner ce __atsortingbute__((packed))
utilisant __atsortingbute__((packed))
; mais mes questions sont:
4
? Sur le site Web d’ARM, j’ai trouvé de la documentation pour aapcs
(EABI version 5) qui spécifie que cette structure a une taille de 2; mais je n’ai rien trouvé sur apcs-gnu
.
C’est une décision spécifique à GCC de concilier taille et performance. Il peut être remplacé avec -mstructure-size-boundary=8
.
Un extrait du code source :
/* Setting STRUCTURE_SIZE_BOUNDARY to 32 produces more efficient code, but the value set in previous versions of this toolchain was 8, which produces more compact structures. The command line option -mstructure_size_boundary= can be used to change this value. For compatibility with the ARM SDK however the value should be left at 32. ARM SDT Reference Manual (ARM DUI 0020D) page 2-20 says "Structures are aligned on word boundaries". The AAPCS specifies a value of 8. */ #define STRUCTURE_SIZE_BOUNDARY arm_structure_size_boundary