[ 
https://issues.apache.org/activemq/browse/AMQCPP-25?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_37877
 ] 

Albert Strasheim commented on AMQCPP-25:
----------------------------------------

Figured it out! Looks like a strict aliasing (whatever that is) issue with GCC 
4 optimization.

Example code to be attached. Compiling with GCC 4.1.1 with different 
optimization levels:

{noformat}
[EMAIL PROTECTED] ~]$ gcc --version
gcc (GCC) 4.1.1 20061011 (Red Hat 4.1.1-30)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[EMAIL PROTECTED] ~]$ g++ -O0 -Wall -ansi -o optobug optobug.cpp && ./optobug
i1 == i3 OK
ll1 == ll3 OK
f1 == f3 OK
d1 == d3 OK
[EMAIL PROTECTED] ~]$ g++ -O1 -Wall -ansi -o optobug optobug.cpp && ./optobug
i1 == i3 OK
ll1 == ll3 OK
f1 == f3 OK
d1 == d3 OK
[EMAIL PROTECTED] ~]$ g++ -O2 -Wall -ansi -o optobug optobug.cpp && ./optobug
optobug.cpp: In static member function 'static float Endian::byteSwap(float)':
optobug.cpp:26: warning: dereferencing type-punned pointer will break 
strict-aliasing rules
optobug.cpp:32: warning: dereferencing type-punned pointer will break 
strict-aliasing rules
optobug.cpp: In static member function 'static double Endian::byteSwap(double)':
optobug.cpp:36: warning: dereferencing type-punned pointer will break 
strict-aliasing rules
optobug.cpp:42: warning: dereferencing type-punned pointer will break 
strict-aliasing rules
i1 == i3 OK
ll1 == ll3 OK
f1 != f3 ERROR
d1 != d3 ERROR
[EMAIL PROTECTED] ~]$ g++ -O2 -fno-strict-aliasing -Wall -ansi -o optobug 
optobug.cpp && ./optobug
i1 == i3 OK
ll1 == ll3 OK
f1 == f3 OK
d1 == d3 OK
{noformat}

The idea I get from [dereferencing type-punned pointer will break 
strict-aliasing 
rules|http://lists.freebsd.org/pipermail/freebsd-current/2003-July/007561.html] 
is that the right way to fix this is to use a union containing a float/unsigned 
int or double/unsigned long long.

Alternatively, AMQCPP's compiler flags can be changed to pass 
-fno-strict-aliasing to the compiler. There's an issue to be aware of (I 
think): no code that needs strict aliasing to be turned off can live in a 
AMQCPP header, since this will force anyone using the library to also compile 
with with -fno-strict-aliasing flag, because if they forget, things will break 
mysteriously with older versions of GCC 4.

> Bus error on Solaris OS from DataInput and DataOutput streams
> -------------------------------------------------------------
>
>                 Key: AMQCPP-25
>                 URL: https://issues.apache.org/activemq/browse/AMQCPP-25
>             Project: ActiveMQ C++ Client
>          Issue Type: Bug
>          Components: CMS Impl
>    Affects Versions: 1.1
>         Environment: Solaris 10 OS
>            Reporter: Timothy Bish
>         Assigned To: Timothy Bish
>            Priority: Minor
>             Fix For: 1.1
>
>         Attachments: optobug.cpp
>
>
> Due to misaligned memory reads, there is a bus error that can occur in using 
> the new DataInputStream and DataOutputStream classes.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
https://issues.apache.org/activemq/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to