Alignment problems

D

David Thompson

Yes, some compilers have a pack directive, but it doesn't always work.

For example, on SPARC, attempting to access a misaligned object causes
the program to crash. Here's a program that uses gcc's
__attribute__((packed)) extension: <snip>
If you refer to the misaligned member directly, so the compiler
knows that it's misaligned, it can access it correctly. If you've
saved a pointer to the misaligned member, there's no way for the
compiler to know that it's misaligned.

Or nonstandardly tag the pointers. That's what then-Tandem TNS/R did
for a (MIPS) 32bit reimplementation of a former custom 16bit ISA.
To (try to) futureproof they actually jumped to 64bit. If you indirect
through a 'refaligned 2' pointer the compiler uses 2 (or 4) 16bit
accesses; for 'refaligned 8' it does one 32bit (or 64bit) which faults
if misaligned (although IIRC they also offered a fixup handler, with
as noted elsethread performance degradation).

They used a pragma not a language qualifier, so it wasn't enforced or
verified across caller/callee, unfortunately.

Now-Tanpaqard changed further to Itanium, and I'm not up to date on
what they've done there.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
474,083
Messages
2,570,591
Members
47,212
Latest member
RobynWiley

Latest Threads

Top