Bug 489990 - Aliasing breakage causes unexpected behavior when compiled with gcc44 -O2
Aliasing breakage causes unexpected behavior when compiled with gcc44 -O2
Status: CLOSED RAWHIDE
Product: Fedora
Classification: Fedora
Component: ruby (Show other bugs)
rawhide
All Linux
high Severity high
: ---
: ---
Assigned To: Jeroen van Meeuwen
Fedora Extras Quality Assurance
:
Depends On:
Blocks: 226381
  Show dependency treegraph
 
Reported: 2009-03-12 15:22 EDT by Mamoru TASAKA
Modified: 2009-03-15 13:50 EDT (History)
2 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2009-03-15 13:50:01 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:


Attachments (Terms of Use)

  None (edit)
Description Mamoru TASAKA 2009-03-12 15:22:44 EDT
Description of problem:
Hello.
Now I want to restart to review ruby Merge Review, however
please also take care of this bug.

When I recompile ruby-1.8.6.287-3.fc11 on rawhide i386 machine,
it fails at %install. This can be fixed by changing to something like:
------------------------------------------------------------------------
# convert to utf-8
for i in `find -type f`; do
  sh -c "
  iconv -f utf-8 -t utf-8 $i > /dev/null 2>&1 || (iconv -f euc-jp -t utf-8 $i > $i.new && mv $i.new $i || exit 1)
  if [ $? != 0 ]; then
    iconv -f iso8859-1 -t utf-8 $i > $.new && mv $i.new $i || rm -f $i.new
  fi
  "
done
-------------------------------------------------------------------------

However after fixing this recompiling latest rawhide ruby srpm
still fails, this time at %check:
-------------------------------------------------------------------------
 20349  Executing(%check): /bin/sh -e /home/tasaka1/rpmbuild/INSTROOT/rpm-tmp.22DLhg
 20350  + umask 022
 20351  + cd /home/tasaka1/rpmbuild/BUILD
 20352  + cd ruby-1.8.6.287
 20353  + unset DISPLAY
 20354  + pushd ruby-1.8.6-p287
 20355  ~/rpmbuild/BUILD/ruby-1.8.6.287/ruby-1.8.6-p287 ~/rpmbuild/BUILD/ruby-1.8.6.287
 20356  + make test
 20357  not ok float 1 -- ./sample/test.rb:1172
 20358  not ok float 2 -- ./sample/test.rb:1173
 20359  not ok float 3 -- ./sample/test.rb:1174
 20360  not ok float 4 -- ./sample/test.rb:1175
 20361  not ok float 5 -- ./sample/test.rb:1176
 20362  not ok float 6 -- ./sample/test.rb:1177
 20363  not ok float 7 -- ./sample/test.rb:1178
 20364  not ok float 8 -- ./sample/test.rb:1179
 20365  not ok float 9 -- ./sample/test.rb:1180
 20366  test failed
 20367  make: *** [test] Error 1
 20368  error: Bad exit status from /home/tasaka1/rpmbuild/INSTROOT/rpm-tmp.22DLhg (%check)
-------------------------------------------------------------------------

Actually the rebuilt miniruby does some very strange behavior:
-------------------------------------------------------------------------
[tasaka1@localhost ruby-1.8.6-p287]$ ./miniruby -e "p 2.6"
26.0
[tasaka1@localhost ruby-1.8.6-p287]$ ./miniruby -e "p 2.6.floor"
26
[tasaka1@localhost ruby-1.8.6-p287]$ ./miniruby -e "p 2.6.floor == 2"
false
-------------------------------------------------------------------------
See the actual line 1172 of sample/test.rb.

Version-Release number of selected component (if applicable):
ruby-1.8.6.287-3.fc11.i386

How reproducible:
100%

Steps to Reproduce:
1. Recompile ruby-1.8.6.287-3.fc11.i386 with gcc44 (i.e. current rawhide)
   (with spec file modified as above to make rebuild succeed at %prep,
   %build, %install)
2. See what occurs at %check
3.
  
Actual results:
make test fails (created miniruby behaves very oddly)

Expected results:
%check succeeds

Additional info:
Info 1:
It seems that this is because util.c is breaking strict aliasing
rules. Fedora's %optflags uses -O2 and -O2 implies -fstrict-aliasing.
build.log shows lots of warnings on util.c:
---------------------------------------------------------------
$ touch util.c ;  LANG=C make RUBY_INSTALL_NAME=ruby 
gcc -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i586 -mtune=generic -fasynchronous-unwind-tables -Wall  -fPIC  -DRUBY_EXPORT -D_GNU_SOURCE=1  -I. -I.   -c util.c
util.c: In function 'b2d':
util.c:1759: warning: dereferencing pointer 'd.119' does break strict-aliasing rules
util.c:1759: note: initialized from here
util.c:1761: warning: dereferencing pointer 'd.119' does break strict-aliasing rules
util.c:1761: note: initialized from here
util.c:1766: warning: dereferencing pointer 'd.119' does break strict-aliasing rules
util.c:1766: note: initialized from here
util.c:1768: warning: dereferencing pointer 'd.119' does break strict-aliasing rules
util.c:1768: note: initialized from here
util.c:1771: warning: dereferencing pointer 'd.119' does break strict-aliasing rules
util.c:1771: note: initialized from here
.....
.....
----------------------------------------------------------------

And
----------------------------------------------------------------
touch util.c ; LANG=C make RUBY_INSTALL_NAME=ruby CC="gcc -fno-strict-aliasing"
----------------------------------------------------------------
seems to be a workaround for this issue. 
However this is really a bug in util.c and upstream (and also
Fedora) must really fix this code.

Info 2:
The codes offending strict aliasing rule in util.c are
also used in prdtoa.c in nspr (and this caused rendering disorder
on firefox and so on). See bug 487844

Info 3:
There are also warning about breaking strict-aliasing rules on
ext/socket/socket.c .
Comment 1 Jeroen van Meeuwen 2009-03-15 00:08:09 EDT
(In reply to comment #0)
> Description of problem:
> Hello.
> Now I want to restart to review ruby Merge Review, however
> please also take care of this bug.
> 
> When I recompile ruby-1.8.6.287-3.fc11 on rawhide i386 machine,
> it fails at %install. This can be fixed by changing to something like:
> ------------------------------------------------------------------------
> # convert to utf-8
> for i in `find -type f`; do
>   sh -c "
>   iconv -f utf-8 -t utf-8 $i > /dev/null 2>&1 || (iconv -f euc-jp -t utf-8 $i >
> $i.new && mv $i.new $i || exit 1)
>   if [ $? != 0 ]; then
>     iconv -f iso8859-1 -t utf-8 $i > $.new && mv $i.new $i || rm -f $i.new
>   fi
>   "
> done
> -------------------------------------------------------------------------
> 

I don't see what goes wrong here, or what it is you are trying to fix. I did find the snippet failed at some points but I'm interested in the error rather then the solution, to see if my fix covers your error as well or whether there's anything else I need to look at. Thanks!
Comment 2 Mamoru TASAKA 2009-03-15 01:07:35 EDT
(In reply to comment #1)
> (In reply to comment #0) 
> I don't see what goes wrong here, or what it is you are trying to fix. I did
> find the snippet failed at some points but I'm interested in the error rather
> then the solution, to see if my fix covers your error as well or whether
> there's anything else I need to look at. Thanks!  

The original script is failing simply because it tries to
execute iconv on binary file (then %install stage exits "immediately"
because %install calls shell script witn "/bin/sh -e")

My script is just trying to ignore this error by executing
iconv with subshell with "/bin/sh -c", not with "/bin/sh -e -c"
Comment 3 Jeroen van Meeuwen 2009-03-15 01:53:07 EDT
The packages in http://koji.fedoraproject.org/koji/taskinfo?taskID=1241902 should fix this issue
Comment 4 Mamoru TASAKA 2009-03-15 13:50:01 EDT
Well,
- Adding -fno-strict-aliasing should be enough (-O2 -fno-strict-aliasing
  will use -fno-strict-aliasing), so I again switched to -O2
- The rebuilt -5 binary rpm will search i586-linux directory instead
  of i386-linux, so I patched against configure so that on i586
  ruby will search i386-linux directory (as before, like perl).

Now I mark this as closed. I will try to review ruby.spec again
and will write some comments on Merge Review ticket if anything
else needs fixing.
Thank you!

Note You need to log in before you can comment on or make changes to this bug.