FS#15189 - [libnice] gcc optimizations -O2 (-fstrict-aliasing) breaks sha1.c

Attached to Project: Community Packages
Opened by Jérémie Laval (Garuma) - Saturday, 20 June 2009, 15:31 GMT
Last edited by Ionut Biru (wonder) - Monday, 22 June 2009, 17:55 GMT
Task Type Bug Report
Category
Status Closed
Assigned To Ionut Biru (wonder)
Architecture All
Severity Medium
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 2
Private No

Details

Description:

Some cryptographic code like sha1.c in libnice breaks with -O2 with Arch gcc on x64. I suspect this is also the case with Ekiga which reports a lot of corrupted packet when used and can't connect anywhere. Since amsn sound conferencing is based on farsight2 which is also based on libnice for its transport layer, that amsn feature is also broken.

Additional info:
* libnice : all version. Testing was done starting from 0.7
* gcc: vanilla from arch : gcc (GCC) 4.4.0 20090526 (prerelease)

Steps to reproduce:

Compile a arch package of libnice (http://repos.archlinux.org/viewvc.cgi/community/lib/libnice/PKGBUILD?revision=1.8&root=community&pathrev=CURRENT) and go to src/libnice-0.0.8/stun/tests. 'make check' in it and run ./test-hmac, sha1 test should report different hash than the one expected while md5 works.

If you 'make clean && make distclean' in the libnice directory and add a 'export CFLAGS=''' in the PKGBUILD before the ./configure call and redo the procedure above it now works correctly.

It's highly unlikely that the sha1.c code is bad since it's quite old&robust and has been reported to work correctly elsewhere.
This task depends upon

Closed by  Ionut Biru (wonder)
Monday, 22 June 2009, 17:55 GMT
Reason for closing:  Fixed
Comment by Ionut Biru (wonder) - Saturday, 20 June 2009, 17:43 GMT
thanks you for notify this. is only related to x86_64?
Comment by Jérémie Laval (Garuma) - Saturday, 20 June 2009, 17:53 GMT
I admit I have no idea, I'm only running on Arch 64.
Comment by Gerardo Exequiel Pozzi (djgera) - Saturday, 20 June 2009, 18:11 GMT
  • Field changed: Summary (gcc optimizations on x64 too aggressive or buggy → gcc optimizations too aggressive or buggy)
  • Field changed: Status (Unconfirmed → Assigned)
  • Field changed: Architecture (x86_64 → All)
  • Task assigned to Allan McRae (Allan)
Yes, the problem is in the function SHA1Transform from sha1.c when you use -O2 you see many of this warnings "warning: dereferencing pointer 'block' does break strict-aliasing rules"

Simple add: to CFLAGS -fno-strict-aliasing (that is enabled in -O2 level)

Not only on x86_64.
Comment by Gerardo Exequiel Pozzi (djgera) - Saturday, 20 June 2009, 18:38 GMT
Trivial change:

- uint32_t workspace[16];
+ uint8_t workspace[64];

should run fine now ;)

Comment by Gerardo Exequiel Pozzi (djgera) - Saturday, 20 June 2009, 19:01 GMT
  • Field changed: Attached to Project (Arch Linux → Community Packages)
  • Field changed: Summary ([gcc] optimizations too aggressive or buggy → [libnice] gcc optimizations -O2 (-fstrict-aliasing) breaks sha1.c)
Moving this to community packages. This should be reported to upstream.
Comment by Ionut Biru (wonder) - Saturday, 20 June 2009, 21:46 GMT
i've rebuilded libnice, farsight2 and others packages that breaks. tell me if is working.
Comment by Jérémie Laval (Garuma) - Monday, 22 June 2009, 10:15 GMT
Awesome! I will give it a spin this evening
Comment by Jérémie Laval (Garuma) - Monday, 22 June 2009, 17:51 GMT
Indeed it works great now.

Loading...