Re: which gcc options can control layout of bit fields

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 27 Oct 2021, 00:24 Andrew Makhorin via Gcc-help, <
gcc-help@xxxxxxxxxxx> wrote:

> Hi,
>
> Could anyone tell me which gcc options can control layout of bit
> fields?
>
> The problem I encountered is that gcc for Cygwin doesn't follow
> System V ABI for i386.



I think that's intentional. Have you tried -mabi=sysv ?

https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html


Namely, ABI says:
>
>    A bit-field must entirely reside in a storage unit appropriate for
>    its declared type. Thus a bit-field never crosses its unit boundary.
>
> But in the code generated by gcc under Cygwin bit fields are allocated
> contiguously and may cross the unit boundary. On the other hand, gcc
> under Linux follows the ABI conventions.
>
> Example:
>
> struct { int a; char b; int c:14, d:14; int e; }
>    s = {0xAAAAAAAA, 0xBB, 0xCCC, 0xDDD, 0xEEEEEEEE};
>
> static int *p = (int *)&s;
>
> int main(void)
> {
>       printf("0x%08X 0x%08X 0x%08X 0x%08X\n", p[0], p[1], p[2], p[3]);
>
>       return 0;
> }
>
> Under Cygwin s.d is splitted between p[1] and p[2]:
>
> 0xAAAAAAAA 0x774CCCBB 0x00000003 0xEEEEEEEE
>
> Under Linux all is okay:
>
> 0xAAAAAAAA 0x000CCCBB 0x00000DDD 0xEEEEEEEE
>
>
> Thank you,
>
> Andrew Makhorin
>



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux