public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/21389] New: optimized code seg faults due to double load on sparcV9
@ 2005-05-04 19:35 drew dot johnson at andrew dot com
  2005-05-04 19:39 ` [Bug c/21389] " drew dot johnson at andrew dot com
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: drew dot johnson at andrew dot com @ 2005-05-04 19:35 UTC (permalink / raw)
  To: gcc-bugs

When -O3 or higher is used, the optimizer utilizes the lddf sparc instruction 
to load doubles into registers.  This can generate a bus-error/seg-fault at 
runtime if the source address of the load is not mod8.  The optimizer does not 
check this, even with -munaligned-doubles set.

-- 
           Summary: optimized code seg faults due to double load on sparcV9
           Product: gcc
           Version: 3.4.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: drew dot johnson at andrew dot com
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: 3.4.2
  GCC host triplet: sparc-sun-solaris2.8
GCC target triplet: sparc-sun-solaris2.8


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21389


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

* [Bug c/21389] optimized code seg faults due to double load on sparcV9
  2005-05-04 19:35 [Bug c/21389] New: optimized code seg faults due to double load on sparcV9 drew dot johnson at andrew dot com
@ 2005-05-04 19:39 ` drew dot johnson at andrew dot com
  2005-05-04 19:58 ` [Bug target/21389] " pinskia at gcc dot gnu dot org
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: drew dot johnson at andrew dot com @ 2005-05-04 19:39 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From drew dot johnson at andrew dot com  2005-05-04 19:38 -------
Created an attachment (id=8820)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=8820&action=view)
compile with -O3 or higher, and execution generates seg-fault

The included file compiles with just -O3 or higher as arguments.  It should run
and print a bunch of lines to stdout, then exit normally.  When compiled at -O3
or higher, it generates a bus-error on the command line, due to a segmentation
violation signal when run from the debugger.

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21389


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

* [Bug target/21389] optimized code seg faults due to double load on sparcV9
  2005-05-04 19:35 [Bug c/21389] New: optimized code seg faults due to double load on sparcV9 drew dot johnson at andrew dot com
  2005-05-04 19:39 ` [Bug c/21389] " drew dot johnson at andrew dot com
@ 2005-05-04 19:58 ` pinskia at gcc dot gnu dot org
  2005-05-06 18:49 ` drew dot johnson at andrew dot com
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-05-04 19:58 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c                           |target


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21389


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

* [Bug target/21389] optimized code seg faults due to double load on sparcV9
  2005-05-04 19:35 [Bug c/21389] New: optimized code seg faults due to double load on sparcV9 drew dot johnson at andrew dot com
  2005-05-04 19:39 ` [Bug c/21389] " drew dot johnson at andrew dot com
  2005-05-04 19:58 ` [Bug target/21389] " pinskia at gcc dot gnu dot org
@ 2005-05-06 18:49 ` drew dot johnson at andrew dot com
  2005-05-06 18:53 ` drew dot johnson at andrew dot com
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: drew dot johnson at andrew dot com @ 2005-05-06 18:49 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
   Attachment #8820|compile with -O3 or higher, |compile with -O1 or higher,
        description|and execution generates seg-|and execution generates seg-
                   |fault                       |fault


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21389


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

* [Bug target/21389] optimized code seg faults due to double load on sparcV9
  2005-05-04 19:35 [Bug c/21389] New: optimized code seg faults due to double load on sparcV9 drew dot johnson at andrew dot com
                   ` (2 preceding siblings ...)
  2005-05-06 18:49 ` drew dot johnson at andrew dot com
@ 2005-05-06 18:53 ` drew dot johnson at andrew dot com
  2005-05-06 18:54 ` pinskia at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: drew dot johnson at andrew dot com @ 2005-05-06 18:53 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From drew dot johnson at andrew dot com  2005-05-06 18:53 -------
(In reply to comment #0)
> When -O3 or higher is used, the optimizer utilizes the lddf sparc 
instruction 
> to load doubles into registers.  This can generate a bus-error/seg-fault at 
> runtime if the source address of the load is not mod8.  The optimizer does 
not 
> check this, even with -munaligned-doubles set.

This actually fails when -O1 or higher is used.  For some reason, I thought 
that -O2 was the default.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21389


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

* [Bug target/21389] optimized code seg faults due to double load on sparcV9
  2005-05-04 19:35 [Bug c/21389] New: optimized code seg faults due to double load on sparcV9 drew dot johnson at andrew dot com
                   ` (3 preceding siblings ...)
  2005-05-06 18:53 ` drew dot johnson at andrew dot com
@ 2005-05-06 18:54 ` pinskia at gcc dot gnu dot org
  2005-05-06 19:04 ` drew dot johnson at andrew dot com
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-05-06 18:54 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-05-06 18:54 -------
I think you violating alignment rules in C:

	x = tptr[1].f3;
	p = (char *)tptr;
	p += 4;
	tptr = (test1 *)p;

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21389


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

* [Bug target/21389] optimized code seg faults due to double load on sparcV9
  2005-05-04 19:35 [Bug c/21389] New: optimized code seg faults due to double load on sparcV9 drew dot johnson at andrew dot com
                   ` (4 preceding siblings ...)
  2005-05-06 18:54 ` pinskia at gcc dot gnu dot org
@ 2005-05-06 19:04 ` drew dot johnson at andrew dot com
  2005-05-06 19:07 ` pinskia at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: drew dot johnson at andrew dot com @ 2005-05-06 19:04 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From drew dot johnson at andrew dot com  2005-05-06 19:04 -------
Subject: RE:  optimized code seg faults due to double load on sparcV9

I don't think so.  Malloc does not guarantee anything but mod-4
alignment.  You have to use memalign to get something better (at least
on a Sun).  I only did the +4 pointer stuff to ensure that the double
would be misaligned mod8, as this is what was happening in my code.  As
long as I am on a mod4 boundary for my struct, the -munaligned-doubles
flag should force the handling of doubles as though they are unaligned.
The compiler with no optimization does this.  But as soon as you turn on
-O1, it ignores the unaligned-doubles directive.

Drew

-----Original Message-----
From: pinskia at gcc dot gnu dot org [mailto:gcc-bugzilla@gcc.gnu.org] 
Sent: Friday, May 06, 2005 2:55 PM
To: Johnson, Drew
Subject: [Bug target/21389] optimized code seg faults due to double load
on sparcV9


------- Additional Comments From pinskia at gcc dot gnu dot org
2005-05-06 18:54 -------
I think you violating alignment rules in C:

	x = tptr[1].f3;
	p = (char *)tptr;
	p += 4;
	tptr = (test1 *)p;

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21389

------- You are receiving this mail because: -------
You reported the bug, or are watching the reporter.



------------------------------------------------------------------------------------------------
This message is for the designated recipient only and may
contain privileged, proprietary, or otherwise private information.  
If you have received it in error, please notify the sender
immediately and delete the original.  Any unauthorized use of
this email is prohibited.
------------------------------------------------------------------------------------------------
[mf2]


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21389


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

* [Bug target/21389] optimized code seg faults due to double load on sparcV9
  2005-05-04 19:35 [Bug c/21389] New: optimized code seg faults due to double load on sparcV9 drew dot johnson at andrew dot com
                   ` (5 preceding siblings ...)
  2005-05-06 19:04 ` drew dot johnson at andrew dot com
@ 2005-05-06 19:07 ` pinskia at gcc dot gnu dot org
  2005-05-06 19:47 ` drew dot johnson at andrew dot com
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-05-06 19:07 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-05-06 19:07 -------
(In reply to comment #4)
> Subject: RE:  optimized code seg faults due to double load on sparcV9
> 
> I don't think so.  Malloc does not guarantee anything but mod-4
> alignment.  You have to use memalign to get something better (at least
> on a Sun).  I only did the +4 pointer stuff to ensure that the double
> would be misaligned mod8, as this is what was happening in my code.  As
> long as I am on a mod4 boundary for my struct, the -munaligned-doubles
> flag should force the handling of doubles as though they are unaligned.
> The compiler with no optimization does this.  But as soon as you turn on
> -O1, it ignores the unaligned-doubles directive.

Again what you said about malloc is not true and has not been true since 1989.
The C standard says malloc aligns things the largest alignment required for that machine.  In this case 
doubles are aligned by 8.  So your code is invalid.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21389


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

* [Bug target/21389] optimized code seg faults due to double load on sparcV9
  2005-05-04 19:35 [Bug c/21389] New: optimized code seg faults due to double load on sparcV9 drew dot johnson at andrew dot com
                   ` (6 preceding siblings ...)
  2005-05-06 19:07 ` pinskia at gcc dot gnu dot org
@ 2005-05-06 19:47 ` drew dot johnson at andrew dot com
  2005-05-08 10:58 ` ebotcazou at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: drew dot johnson at andrew dot com @ 2005-05-06 19:47 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From drew dot johnson at andrew dot com  2005-05-06 19:47 -------
Subject: RE:  optimized code seg faults due to double load on sparcV9

Then what is the point of the -munaligned-doubles flag?  Is this simply
ignored?  I understand your point about malloc, but what if we have
casts to buffers that are not mod8-aligned?  Isn't that what
-munaligned-doubles is for? 

I am going back over the original code to find out how we are allocating
the data struct that is causing my program to fail.  I will let you know
when I find something more.

Drew

-----Original Message-----
From: pinskia at gcc dot gnu dot org [mailto:gcc-bugzilla@gcc.gnu.org] 
Sent: Friday, May 06, 2005 3:08 PM
To: Johnson, Drew
Subject: [Bug target/21389] optimized code seg faults due to double load
on sparcV9


------- Additional Comments From pinskia at gcc dot gnu dot org
2005-05-06 19:07 -------
(In reply to comment #4)
> Subject: RE:  optimized code seg faults due to double load on sparcV9
> 
> I don't think so.  Malloc does not guarantee anything but mod-4
> alignment.  You have to use memalign to get something better (at least
> on a Sun).  I only did the +4 pointer stuff to ensure that the double
> would be misaligned mod8, as this is what was happening in my code.
As
> long as I am on a mod4 boundary for my struct, the -munaligned-doubles
> flag should force the handling of doubles as though they are
unaligned.
> The compiler with no optimization does this.  But as soon as you turn
on
> -O1, it ignores the unaligned-doubles directive.

Again what you said about malloc is not true and has not been true since
1989.
The C standard says malloc aligns things the largest alignment required
for that machine.  In this case 
doubles are aligned by 8.  So your code is invalid.

-- 
           What    |Removed                     |Added
------------------------------------------------------------------------
----
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21389

------- You are receiving this mail because: -------
You reported the bug, or are watching the reporter.



------------------------------------------------------------------------------------------------
This message is for the designated recipient only and may
contain privileged, proprietary, or otherwise private information.  
If you have received it in error, please notify the sender
immediately and delete the original.  Any unauthorized use of
this email is prohibited.
------------------------------------------------------------------------------------------------
[mf2]


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21389


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

* [Bug target/21389] optimized code seg faults due to double load on sparcV9
  2005-05-04 19:35 [Bug c/21389] New: optimized code seg faults due to double load on sparcV9 drew dot johnson at andrew dot com
                   ` (7 preceding siblings ...)
  2005-05-06 19:47 ` drew dot johnson at andrew dot com
@ 2005-05-08 10:58 ` ebotcazou at gcc dot gnu dot org
  2005-05-10 12:57 ` drew dot johnson at andrew dot com
  2005-05-10 14:24 ` ebotcazou at gcc dot gnu dot org
  10 siblings, 0 replies; 12+ messages in thread
From: ebotcazou at gcc dot gnu dot org @ 2005-05-08 10:58 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From ebotcazou at gcc dot gnu dot org  2005-05-08 10:58 -------
> Then what is the point of the -munaligned-doubles flag?  Is this simply
> ignored?  I understand your point about malloc, but what if we have
> casts to buffers that are not mod8-aligned?  Isn't that what
> -munaligned-doubles is for? 

Excerpt from the manual:

     With `-munaligned-doubles', GCC assumes that doubles have 8 byte
     alignment only if they are contained in another type, or if they
     have an absolute address.  Otherwise, it assumes they have 4 byte
     alignment.  Specifying this option avoids some rare compatibility
     problems with code generated by other compilers.  It is not the
     default because it results in a performance loss, especially for
     floating point code.

So -munaligned-doubles cannot do anything for your invalid code and the bus
error is to be expected.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21389


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

* [Bug target/21389] optimized code seg faults due to double load on sparcV9
  2005-05-04 19:35 [Bug c/21389] New: optimized code seg faults due to double load on sparcV9 drew dot johnson at andrew dot com
                   ` (8 preceding siblings ...)
  2005-05-08 10:58 ` ebotcazou at gcc dot gnu dot org
@ 2005-05-10 12:57 ` drew dot johnson at andrew dot com
  2005-05-10 14:24 ` ebotcazou at gcc dot gnu dot org
  10 siblings, 0 replies; 12+ messages in thread
From: drew dot johnson at andrew dot com @ 2005-05-10 12:57 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From drew dot johnson at andrew dot com  2005-05-10 12:57 -------
Subject: RE:  optimized code seg faults due to double load on sparcV9

OK, I see your point.  Sorry for inconvenience.  I see that the status
in bugzilla has been updated accordingly.  Is there anything else I
should do to close this?

Drew

-----Original Message-----
From: ebotcazou at gcc dot gnu dot org [mailto:gcc-bugzilla@gcc.gnu.org]

Sent: Sunday, May 08, 2005 6:59 AM
To: Johnson, Drew
Subject: [Bug target/21389] optimized code seg faults due to double load
on sparcV9


------- Additional Comments From ebotcazou at gcc dot gnu dot org
2005-05-08 10:58 -------
> Then what is the point of the -munaligned-doubles flag?  Is this
simply
> ignored?  I understand your point about malloc, but what if we have
> casts to buffers that are not mod8-aligned?  Isn't that what
> -munaligned-doubles is for? 

Excerpt from the manual:

     With `-munaligned-doubles', GCC assumes that doubles have 8 byte
     alignment only if they are contained in another type, or if they
     have an absolute address.  Otherwise, it assumes they have 4 byte
     alignment.  Specifying this option avoids some rare compatibility
     problems with code generated by other compilers.  It is not the
     default because it results in a performance loss, especially for
     floating point code.

So -munaligned-doubles cannot do anything for your invalid code and the
bus
error is to be expected.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21389

------- You are receiving this mail because: -------
You reported the bug, or are watching the reporter.



------------------------------------------------------------------------------------------------
This message is for the designated recipient only and may
contain privileged, proprietary, or otherwise private information.  
If you have received it in error, please notify the sender
immediately and delete the original.  Any unauthorized use of
this email is prohibited.
------------------------------------------------------------------------------------------------
[mf2]


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21389


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

* [Bug target/21389] optimized code seg faults due to double load on sparcV9
  2005-05-04 19:35 [Bug c/21389] New: optimized code seg faults due to double load on sparcV9 drew dot johnson at andrew dot com
                   ` (9 preceding siblings ...)
  2005-05-10 12:57 ` drew dot johnson at andrew dot com
@ 2005-05-10 14:24 ` ebotcazou at gcc dot gnu dot org
  10 siblings, 0 replies; 12+ messages in thread
From: ebotcazou at gcc dot gnu dot org @ 2005-05-10 14:24 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From ebotcazou at gcc dot gnu dot org  2005-05-10 14:24 -------
> OK, I see your point.  Sorry for inconvenience.  I see that the status
> in bugzilla has been updated accordingly.  Is there anything else I
> should do to close this?

No, the status has already been set to RESOLVED.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21389


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

end of thread, other threads:[~2005-05-10 14:24 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-05-04 19:35 [Bug c/21389] New: optimized code seg faults due to double load on sparcV9 drew dot johnson at andrew dot com
2005-05-04 19:39 ` [Bug c/21389] " drew dot johnson at andrew dot com
2005-05-04 19:58 ` [Bug target/21389] " pinskia at gcc dot gnu dot org
2005-05-06 18:49 ` drew dot johnson at andrew dot com
2005-05-06 18:53 ` drew dot johnson at andrew dot com
2005-05-06 18:54 ` pinskia at gcc dot gnu dot org
2005-05-06 19:04 ` drew dot johnson at andrew dot com
2005-05-06 19:07 ` pinskia at gcc dot gnu dot org
2005-05-06 19:47 ` drew dot johnson at andrew dot com
2005-05-08 10:58 ` ebotcazou at gcc dot gnu dot org
2005-05-10 12:57 ` drew dot johnson at andrew dot com
2005-05-10 14:24 ` ebotcazou at gcc dot gnu dot org

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