This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
GCC 2.9.5, Solaris 2.8, SPARC - alignment issue - PLEASE HELP!
- To: gcc-help at gcc dot gnu dot org
- Subject: GCC 2.9.5, Solaris 2.8, SPARC - alignment issue - PLEASE HELP!
- From: Rob Newberry <robnewberry at grouplogic dot com>
- Date: Tue, 24 Jul 2001 17:23:23 -0400 (EDT)
Hi,
I have some legacy code, and I really, really, really need to not modify
it. This code has alignment issues, but I would expect the compiler (or
the OS maybe) to handle this for me.
Here's some example of the code that causes problems:
char key[256];
long value = 1;
// this causes a SIGSEGV on SPARC
*((long*)&key[2]) = value;
I know this is cruddy, but I would _EXPECT_ the compiler to essentially
catch this and (more-or-less) rewrite it as something similar to:
memcpy( &key[2], &value, sizeof(long));
I have tried compiling with STRICT_ALIGNMENT=1 and
SLOW_UNALIGNED_ACCESS=1, but neither is helping. It always seg-faults.
Is there a solution to my problem on Sun OS 5.8 with GCC?
I am amenable to mucking with the Makefile or changing some kind of OS
configuration. The thing that I can't do is modify the code.
(Actually, I can modify the code, but the problem is that I'm not sure I
can find all the places this could happen in the code, so I'd like to
simply let the compiler do it. If there is a way to have the compiler
generate an error every time it sees misalignment, that would also be OK,
but absolutely less optimal.)
PLEASE HELP!
Rob
---------------------------------------------------------------------
Rob Newberry
Director of Fajita Technology
Group Logic, Inc.