Structure structure in apcs-gnu ABI

For this code :

struct S {     unsigned char ch[2]; };

int main(void)
{
    _Static_assert( sizeof(struct S) == 2, "size was not 2");
}

using GCC (various versions) for ARM with ABI apcs-gnu(aka. OABI, or EABI version 0), I get the statement to fail. It turns out the size of the structure 4.

I can get around this using __attribute__((packed)); but my questions are:

  • What is the point of creating this structure size 4?
  • Is there any documentation that defines the location of structures in this ABI?

On the ARM website, I found documentation for aapcs(EABI version 5) that indicates that this structure is 2; but I couldn’t find anything about apcs-gnu.

+1
source share
1

. -mstructure-size-boundary=8.

:

/* 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=<n>
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
+2

Source: https://habr.com/ru/post/1681930/


All Articles