Bugzilla will be upgraded to version 5.0. The upgrade date is tentatively scheduled for 2 December 2018, pending final testing and feedback.
Bug 51995 - layout for long long bitfield wrong
layout for long long bitfield wrong
Product: Red Hat Linux
Classification: Retired
Component: gcc (Show other bugs)
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
David Lawrence
Depends On:
  Show dependency treegraph
Reported: 2001-08-17 17:37 EDT by Arch D. Robison
Modified: 2007-04-18 12:36 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2002-12-15 12:34:00 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Arch D. Robison 2001-08-17 17:37:42 EDT
From Bugzilla Helper:
User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)

Description of problem:
The gcc with Linux 7.1 lays out long long bitfields in a way that is both 
incompatible with Linux 6.2, and just plain irrational.  Surely, changing 
a field of type T to a bitfield of type T should not make a structure 
larger.  A struct containing a char and a long long bitfield should occupy 
12 bytes: 1 for the char, 3 for padding, and 8 for the long long.

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
1. Compile program as shown in "Additional Information".
2. Run program.

Actual Results:  sizeof(PlainField)=12
sizeof(BitField  )=16

Expected Results:  sizeof(PlainField)=12
sizeof(BitField  )=12

Additional info:

$ cat b.C
#include <stdio.h>

typedef long long T;

struct PlainField {
    char c;
    T field;

struct BitField {
    char c;
    T field: 61;

int main() {
    printf("sizeof(PlainField)=%d\n", sizeof(PlainField));
    printf("sizeof(BitField  )=%d\n", sizeof(BitField));
    return 0;
$ gcc -v b.C
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/2.96/specs
gcc version 2.96 20000731 (Red Hat Linux 7.1 2.96-81)
 /usr/lib/gcc-lib/i386-redhat-linux/2.96/cpp0 -lang-c++ -D__GNUG__=2 -
F__ -Dunix -Dlinux -D__ELF__ -D__unix__ -D__linux__ -D__unix -D__linux -
Asystem(posix) -Acpu(i386) -Amachine(i386) -Di386 -D__i386 -D__i386__ -
_i386__ b.C /usr/tmp/ccbx3Oxo.ii
GNU CPP version 2.96 20000731 (Red Hat Linux 7.1 2.96-81) (cpplib) (i386 
ignoring nonexistent directory "/usr/local/include"
ignoring nonexistent directory "/usr/i386-redhat-linux/include"
#include "..." search starts here:
#include <...> search starts here:
End of search list.
 /usr/lib/gcc-lib/i386-redhat-linux/2.96/cc1plus /usr/tmp/ccbx3Oxo.ii -
quiet -dumpbase b.C -version -o /usr/tmp/cckafkTF.s
GNU C++ version 2.96 20000731 (Red Hat Linux 7.1 2.96-81) (i386-redhat-
linux) compiled by GNU C version 2.96 20000731 (Red Hat Linux 7.1 2.96-81).
 as -V -Qy -o /usr/tmp/cc9K0tF0.o /usr/tmp/cckafkTF.s
GNU assembler version 2.10.91 (i386-redhat-linux) using BFD version
 /usr/lib/gcc-lib/i386-redhat-linux/2.96/collect2 -m elf_i386 -dynamic-
linker /lib/ld-linux.so.2 /usr/lib/gcc-lib/i386-redhat-
.o /usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../crti.o /usr/lib/gcc-
lib/i386-redhat-linux/2.96/crtbegin.o -L/usr/lib/gcc-lib/i386-redhat-
6 -L/usr/lib/gcc-lib/i386-redhat-linux/2.96/../../.. /usr/tmp/cc9K0tF0.o -
lgcc -lc -lgcc /usr/lib/gcc-lib/i386-redhat-
linux/2.96/crtend.o /usr/lib/gcc
$ a.out
sizeof(BitField  )=16
Comment 1 Alan Cox 2002-12-15 12:34:00 EST
gcc 3.2 sorted all this out

Note You need to log in before you can comment on or make changes to this bug.