Bug 20253

Summary: [critical] O2 optimization with egcs 2.95.2 (19991024) cause segfault
Product: Base System Reporter: jym <jym>
Component: gnuAssignee: freebsd-bugs (Nobody) <bugs>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: 4.1-STABLE   
Hardware: Any   
OS: Any   

Description jym 2000-07-28 15:10:01 UTC
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...

Fix: 

re-install gcc 2.8.1
bug appears in latest dev egcs version ? don't know...
How-To-Repeat: I cannot send you my specific program sorry.
Comment 1 Sheldon Hearn freebsd_committer freebsd_triage 2000-07-31 09:39:39 UTC
State Changed
From-To: open->closed

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.