public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c++/8464: Bus Error (SIGBUS) due to misaligned access
@ 2002-11-05  9:16 Andreas Schwab
  0 siblings, 0 replies; 3+ messages in thread
From: Andreas Schwab @ 2002-11-05  9:16 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1293 bytes --]

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

From: Andreas Schwab <schwab@suse.de>
To: kyle_s_hoyt@raytheon.com
Cc: gcc-gnats@gcc.gnu.org
Subject: Re: c++/8464: Bus Error (SIGBUS) due to misaligned access
Date: Tue, 05 Nov 2002 18:10:46 +0100

 kyle_s_hoyt@raytheon.com writes:
 
 |> typedef struct
 |> {
 |>   int message;
 |>   int numwords;
 |>   double latitude;
 |>   double longitude;
 |>   double altitude;
 |>   double ew_rate;
 |>   double ns_rate;
 |>   int time;
 |> } NAVIGATION_DATAS __attribute__ ((aligned(4)));
 |> 
 |> void ProcessNavData(NAVIGATION_DATAS *nav_ptr)
 |> {
 |>   NAVIGATION_DATAS store;
 |> 
 |>   store = *nav_ptr;
 |> }
 |> 
 |> int main()
 |> {
 |>   unsigned int data[1024];
 |> 
 |>   ProcessNavData((NAVIGATION_DATAS *)&data[0]);
 |>   ProcessNavData((NAVIGATION_DATAS *)&data[1]);
 |> }
 
 This is invoking undefined behavior.  The aligned attribute by itself
 cannot _decrease_ the alignment, only _increase_ it (ie. it specifies a
 minimum alignment).  You have to add packed as well.
 
 Andreas.
 
 -- 
 Andreas Schwab, SuSE Labs, schwab@suse.de
 SuSE Linux AG, Deutschherrnstr. 15-19, D-90429 Nürnberg
 Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
 "And now for something completely different."


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

* Re: c++/8464: Bus Error (SIGBUS) due to misaligned access
@ 2002-11-05  8:49 bangerth
  0 siblings, 0 replies; 3+ messages in thread
From: bangerth @ 2002-11-05  8:49 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, kyle_s_hoyt, nobody

Synopsis: Bus Error (SIGBUS) due to misaligned access

State-Changed-From-To: open->closed
State-Changed-By: bangerth
State-Changed-When: Tue Nov  5 08:49:44 2002
State-Changed-Why:
    Confirmed with 2.95, but does not happen with 3.0 any more.
    3.2 rejects the code for other reasons.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=8464


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

* c++/8464: Bus Error (SIGBUS) due to misaligned access
@ 2002-11-05  8:26 kyle_s_hoyt
  0 siblings, 0 replies; 3+ messages in thread
From: kyle_s_hoyt @ 2002-11-05  8:26 UTC (permalink / raw)
  To: gcc-gnats


>Number:         8464
>Category:       c++
>Synopsis:       Bus Error (SIGBUS) due to misaligned access
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Tue Nov 05 08:26:00 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     Kyle Hoyt
>Release:        2.95.2 19991024
>Organization:
>Environment:
SunOS 2.6 Generic_108528-06 sun4u sparc SUNW,Ultra-250
>Description:
Copying of data from a pointer results in a SIGBUS error.
Basically, the compiler is generating a ldd instruction
when the data is not guaranteed to be 8-byte aligned.
I have tried to multiple options such as the __attribute__
((aligned)); but I can not get the compiler not to 
create the ldd instruction.
>How-To-Repeat:
Compile the included code and run.  Basically, this is
a real stripped down version of the program.  The program
receives Navigation Data messages via a data tape.  The
message is guarranteed to be 4 byte aligned but not 8 byte.
The ProcessNav routine stores a history of the navigation
data. Thus it copies the message and puts it in a FIFO.
The code works on Pentium (G++ complier) and PowerPC 
(GreenHills compiler) platforms but not on Sparc.
>Fix:
Change the code to use bcopy.
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="gccbug.txt"
Content-Disposition: inline; filename="gccbug.txt"

typedef struct
{
  int message;
  int numwords;
  double latitude;
  double longitude;
  double altitude;
  double ew_rate;
  double ns_rate;
  int time;
} NAVIGATION_DATAS __attribute__ ((aligned(4)));

void ProcessNavData(NAVIGATION_DATAS *nav_ptr)
{
  NAVIGATION_DATAS store;

  store = *nav_ptr;
}

int main()
{
  unsigned int data[1024];

  ProcessNavData((NAVIGATION_DATAS *)&data[0]);
  ProcessNavData((NAVIGATION_DATAS *)&data[1]);
}


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

end of thread, other threads:[~2002-11-05 17:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-11-05  9:16 c++/8464: Bus Error (SIGBUS) due to misaligned access Andreas Schwab
  -- strict thread matches above, loose matches on Subject: below --
2002-11-05  8:49 bangerth
2002-11-05  8:26 kyle_s_hoyt

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