Bug 61813 - __attribute__((__packed__)) does not pack struct containing uint16_t with uint32_t
Summary: __attribute__((__packed__)) does not pack struct containing uint16_t with uin...
Status: RESOLVED DUPLICATE of bug 52991
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.8.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: ABI, wrong-code
Depends on:
Blocks:
 
Reported: 2014-07-15 15:25 UTC by Szikra
Modified: 2022-01-10 08:16 UTC (History)
0 users

See Also:
Host:
Target: x86_64-w64-mingw32
Build:
Known to work: 10.1.0, 8.1.0, 8.5.0
Known to fail: 7.5.0
Last reconfirmed:


Attachments
preprocessed bugreport_packed.c (5.34 KB, text/plain)
2014-07-15 15:25 UTC, Szikra
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Szikra 2014-07-15 15:25:16 UTC
Created attachment 33125 [details]
preprocessed bugreport_packed.c

Test case:
typedef struct __attribute__((__packed__)) {
    uint16_t a;		///  2
    uint32_t b;     /// +4
    uint32_t c[8];  /// +4*8 = 38
} foo_t;

but the size of foo_t is 40 (instead of the 38 which it should be). (It does not matter where I put the packed attribute.)


I'm using the latest released mingw to date (4.8.1 rev 5).
I'm compiling on Windows 7 x64 (with mingw).
GCC config:
Target: x86_64-w64-mingw32
Configured with: ../../../src/gcc-4.8.1/configure --host=x86_64-w64-mingw32 --build=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --prefix=/mingw64 --with-sysroot=/tmp/x64-481-win32-seh-r5/mingw64 --enable-shared --enable-static --disable-multilib --enable-languages=ada,c,c++,fortran,objc,obj-c++,lto --enable-libstdcxx-time=yes --enable-threads=win32 --enable-libgomp --enable-lto --enable-graphite --enable-checking=release --enable-fully-dynamic-string --enable-version-specific-runtime-libs --disable-isl-version-check --disable-cloog-version-check --disable-libstdcxx-pch --disable-libstdcxx-debug --enable-bootstrap --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-gnu-as --with-gnu-ld --with-arch=nocona --with-tune=core2 --with-libiconv --with-system-zlib --with-gmp=/tmp/mingw-prereq/x86_64-w64-mingw32-static --with-mpfr=/tmp/mingw-prereq/x86_64-w64-mingw32-static --with-mpc=/tmp/mingw-prereq/x86_64-w64-mingw32-static --with-isl=/tmp/mingw-prereq/x86_64-w64-mingw32-static --with-cloog=/tmp/mingw-prereq/x86_64-w64-mingw32-static --enable-cloog-backend=isl --with-pkgversion='rev5, Built by MinGW-W64 project' --with-bugurl=http://sourceforge.net/projects/mingw-w64 CFLAGS='-O2 -pipe -I/tmp/x64-481-win32-seh-r5/libs/include -I/tmp/mingw-prereq/x64-zlib/include -I/tmp/mingw-prereq/x86_64-w64-mingw32-static/include' CXXFLAGS='-O2 -pipe -I/tmp/x64-481-win32-seh-r5/libs/include -I/tmp/mingw-prereq/x64-zlib/include -I/tmp/mingw-prereq/x86_64-w64-mingw32-static/include' CPPFLAGS= LDFLAGS='-pipe -L/tmp/x64-481-win32-seh-r5/libs/lib -L/tmp/mingw-prereq/x64-zlib/lib -L/tmp/mingw-prereq/x86_64-w64-mingw32-static/lib -L/tmp/x64-481-win32-seh-r5/mingw64/opt/lib '
Thread model: win32
gcc version 4.8.1 (rev5, Built by MinGW-W64 project) 

command line 
gcc bugreport_packed.c
or
gcc -v -save-temps  -Wall -Wextra bugreport_packed.c

complete comiler output:
Using built-in specs.
COLLECT_GCC=C:\MinGW\x64-4.8.1-win32-seh-rev5\mingw64\bin\gcc
COLLECT_LTO_WRAPPER=c:/mingw/x64-4.8.1-win32-seh-rev5/mingw64/bin/../libexec/gcc/x86_64-w64-mingw32/4.8.1/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../../../src/gcc-4.8.1/configure --host=x86_64-w64-mingw32 --build=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --prefix=/mingw64 --with-sysroot=/tmp/x64-481-win32-seh-r5/mingw64 --enable-shared --enable-static --disable-multilib --enable-languages=ada,c,c++,fortran,objc,obj-c++,lto --enable-libstdcxx-time=yes --enable-threads=win32 --enable-libgomp --enable-lto --enable-graphite --enable-checking=release --enable-fully-dynamic-string --enable-version-specific-runtime-libs --disable-isl-version-check --disable-cloog-version-check --disable-libstdcxx-pch --disable-libstdcxx-debug --enable-bootstrap --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-gnu-as --with-gnu-ld --with-arch=nocona --with-tune=core2 --with-libiconv --with-system-zlib --with-gmp=/tmp/mingw-prereq/x86_64-w64-mingw32-static --with-mpfr=/tmp/mingw-prereq/x86_64-w64-mingw32-static --with-mpc=/tmp/mingw-prereq/x86_64-w64-mingw32-static --with-isl=/tmp/mingw-prereq/x86_64-w64-mingw32-static --with-cloog=/tmp/mingw-prereq/x86_64-w64-mingw32-static --enable-cloog-backend=isl --with-pkgversion='rev5, Built by MinGW-W64 project' --with-bugurl=http://sourceforge.net/projects/mingw-w64 CFLAGS='-O2 -pipe -I/tmp/x64-481-win32-seh-r5/libs/include -I/tmp/mingw-prereq/x64-zlib/include -I/tmp/mingw-prereq/x86_64-w64-mingw32-static/include' CXXFLAGS='-O2 -pipe -I/tmp/x64-481-win32-seh-r5/libs/include -I/tmp/mingw-prereq/x64-zlib/include -I/tmp/mingw-prereq/x86_64-w64-mingw32-static/include' CPPFLAGS= LDFLAGS='-pipe -L/tmp/x64-481-win32-seh-r5/libs/lib -L/tmp/mingw-prereq/x64-zlib/lib -L/tmp/mingw-prereq/x86_64-w64-mingw32-static/lib -L/tmp/x64-481-win32-seh-r5/mingw64/opt/lib '
Thread model: win32
gcc version 4.8.1 (rev5, Built by MinGW-W64 project) 
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-Wextra' '-mtune=core2' '-march=nocona'
 c:/mingw/x64-4.8.1-win32-seh-rev5/mingw64/bin/../libexec/gcc/x86_64-w64-mingw32/4.8.1/cc1.exe -E -quiet -v -iprefix c:\mingw\x64-4.8.1-win32-seh-rev5\mingw64\bin\../lib/gcc/x86_64-w64-mingw32/4.8.1/ -U_REENTRANT bugreport_packed.c -mtune=core2 -march=nocona -Wall -Wextra -fpch-preprocess -o bugreport_packed.i
ignoring duplicate directory "c:/mingw/x64-4.8.1-win32-seh-rev5/mingw64/lib/gcc/../../lib/gcc/x86_64-w64-mingw32/4.8.1/include"
ignoring nonexistent directory "C:/Temp/msys64/tmp/x64-481-win32-seh-r5/mingw64C:/Temp/msys64/mingw64/lib/gcc/x86_64-w64-mingw32/4.8.1/../../../../include"
ignoring duplicate directory "c:/mingw/x64-4.8.1-win32-seh-rev5/mingw64/lib/gcc/../../lib/gcc/x86_64-w64-mingw32/4.8.1/include-fixed"
ignoring duplicate directory "c:/mingw/x64-4.8.1-win32-seh-rev5/mingw64/lib/gcc/../../lib/gcc/x86_64-w64-mingw32/4.8.1/../../../../x86_64-w64-mingw32/include"
ignoring nonexistent directory "C:/Temp/msys64/tmp/x64-481-win32-seh-r5/mingw64/mingw/include"
#include "..." search starts here:
#include <...> search starts here:
 c:\mingw\x64-4.8.1-win32-seh-rev5\mingw64\bin\../lib/gcc/x86_64-w64-mingw32/4.8.1/include
 c:\mingw\x64-4.8.1-win32-seh-rev5\mingw64\bin\../lib/gcc/x86_64-w64-mingw32/4.8.1/include-fixed
 c:\mingw\x64-4.8.1-win32-seh-rev5\mingw64\bin\../lib/gcc/x86_64-w64-mingw32/4.8.1/../../../../x86_64-w64-mingw32/include
End of search list.
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-Wextra' '-mtune=core2' '-march=nocona'
 c:/mingw/x64-4.8.1-win32-seh-rev5/mingw64/bin/../libexec/gcc/x86_64-w64-mingw32/4.8.1/cc1.exe -fpreprocessed bugreport_packed.i -quiet -dumpbase bugreport_packed.c -mtune=core2 -march=nocona -auxbase bugreport_packed -Wall -Wextra -version -o bugreport_packed.s
GNU C (rev5, Built by MinGW-W64 project) version 4.8.1 (x86_64-w64-mingw32)
	compiled by GNU C version 4.8.1, GMP version 5.1.2, MPFR version 3.1.2, MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C (rev5, Built by MinGW-W64 project) version 4.8.1 (x86_64-w64-mingw32)
	compiled by GNU C version 4.8.1, GMP version 5.1.2, MPFR version 3.1.2, MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: b31b8d99d71c616db8d6053c2fc710b4
bugreport_packed.c: In function 'main':
bugreport_packed.c:16:5: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long unsigned int' [-Wformat=]
     printf("Packet Size: %d\r\n", sizeof(foo_t));
     ^
bugreport_packed.c:12:14: warning: unused parameter 'argc' [-Wunused-parameter]
 int main(int argc, char **argv)
              ^
bugreport_packed.c:12:27: warning: unused parameter 'argv' [-Wunused-parameter]
 int main(int argc, char **argv)
                           ^
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-Wextra' '-mtune=core2' '-march=nocona'
 c:/mingw/x64-4.8.1-win32-seh-rev5/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.8.1/../../../../x86_64-w64-mingw32/bin/as.exe -v -o bugreport_packed.o bugreport_packed.s
GNU assembler version 2.23.2 (x86_64-w64-mingw32) using BFD version (GNU Binutils) 2.23.2
COMPILER_PATH=c:/mingw/x64-4.8.1-win32-seh-rev5/mingw64/bin/../libexec/gcc/x86_64-w64-mingw32/4.8.1/;c:/mingw/x64-4.8.1-win32-seh-rev5/mingw64/bin/../libexec/gcc/;c:/mingw/x64-4.8.1-win32-seh-rev5/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.8.1/../../../../x86_64-w64-mingw32/bin/
LIBRARY_PATH=c:/mingw/x64-4.8.1-win32-seh-rev5/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.8.1/;c:/mingw/x64-4.8.1-win32-seh-rev5/mingw64/bin/../lib/gcc/;c:/mingw/x64-4.8.1-win32-seh-rev5/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.8.1/../../../../x86_64-w64-mingw32/lib/../lib/;c:/mingw/x64-4.8.1-win32-seh-rev5/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.8.1/../../../../lib/;c:/mingw/x64-4.8.1-win32-seh-rev5/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.8.1/../../../../x86_64-w64-mingw32/lib/;c:/mingw/x64-4.8.1-win32-seh-rev5/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.8.1/../../../
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-Wextra' '-mtune=core2' '-march=nocona'
 c:/mingw/x64-4.8.1-win32-seh-rev5/mingw64/bin/../libexec/gcc/x86_64-w64-mingw32/4.8.1/collect2.exe --sysroot=C:/Temp/msys64/tmp/x64-481-win32-seh-r5/mingw64 -m i386pep -Bdynamic c:/mingw/x64-4.8.1-win32-seh-rev5/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.8.1/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o c:/mingw/x64-4.8.1-win32-seh-rev5/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.8.1/../../../../x86_64-w64-mingw32/lib/../lib/crtbegin.o -Lc:/mingw/x64-4.8.1-win32-seh-rev5/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.8.1 -Lc:/mingw/x64-4.8.1-win32-seh-rev5/mingw64/bin/../lib/gcc -Lc:/mingw/x64-4.8.1-win32-seh-rev5/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.8.1/../../../../x86_64-w64-mingw32/lib/../lib -Lc:/mingw/x64-4.8.1-win32-seh-rev5/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.8.1/../../../../lib -Lc:/mingw/x64-4.8.1-win32-seh-rev5/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.8.1/../../../../x86_64-w64-mingw32/lib -Lc:/mingw/x64-4.8.1-win32-seh-rev5/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.8.1/../../.. bugreport_packed.o -lmingw32 -lgcc -lgcc_eh -lmoldname -lmingwex -lmsvcrt -ladvapi32 -lshell32 -luser32 -lkernel32 -liconv -lmingw32 -lgcc -lgcc_eh -lmoldname -lmingwex -lmsvcrt c:/mingw/x64-4.8.1-win32-seh-rev5/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.8.1/../../../../x86_64-w64-mingw32/lib/../lib/crtend.o


Notes:
The same bug is produced with compiler version 4.7.3 (gcc version 4.7.3 (release with patches / build 20130526 by strawberryperl.com) )
Comment 1 Stephen Kitt 2015-08-26 20:44:02 UTC
This appears to be a duplicate of https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54589 (__attribute__((packed)) doesn't work on mingw32 targets since ms-bitfields became the default).
Comment 2 Andrew Pinski 2022-01-10 08:16:45 UTC
Dup of bug 52991.

*** This bug has been marked as a duplicate of bug 52991 ***