From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by sourceware.org (Postfix) with ESMTPS id 72BF23858C60 for ; Tue, 26 Oct 2021 23:40:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 72BF23858C60 Received: by mail-wm1-x32f.google.com with SMTP id v127so914113wme.5 for ; Tue, 26 Oct 2021 16:40:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=H1wzIGNosXcoJksFErs7jj2lQPFQr74Ze1mburtSnIs=; b=hu61M4iwy1xci3S81qcoTxLBmq/DXI6IuLNVt6y6fQEvUKGcs4vzi01BS4piGxuVG9 Mw3y18duQWk7kMA7/Cdpy5yQbq6Rxn6q9/RNezubcn1hQ+Jq1/MEVIP64FRfgGQxthWL 6auQdVklCHosOxpx0362HfR6dDZdvIzvHUPjULtz18AT1TsUqSbRKbZWudfvsgHcC/pv z3GtYm6eGIute0tqtydQvQL30g6E5Z+vKU2M3BblSxAafhAjtxucyAe8RaHvupGYd3r4 rGsORHuh5b1dpi11E40wnRyhl2k9Ho2Pq24bay5/xlSR+6PTu/IF7Zmx9b5kz51jrtlN lMCQ== X-Gm-Message-State: AOAM530kObkBNh2mX3cbRAckTliA25d4VPjCfqIfiz4R7oDZ/6onAuSq SkxgGIrp1MG9/0v9oiog4BYf/4ueFOLRWkDGSMM= X-Google-Smtp-Source: ABdhPJybWL33H6C95H7nhvM1BVlUmBtIW6mVNutGrrV3ZxXujG8At8c6mWbbev0K9820xwiAARiBDCfqIwhoqLTI3ro= X-Received: by 2002:a1c:7201:: with SMTP id n1mr1913350wmc.176.1635291603416; Tue, 26 Oct 2021 16:40:03 -0700 (PDT) MIME-Version: 1.0 References: <1635290628.10041.1.camel@gnu.org> In-Reply-To: <1635290628.10041.1.camel@gnu.org> From: Jonathan Wakely Date: Wed, 27 Oct 2021 00:39:52 +0100 Message-ID: Subject: Re: which gcc options can control layout of bit fields To: Andrew Makhorin Cc: gcc-help X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, HTML_MESSAGE, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: gcc-help@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-help mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Oct 2021 23:40:05 -0000 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 >