public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/110044] New: #pragma pack(push, 1) may not force packing, while __attribute__((packed, aligned(1))) works
@ 2023-05-30 21:15 vital.had at gmail dot com
  2023-05-30 22:14 ` [Bug target/110044] " pinskia at gcc dot gnu.org
                   ` (14 more replies)
  0 siblings, 15 replies; 16+ messages in thread
From: vital.had at gmail dot com @ 2023-05-30 21:15 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110044

            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); seems 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 <iostream>
#include <stdint.h>

#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

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2023-06-09 22:56 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-30 21:15 [Bug target/110044] New: #pragma pack(push, 1) may not force packing, while __attribute__((packed, aligned(1))) works vital.had at gmail dot com
2023-05-30 22:14 ` [Bug target/110044] " pinskia at gcc dot gnu.org
2023-05-31  6:04 ` egallager at gcc dot gnu.org
2023-05-31  6:38 ` vital.had at gmail dot com
2023-05-31  8:22 ` iains at gcc dot gnu.org
2023-05-31  8:24 ` iains at gcc dot gnu.org
2023-05-31  8:34 ` [Bug target/110044] [10, 11, 12, 13, 14 Regression] " iains at gcc dot gnu.org
2023-05-31 13:34 ` iains at gcc dot gnu.org
2023-06-01  3:38 ` vital.had at gmail dot com
2023-06-02 19:04 ` [Bug target/110044] [10/11/12/13/14 " cvs-commit at gcc dot gnu.org
2023-06-09  8:39 ` [Bug target/110044] [10/11/12/13 " cvs-commit at gcc dot gnu.org
2023-06-09  8:39 ` cvs-commit at gcc dot gnu.org
2023-06-09  8:41 ` cvs-commit at gcc dot gnu.org
2023-06-09  8:41 ` cvs-commit at gcc dot gnu.org
2023-06-09  8:49 ` iains at gcc dot gnu.org
2023-06-09 22:56 ` vital.had at gmail dot com

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).