public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c/4104: structure misalignment problem causing kernel failures
@ 2001-10-15  7:56 Paul Clements
  0 siblings, 0 replies; 4+ messages in thread
From: Paul Clements @ 2001-10-15  7:56 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR c/4104; it has been noted by GNATS.

From: Paul Clements <Paul.Clements@SteelEye.com>
To: rodrigc@gcc.gnu.org
Cc: gcc-bugs@gcc.gnu.org, gcc-prs@gcc.gnu.org, nobody@gcc.gnu.org
Subject: Re: c/4104: structure misalignment problem causing kernel failures
Date: Mon, 15 Oct 2001 09:29:06 -0400

 rodrigc@gcc.gnu.org wrote:
 > 
 > Synopsis: structure misalignment problem causing kernel failures
 > 
 > State-Changed-From-To: open->feedback
 > State-Changed-By: rodrigc
 > State-Changed-When: Sat Oct 13 20:52:01 2001
 > State-Changed-Why:
 >     Please review the bug submission guidelines at
 >     http://gcc.gnu.org/bugs.html and submit preprocessed source
 >     with your bug report.
 > 
 >     Also, since you are using the Redhat version of gcc,
 >     please report your bug to Red Hat's bug reporting
 >     system at:
 >     http://bugzilla.redhat.com/bugzilla/
 > 
 > http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view&pr=4104&database=gcc
 
 
 more info:
 ----------------------
 
 Subject: [Bug 52451] Changed - structure misalignment problem in gcc
 2.96-81
 Date: Thu, 23 Aug 2001 16:59:12 -0400
 From: bugzilla@redhat.com
 To: jakub@redhat.com, paul.clements@steeleye.com, dlt@redhat.com
 
 Please do not reply directly to this email. All additional
 comments should be made in the comments box of this bug
 report.
 
 https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=52451
 
 --- shadow/52451	Thu Aug 23 16:37:00 2001
 +++ shadow/52451.tmp.10269	Thu Aug 23 16:59:12 2001
 @@ -3,7 +3,7 @@
  Version: 7.1
  Platform: i386
  OS/Version: Linux
 -Status: NEEDINFO   
 +Status: ASSIGNED   
  Resolution: 
  Severity: high
  Priority: normal
 @@ -139,3 +139,24 @@
  Created an attachment (id=29274)
  pre-processed source file, which demonstrates misalignment problem
  
 +
 +------- Additional comments from jakub@redhat.com 2001-08-23 16:59:38
 -------
 +Simplified testcase
 +typedef struct x { int a; int b; } __attribute__((aligned(32))) X;
 +typedef struct y { X x[32]; int c; } Y;
 +
 +Y y[3];
 +
 +int main(void)
 +{
 +  if (sizeof (y) != 3168)
 +    abort ();
 +  exit (0);
 +}
 +(the X in array is important, changing it to
 +typedef struct y { X x; X y[31]; int c; } Y;
 +fixes it).
 +This testcase works on gcc < 2.96-RH or on 2.96-RH+ (incl. 3.0, 3.0.1,
 3.1)
 +on non-IA-32 architectures (tested alpha, IA-64, sparc).
 +Fails on IA-32 with 2.96-RH, 3.0, 3.0.1, 3.1.
 +Apparently some config/i386 alignment issue, will debug this tomorrow.


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

* Re: c/4104: structure misalignment problem causing kernel failures
@ 2001-10-15  8:10 rodrigc
  0 siblings, 0 replies; 4+ messages in thread
From: rodrigc @ 2001-10-15  8:10 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, nobody, paul.clements, rodrigc

Synopsis: structure misalignment problem causing kernel failures

State-Changed-From-To: feedback->closed
State-Changed-By: rodrigc
State-Changed-When: Mon Oct 15 08:10:39 2001
State-Changed-Why:
    The patch in this e-mail:
    http://gcc.gnu.org/ml/gcc-patches/2001-09/msg00072.htm
    
    has been applied to the FSF version of gcc.
    I tested gcc 3.0.2 (prerelease) with your testcase
    and it did not crash.  This patch introduces a slight
    binary incompatibility with previous versions
    of gcc 3.0.x.
    
    For Red Hat's gcc version, you will have to ask
    Red Hat if they have applied this patch or not.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view&pr=4104&database=gcc


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

* Re: c/4104: structure misalignment problem causing kernel failures
@ 2001-10-13 20:52 rodrigc
  0 siblings, 0 replies; 4+ messages in thread
From: rodrigc @ 2001-10-13 20:52 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, nobody, paul.clements, rodrigc

Synopsis: structure misalignment problem causing kernel failures

State-Changed-From-To: open->feedback
State-Changed-By: rodrigc
State-Changed-When: Sat Oct 13 20:52:01 2001
State-Changed-Why:
    Please review the bug submission guidelines at
    http://gcc.gnu.org/bugs.html and submit preprocessed source
    with your bug report.
    
    Also, since you are using the Redhat version of gcc,
    please report your bug to Red Hat's bug reporting
    system at:
    http://bugzilla.redhat.com/bugzilla/

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view&pr=4104&database=gcc


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

* c/4104: structure misalignment problem causing kernel failures
@ 2001-08-23 13:06 paul.clements
  0 siblings, 0 replies; 4+ messages in thread
From: paul.clements @ 2001-08-23 13:06 UTC (permalink / raw)
  To: gcc-gnats

>Number:         4104
>Category:       c
>Synopsis:       structure misalignment problem causing kernel failures
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Aug 23 13:06:02 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Paul Clements
>Release:        
>Organization:
>Environment:
i386, Red Hat 7.1, 2.4.3-12 RedHat kernel
>Description:
We have been experiencing some problems trying to use kernel modules
with kernels that are compiled with different versions of gcc. On our
kernel build machine (where we compile our kernel modules) we have gcc
2.91.66 ; RedHat 7.1 ships with gcc 2.96. 

Now, the problem is that RedHat also apparently compiles (at least its
newer) kernels with the 2.96 gcc. Unfortunately, there appears to be a
structure misalignment problem in gcc 2.96. 

One particular instance of this problem that we are running into is in
the raid1.o module in the 2.4.3 kernel. The structure alignment problem
is causing our gcc 2.91.66-compiled raid1 module to malfunction.
(raid1.o compiled from the same source on gcc 2.96 works fine.) We've
traced the problem down to the following assembly code generated by the
2.96 and 2.91.66 gcc's respectively:

(assembly code for parameter setup and call to __alloc_pages (within
raid1_grow_buffers))

2.96:

movl    $contig_page_data_Rsmp_cef82582+3800, %eax
call    __alloc_pages_Rsmp_decacc2f

2.91.66:

movl    $contig_page_data_Rsmp_cef82582+3884,%eax
call    __alloc_pages_Rsmp_decacc2f
 

gcc 2.91.66 is padding out the zone_t structure by 28 bytes. With an
array of 3 of those before our field in question that equals 84 bytes
offset in the above assembler code.
 
The 28 byte padding is because gcc 2.91.66 is trying to 32 byte align
this structure. The reason for this is that the first submember of
zone_t is explicitly defined as 32 byte aligned (per_cpu_t).

So, gcc 2.91.66 is (properly) aligning the per_cpu_t structure on a 32
byte boundary as specified by the __attribute__((aligned(32))) directive
in that structure's definition:

(gdb) p &((pg_data_t *)0)->node_zones[1].cpu_pages[0]
$22 = (per_cpu_t *) 0x4e0

(gdb) p &((pg_data_t *)0)->node_zones[1].cpu_pages[1]
$23 = (per_cpu_t *) 0x500

(gdb) p 0x500 % 32
$24 = 0

(gdb) p 0x4e0 % 32
$25 = 0


gcc 2.96 is not properly aligning this structure:

(gdb) p &((pg_data_t *)0)->node_zones[1].cpu_pages[0]
$32 = (per_cpu_t *) 0x4c4

(gdb) p &((pg_data_t *)0)->node_zones[1].cpu_pages[1]
$33 = (per_cpu_t *) 0x4e4

(gdb) p 0x4c4 % 32
$34 = 4

(gdb) p 0x4e4 % 32
$35 = 4


So, in order for our raid1 modules to work properly with a kernel
compiled by gcc 2.96, we must also use (the broken) 2.96 to compile our
module.

>How-To-Repeat:
compile raid1.o kernel module with gcc v2.91.66 and attempt
to install module on (gcc 2.96 compiled) RedHat 7.1 2.4.3-12 kernel

Module will fail to perform correctly. Data will never be resynced.

(Root problem is structure misalignment which causes failure in __alloc_pages kernel function call.)
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:
 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)
 


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

end of thread, other threads:[~2001-10-15  8:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-10-15  7:56 c/4104: structure misalignment problem causing kernel failures Paul Clements
  -- strict thread matches above, loose matches on Subject: below --
2001-10-15  8:10 rodrigc
2001-10-13 20:52 rodrigc
2001-08-23 13:06 paul.clements

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