🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.help
Article #41445

Help: Alignment faults on Sparc

#41445
From: Brian Winter
Date: Mon, 08 Apr 1996 00:00
32 lines
1191 bytes
We're running gcc 2.7.2 on a Sparc using optimization level 1, and are
hitting alignment faults. Here's the scenario:

We've got a structure:

struct foo {
  char *a;
  char *b;
  long *c;
}

struct foo *bar;

We've got code that checks that value of bar->a and bar->b:

if ((bar->a == 0xff) && (bar->b == 3))

The optimizer seems to say, hey, a and b are both bytes, why don't
I speed things up a bit and combine the two if clauses into a single
check against the 2 byte value 0xff03. 

The problem is that the memory that *bar points to might be aligned
on an odd boundary. This causes the code to reference a short on a 
byte boundary and we get a SIGBUS. 

We'd like to get around this problem without having to change code.

Any ideas?

Brian
winter@guest.wpi.edu
Technical Details
Message-ID: <4kb8am$ca9@bigboote.WPI.EDU>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 11318c,9c030c5027b1b3,start
X-Google-Attributes: gid11318c,public
From: winter@guest.WPI.EDU (Brian Winter)
Subject: Help: Alignment faults on Sparc
Date: 1996/04/08
Message-ID: <4kb8am$ca9@bigboote.WPI.EDU>
X-Deja-AN: 146367412
distribution: world
organization: Worcester Polytechnic Institute
newsgroups: gnu.gcc.help