* GCC 2.9.5, Solaris 2.8, SPARC - alignment issue - PLEASE HELP!
@ 2001-07-24 14:24 Rob Newberry
2001-07-26 16:23 ` Alexandre Oliva
0 siblings, 1 reply; 2+ messages in thread
From: Rob Newberry @ 2001-07-24 14:24 UTC (permalink / raw)
To: gcc-help
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.
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: GCC 2.9.5, Solaris 2.8, SPARC - alignment issue - PLEASE HELP!
2001-07-24 14:24 GCC 2.9.5, Solaris 2.8, SPARC - alignment issue - PLEASE HELP! Rob Newberry
@ 2001-07-26 16:23 ` Alexandre Oliva
0 siblings, 0 replies; 2+ messages in thread
From: Alexandre Oliva @ 2001-07-26 16:23 UTC (permalink / raw)
To: Rob Newberry; +Cc: gcc-help
On Jul 24, 2001, Rob Newberry <robnewberry@grouplogic.com> wrote:
> char key[256];
> // 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));
Except that, when you tell it it's accessing a long, it's free to
assume it can do it efficiently, without using the byte access
instructions. If you mean to do byte-per-byte access, use memcpy
explicitly.
> Is there a solution to my problem on Sun OS 5.8 with GCC?
It might be possible to use signal handlers to trap bus errors and
adjust unaligned accesses.
--
Alexandre Oliva Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist *Please* write to mailing lists, not to me
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2001-07-26 16:23 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-07-24 14:24 GCC 2.9.5, Solaris 2.8, SPARC - alignment issue - PLEASE HELP! Rob Newberry
2001-07-26 16:23 ` Alexandre Oliva
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).