From: Jonathan Wakely <jwakely.gcc@gmail.com>
To: Andrew Makhorin <mao@gnu.org>
Cc: gcc-help <gcc-help@gcc.gnu.org>
Subject: Re: which gcc options can control layout of bit fields
Date: Wed, 27 Oct 2021 00:39:52 +0100 [thread overview]
Message-ID: <CAH6eHdQj4nob0bpzK136rXPjLSVvROStL2RXBBxOUZ6o=0FNiA@mail.gmail.com> (raw)
In-Reply-To: <1635290628.10041.1.camel@gnu.org>
On Wed, 27 Oct 2021, 00:24 Andrew Makhorin via Gcc-help, <
gcc-help@gcc.gnu.org> 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
>
prev parent reply other threads:[~2021-10-26 23:40 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-26 23:23 Andrew Makhorin
2021-10-26 23:39 ` Jonathan Wakely [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAH6eHdQj4nob0bpzK136rXPjLSVvROStL2RXBBxOUZ6o=0FNiA@mail.gmail.com' \
--to=jwakely.gcc@gmail.com \
--cc=gcc-help@gcc.gnu.org \
--cc=mao@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).