From nobody@FreeBSD.ORG  Fri Jul 28 07:09:20 2000
Return-Path: <nobody@FreeBSD.ORG>
Received: by hub.freebsd.org (Postfix, from userid 32767)
	id 74EB837C210; Fri, 28 Jul 2000 07:09:20 -0700 (PDT)
Message-Id: <20000728140920.74EB837C210@hub.freebsd.org>
Date: Fri, 28 Jul 2000 07:09:20 -0700 (PDT)
From: jym@bsdfr.org
Sender: nobody@FreeBSD.ORG
To: freebsd-gnats-submit@FreeBSD.org
Subject: [critical] O2 optimization with egcs 2.95.2 (19991024) cause segfault
X-Send-Pr-Version: www-1.0

>Number:         20253
>Category:       gnu
>Synopsis:       [critical] O2 optimization with egcs 2.95.2 (19991024) cause segfault
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Jul 28 07:10:01 PDT 2000
>Closed-Date:    Mon Jul 31 01:39:39 PDT 2000
>Last-Modified:  Mon Jul 31 01:41:22 PDT 2000
>Originator:     Jean-Yves Moulin
>Release:        FreeBSD 4.1-STABLE
>Organization:
waycom
>Environment:
FreeBSD pulsar.waycom.net 4.1-STABLE FreeBSD 4.1-STABLE #7: Thu Jul 27 15:04:46 CEST 2000     root@pulsar.waycom.net:/usr/src/sys/compile/PULSAR  i386

>Description:
When I try to use egcs version 2.95.2 19991024 with -O2 compilation 
option, program cause sigsegv randomly.
I try to use gdb to debug my program but with no success.
An example of gdb output:
(gdb) run
Starting program: /usr/users/jym/xfdump-0.5/./xfdump
(no debugging symbols found)...(no debugging symbols found)...
(no debugging symbols found)...(no debugging symbols found)...
Connect to DB...        OK => connected at 127.0.0.1
Openning socket...      OK => connected at 127.0.0.1:127

New
Create 0
Found: 0
Add 0:1
Found: 0
Add 0:2
(no debugging symbols found)...(no debugging symbols found)...
Program received signal SIGSEGV, Segmentation fault.
0x280ecf21 in isatty () from /usr/lib/libc.so.4
(gdb) where
#0  0x280ecf21 in isatty () from /usr/lib/libc.so.4
#1  0x280ed101 in isatty () from /usr/lib/libc.so.4
#2  0x280ed815 in malloc () from /usr/lib/libc.so.4
#3  0x8048e88 in extract_news ()
Error accessing memory address 0x7c: Bad address.
(gdb)

Another Example with simple gethostbyname function:

(gdb) run
Starting program: /usr/users/jym/xfdump-0.5/xfdump
(no debugging symbols found)...(no debugging symbols found)...
(no debugging symbols found)...(no debugging symbols found)...
Connect to DB...        OK => connected at localhost
(no debugging symbols found)...(no debugging symbols found)...
Program received signal SIGSEGV, Segmentation fault.
0x280ecf21 in isatty () from /usr/lib/libc.so.4
(gdb) where
#0  0x280ecf21 in isatty () from /usr/lib/libc.so.4
#1  0x280ed101 in isatty () from /usr/lib/libc.so.4
#2  0x280ed815 in malloc () from /usr/lib/libc.so.4
#3  0x280c49a5 in getaddrinfo () from /usr/lib/libc.so.4
#4  0x280c463e in getaddrinfo () from /usr/lib/libc.so.4
#5  0x280c47a8 in getaddrinfo () from /usr/lib/libc.so.4
#6  0x280c3f84 in getaddrinfo () from /usr/lib/libc.so.4
#7  0x280c3231 in res_init () from /usr/lib/libc.so.4
#8  0x280cdec8 in _sethostdnsent () from /usr/lib/libc.so.4
#9  0x280cc6c5 in sethostent () from /usr/lib/libc.so.4
#10 0x280ccc2f in _gethostbyhtname () from /usr/lib/libc.so.4
#11 0x280cc5ac in gethostbyname2 () from /usr/lib/libc.so.4
#12 0x280cc53c in gethostbyname () from /usr/lib/libc.so.4
(gdb)

Huhu...

I try to recompile the same program without -O2 optimization option and
the program work very fine.
I try to use gcc 2.8.1 with -O2 compilation option and the program work
fine too.

Huhu... what's the problem ??? Unknow bug in egcs ??
egcs is in 4.x-RELEASE and STABLE base system... urgl...
>How-To-Repeat:
I cannot send you my specific program sorry.
>Fix:
re-install gcc 2.8.1
bug appears in latest dev egcs version ? don't know...

>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: sheldonh 
State-Changed-When: Mon Jul 31 01:39:39 PDT 2000 
State-Changed-Why:  
See what /etc/defaults/make.conf has to say about optimization. 
This is almost certainly something you'd want to take up 
with the GCC maintainers, but they probably wouldn't be 
able to help you without specific code. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=20253 
>Unformatted:
