From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 43A4C3858C5E; Tue, 30 May 2023 21:15:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 43A4C3858C5E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1685481358; bh=LCYmRcTkVxZmQ+gGoQEVaZpqW55BJhonyc8CvzX3nUk=; h=From:To:Subject:Date:From; b=Rb5ilxodR6JCBONJWuoc2dIBEJkPIO53blMNT8PtcddOgjsqiEMkICxVq0tGcvL9e p6FXjaZBRCYb/IwmPAubQc5mjk4mzJ+JG0UFjZCYsYWXGT2CHpM8C7tcPfublEGSfo ghXNj0sMfe+DF5ho4fJM7ZYkvF0HIC+LbWj5sPzM= From: "vital.had at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/110044] New: #pragma pack(push, 1) may not force packing, while __attribute__((packed, aligned(1))) works Date: Tue, 30 May 2023 21:15:57 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 12.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: vital.had at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter cc target_milestone cf_gcctarget Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D110044 Bug ID: 110044 Summary: #pragma pack(push, 1) may not force packing, while __attribute__((packed, aligned(1))) works Product: gcc Version: 12.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: vital.had at gmail dot com CC: iains at gcc dot gnu.org Target Milestone: --- Target: powerpc-apple-darwin Problem: #pragma pack(push, 1) may not work correctly on ppc (32-bit); seem= s to be present across GCC versions, confirmed to affect gcc7, gcc11 and gcc12. Old Apple GCC 4.2 is not affected, at the same time. Test code: #include #include #pragma pack(push, 1) /* struct from OpenEXR; should be packed with the pragma directive */ typedef struct { uint32_t x_size; uint32_t y_size; uint8_t level_and_round; } exr_attr_tiledesc_t; /* same struct but reordered */ typedef struct { uint8_t level_and_round; uint32_t x_size; uint32_t y_size; } new1_exr_attr_tiledesc_t; /* same as first struct but with packed forced */ typedef struct { uint32_t x_size; uint32_t y_size; uint8_t level_and_round; } __attribute__((packed, aligned(1))) new2_exr_attr_tiledesc_t; #pragma pack(pop) int main() { std::cout << sizeof(exr_attr_tiledesc_t) << " " << sizeof(new1_exr_attr_tiledesc_t) << " " << sizeof(new2_exr_attr_tiledesc_t) << "\n"; return 0; } On Mac OS X Leopart (10.5 PowerPC): `g++-mp-7 main.cxx && ./a.out` gives: 12 9 9 `g++ main.cxx && ./a.out` gives: 9 9 9 `g++* -arch ppc64 && ./a.out` gives: 9 9 9 On Mac OS X Snow Leopard (10A190 PowerPC): `g++-mp-11 main.cxx && ./a.out` gives: 12 9 9 `g++-mp-12 main.cxx && ./a.out` gives: 12 9 9 `g++ main.cxx && ./a.out` gives: 9 9 9 where g++ stands for Xcode gcc-4.2. Discussion in: https://github.com/macports/macports-ports/pull/18872 Also see: https://trac.macports.org/ticket/63490=