On Thu, 18 Jul 2002, Mike Lambert wrote:

> Last night I committed the GC refactoring I submitted the other day, then
> spent a couple hours putting out fires on the tinderbox.
> 
> The last thing I attempted was to align my pointer accesses, because Tru64
> was giving lots of warnings about
> Unaligned access pid=246428 <parrot> va=0x1400b7364 pc=0x12005e408
> ra=0x120037228 inst=0xb52c0010

Using perl-5.8.0-RC3 compiled with 64bit integers and gcc-2.8.1 to build
Parrot, I get 51 warnings of the sort "cast increases required alignment
of target type" One or more of these may be relevant to the failures seen
on 64-bit machines.

For example, one warning in headers.c is:
headers.c:364: warning: cast increases required alignment of target type
and here is line 364:

    ptr = (void**)((char*)headers->bufstart + headers->buflen - sizeof(void*));

On some architectures, some pointers must be aligned on certain
wordsize boundaries.  For example, all void* pointers might be required to
be aligned on 8-byte boundaries.  (See perl5's $Config{alignbytes}).
Although headers->bufstart is a void*, and hence is suitably aligned,
there is apparently no guarantee that headers->buflen is a suitably
sized integer.  If it were '7', for example, then ptr would end up
trying to point to an odd address, and that might be forbidden.

Sometimes, you know from the larger picture that alignment *is*
guaranteed, and the warning can be ignored, even if the compiler can't
figure that out.  Other times, howevever, the warning is pointing to a
real potential problem.  I haven't traced through the headers code to
figure out for myself which it is in this case.

Not too long ago, I went through all the packfile stuff and changed it
from being a stream of char (all of which were assumed to be items
of sizeof(opcode_t)) to an actual stream of opcode_t.  (Look at the
operations on "cursor" in packfile.c to see what I mean.)

Hmm.  I see one packfile warning has snuck back in:
packfile.c:301: warning: cast increases required alignment of target type

    cursor = (opcode_t*)((char*)packed + PACKFILE_HEADER_BYTES);

That's actually harmless, since PACKFILE_HEADER_BYTES = 16, so it is
an integral number of opcode_t's.  The warning can be ignored.  But
the statement could also be better written as
    
    cursor = packed + PACKFILE_HEADER_BYTES/sizeof(opcode_t);

although the paranoid would include a test, perhaps at Configure
time, to verify that this still works -- suppose someone changes
PACKFILE_HEADER_BYTES to 17!

Generally speaking, if you have to cast to (char *) in order to do
pointer arithmetic, you also have to be very very careful that your
result is still suitably aligned for the final target.

Here is the full list of alignment warnings I got this morning:

intqueue.pmc:92: warning: cast increases required alignment of target type
debug.ops:96: warning: cast increases required alignment of target type
debug.ops:106: warning: cast increases required alignment of target type
packfile.c:301: warning: cast increases required alignment of target type
hash.c:95: warning: cast increases required alignment of target type
hash.c:101: warning: cast increases required alignment of target type
hash.c:112: warning: cast increases required alignment of target type
jit.c:213: warning: cast increases required alignment of target type
include/parrot/jit_emit.h:292: warning: cast increases required alignment of target 
type
include/parrot/jit_emit.h:299: warning: cast increases required alignment of target 
type
include/parrot/jit_emit.h:316: warning: cast increases required alignment of target 
type
include/parrot/jit_emit.h:317: warning: cast increases required alignment of target 
type
include/parrot/jit_emit.h:321: warning: cast increases required alignment of target 
type
include/parrot/jit_emit.h:330: warning: cast increases required alignment of target 
type
include/parrot/jit_emit.h:331: warning: cast increases required alignment of target 
type
include/parrot/jit_emit.h:337: warning: cast increases required alignment of target 
type
include/parrot/jit_emit.h:343: warning: cast increases required alignment of target 
type
include/parrot/jit_emit.h:368: warning: cast increases required alignment of target 
type
include/parrot/jit_emit.h:374: warning: cast increases required alignment of target 
type
include/parrot/jit_emit.h:398: warning: cast increases required alignment of target 
type
include/parrot/jit_emit.h:404: warning: cast increases required alignment of target 
type
include/parrot/jit_emit.h:428: warning: cast increases required alignment of target 
type
include/parrot/jit_emit.h:434: warning: cast increases required alignment of target 
type
include/parrot/jit_emit.h:462: warning: cast increases required alignment of target 
type
include/parrot/jit_emit.h:468: warning: cast increases required alignment of target 
type
include/parrot/jit_emit.h:486: warning: cast increases required alignment of target 
type
include/parrot/jit_emit.h:499: warning: cast increases required alignment of target 
type
include/parrot/jit_emit.h:503: warning: cast increases required alignment of target 
type
include/parrot/jit_emit.h:505: warning: cast increases required alignment of target 
type
include/parrot/jit_emit.h:512: warning: cast increases required alignment of target 
type
include/parrot/jit_emit.h:513: warning: cast increases required alignment of target 
type
include/parrot/jit_emit.h:521: warning: cast increases required alignment of target 
type
include/parrot/jit_emit.h:522: warning: cast increases required alignment of target 
type
include/parrot/jit_emit.h:530: warning: cast increases required alignment of target 
type
include/parrot/jit_emit.h:532: warning: cast increases required alignment of target 
type
include/parrot/jit_emit.h:536: warning: cast increases required alignment of target 
type
include/parrot/jit_emit.h:539: warning: cast increases required alignment of target 
type
include/parrot/jit_emit.h:542: warning: cast increases required alignment of target 
type
include/parrot/jit_emit.h:543: warning: cast increases required alignment of target 
type
jit_cpu.c:17: warning: cast increases required alignment of target type
jit_cpu.c:18: warning: cast increases required alignment of target type
jit_cpu.c:22: warning: cast increases required alignment of target type
jit_cpu.c:37: warning: cast increases required alignment of target type
jit_cpu.c:53: warning: cast increases required alignment of target type
jit_cpu.c:59: warning: cast increases required alignment of target type
jit_cpu.c:61: warning: cast increases required alignment of target type
jit_cpu.c:66: warning: cast increases required alignment of target type
resources.c:186: warning: cast increases required alignment of target type
embed.c:212: warning: cast increases required alignment of target type
headers.c:364: warning: cast increases required alignment of target type
dod.c:277: warning: cast increases required alignment of target type

-- 
    Andy Dougherty              [EMAIL PROTECTED]
    Dept. of Physics
    Lafayette College, Easton PA 18042

Reply via email to