SIGBUS on ( double * )

Marco Bernasocchi marco at bernawebdesign.ch
Wed Oct 23 18:00:36 UTC 2013


On 10/23/2013 07:45 PM, Jeffrey Walton wrote:
>> I often get SIGBUS when my code (qgis.org) hits stuff like this:
>>
>> GEOSCoordSeq_getX( cs, j, ( double * )&mGeometry[position] );
> Yes, that's not legal C/C++. Its undefined behavior.
how do you mean?
I get SIGBUS also for things like:
tempx = ( double* )ptr;

and replacing with the following does the job:
memcpy( &tempx, ptr, sizeof( tempx ) );
>
>> double a;
>> memcpy( a, &mGeometry[position])
>> GEOSCoordSeq_getX( cs, j, &a )
>>
>> then all works correctly,
> Yep. And if the buffers overlap, you need to `memmov` it.
>
>> could this be because of a
>> compiler setting?
> No, its the QT devs doing something they should not be doing. Newer
> ARMs are OK with unaligned data, while older ARMs are not. They appear
> to be testing on newer ARMs only (ARMv6 or ARMv7, IIRC).
I run my code on ARMv7 after building with:
for debug:
CFLAGS: -DANDROID -Wno-psabi -std=c99 -g -O0 -marm -finline-limit=300 
-fno-strict-aliasing -fno-omit-frame-pointer -DDEBUG -D_DEBUG 
-march=armv7-a -mfloat-abi=softfp -mfpu=vfp
CXXFLAGS: -DANDROID -Wno-psabi -std=gnu++0x -g -O0 -marm 
-finline-limit=300 -fno-strict-aliasing -fno-omit-frame-pointer -DDEBUG 
-D_DEBUG
LDFLAGS:  -Wl,--fix-cortex-a8

for release:
CFLAGS: -DANDROID -Wno-psabi -std=c99 -mthumb -O0 -march=armv7-a 
-mfloat-abi=softfp -mfpu=vfp
CXXFLAGS:-DANDROID -Wno-psabi -std=gnu++0x -mthumb -O0 -march=armv7-a 
-mfloat-abi=softfp -mfpu=vfp
LDFLAGS: -Wl,--fix-cortex-a8

>
> I believe -Wstrict-aliasing or -Wcast-align will catch it at compile
> time. See http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html and
> https://www.gnu.org/software/gsl/manual/html_node/GCC-warning-options-for-numerical-programs.html#GCC-warning-options-for-numerical-programs.
>
thanks a lot
> Jeff
>
> On Wed, Oct 23, 2013 at 1:12 PM, Marco Bernasocchi
> <marco at bernawebdesign.ch> wrote:
>> Hi all, I often get SIGBUS when my code (qgis.org) hits stuff like this:
>>
>> GEOSCoordSeq_getX( cs, j, ( double * )&mGeometry[position] );
>>
>> if I change the call to use memcpy like
>>
>> double a;
>> memcpy( a, &mGeometry[position])
>> GEOSCoordSeq_getX( cs, j, &a )
>>
>> then all works correctly, the issue is that I've a lot of those calls and If
>> I'm not wrong in the past it used to work). could this be because of a
>> compiler setting? I'm using necessitas Qt sdk with ndk r8b1 compiling both
>> with -mthumb and without has the same issue.
>>
>> thanks a lot
>> Marco
> _______________________________________________
> Necessitas-devel mailing list
> Necessitas-devel at kde.org
> https://mail.kde.org/mailman/listinfo/necessitas-devel
>


-- 
Marco Bernasocchi
http://opengis.ch


More information about the Necessitas-devel mailing list