Index: src/packfile.c
===================================================================
--- src/packfile.c	(revision 36276)
+++ src/packfile.c	(working copy)
@@ -451,12 +451,18 @@
     extern int Parrot_exec_run;
 #endif
 
-#define TRACE_PACKFILE 0
+#define TRACE_PACKFILE 2
 
+/* FIXME for 64bit: 0xbc => 0xc0 */
 #define ROUND_16(val) (((val) & 0xf) ? 16 - ((val) & 0xf) : 0)
 #define ALIGN_16(st, cursor) \
-    (cursor) += ROUND_16((const char *)(cursor) - (const char *)(st))/sizeof (opcode_t)
+    (cursor) += (ROUND_16((const unsigned char *)(cursor) - (const unsigned char *)(st))/OPCODE_T_SIZE)
 
+#define ALIGN16(ptr) (const opcode_t *)(((unsigned long)ptr + 15) & (~15))
+
+#define ALIGN_DOWN(v, align)   ((v)&(-align))
+#define ALIGN_UP(v, align)     ALIGN_DOWN((v)+((align)-1), align)
+#define ALIGN_UP_PTR(v, align) (void*)ALIGN_UP((unsigned long)(v), align)
 /*
 
 =item C<void PackFile_destroy>
@@ -1006,6 +1012,9 @@
     }
 
     /* Padding. */
+#if TRACE_PACKFILE
+    Parrot_io_eprintf(NULL, "PackFile_unpack: 3 words padding.\n");
+#endif
     padding = PF_fetch_opcode(self, &cursor);
     padding = PF_fetch_opcode(self, &cursor);
     padding = PF_fetch_opcode(self, &cursor);
@@ -1143,7 +1152,6 @@
             }
         }
     }
-
     return NULL;
 }
 
@@ -1377,6 +1385,10 @@
     self->itype    = PF_fetch_opcode(self->pf, &cursor);
     self->id       = PF_fetch_opcode(self->pf, &cursor);
     self->size     = PF_fetch_opcode(self->pf, &cursor);
+#if TRACE_PACKFILE == 2
+    Parrot_io_eprintf(NULL, "default_unpack: op_count=%d, itype=%d, id=%d, size=%d.\n",
+        self->op_count, self->itype, self->id, self->size);
+#endif
 
     if (self->size == 0)
         return cursor;
@@ -1409,7 +1421,8 @@
         for (i = 0; i < (int)self->size; i++) {
             self->data[i] = PF_fetch_opcode(self->pf, &cursor);
 #if TRACE_PACKFILE
-            Parrot_io_eprintf(NULL, "op[#%d] %u\n", i, self->data[i]);
+            Parrot_io_eprintf(NULL, "default_unpack: transformed op[#%d]/%d %u\n", 
+                i, self->size, self->data[i]);
 #endif
         }
     }
@@ -1787,12 +1800,22 @@
         return NULL;
 
     if (f) {
+#if TRACE_PACKFILE
+        Parrot_io_eprintf(NULL, "PackFile_Segment_unpack: special\n");
+#endif
         cursor = (f)(interp, self, cursor);
+#if TRACE_PACKFILE == 2
+        Parrot_io_eprintf(NULL, "  PackFile_Segment_unpack: cursor=0x%x\n", cursor);
+#endif
         if (!cursor)
             return NULL;
     }
 
-    ALIGN_16(self->pf->src, cursor);
+    /* ALIGN_16(self->pf->src, cursor); */
+    cursor = ALIGN16(cursor);
+#if TRACE_PACKFILE == 2
+    Parrot_io_eprintf(NULL, "  ALIGN(16): src=0x%x cursor=0x%x\n", self->pf->src, cursor);
+#endif
     return cursor;
 }
 
@@ -1906,6 +1929,9 @@
     size_t                     i;
 
     dir->num_segments = PF_fetch_opcode(pf, &cursor);
+#if TRACE_PACKFILE
+    Parrot_io_eprintf(interp, "directory_unpack: %ld num_segments\n", dir->num_segments);
+#endif
     mem_realloc_n_typed(dir->segments, dir->num_segments, PackFile_Segment *);
 
     for (i = 0; i < dir->num_segments; i++) {
@@ -1915,17 +1941,16 @@
 
         /* get type */
         UINTVAL type = PF_fetch_opcode(pf, &cursor);
-
         if (type >= PF_MAX_SEG)
             type = PF_UNKNOWN_SEG;
 
-#if TRACE_PACKFILE
+#if TRACE_PACKFILE == 2
         Parrot_io_eprintf(NULL, "Segment type %d.\n", type);
 #endif
         /* get name */
         name = PF_fetch_cstring(pf, &cursor);
 
-#if TRACE_PACKFILE
+#if TRACE_PACKFILE == 2
         Parrot_io_eprintf(NULL, "Segment name \"%s\".\n", name);
 #endif
 
@@ -1934,7 +1959,13 @@
         mem_sys_free(name);
 
         seg->file_offset = PF_fetch_opcode(pf, &cursor);
+#if TRACE_PACKFILE == 2
+        Parrot_io_eprintf(NULL, "Segment file_offset %ld.\n", seg->file_offset);
+#endif
         seg->op_count    = PF_fetch_opcode(pf, &cursor);
+#if TRACE_PACKFILE == 2
+        Parrot_io_eprintf(NULL, "Segment op_count %ld.\n", seg->op_count);
+#endif
 
         if (pf->need_wordsize) {
 #if OPCODE_T_SIZE == 8
@@ -1950,6 +1981,10 @@
                         pf->header->wordsize);
                 return 0;
             }
+#if TRACE_PACKFILE == 2
+        Parrot_io_eprintf(NULL, "Segment offset: new pos 0x%x (src=0x%x cursor=0x%x).\n", 
+            pos - pf->src, pf->src, cursor);
+#endif
         }
         else
             pos = pf->src + seg->file_offset;
@@ -1978,7 +2013,16 @@
         seg->dir         = dir;
     }
 
-    ALIGN_16(pf->src, cursor);
+    /* FIXME on 64bit reading 32bit */
+#  if TRACE_PACKFILE == 2
+    Parrot_io_eprintf(NULL, "pre-ALIGN: cursor=0x%x\n", cursor);
+#  endif
+    /*ALIGN_16(pf->src, cursor);*/
+    cursor = ALIGN16(cursor);
+    /*cursor = ALIGN(cursor, (opcode_t)16);*/
+#  if TRACE_PACKFILE == 2
+    Parrot_io_eprintf(NULL, "ALIGN(16): src=0x%x cursor=0x%x\n", pf->src, cursor);
+#  endif
 
     /* and now unpack contents of dir */
     for (i = 0; cursor && i < dir->num_segments; i++) {
@@ -1991,6 +2035,9 @@
         size_t delta = 0;
 
         cursor = csave;
+#if TRACE_PACKFILE == 2
+        Parrot_io_eprintf(NULL, "PackFile_Segment_unpack [%d] tmp len=%d.\n", i, tmp);
+#endif
         pos    = PackFile_Segment_unpack(interp, dir->segments[i], cursor);
 
         if (!pos) {
@@ -1998,7 +2045,12 @@
                     dir->segments[i]->name);
             return 0;
         }
+#if TRACE_PACKFILE == 2
+        else
+            Parrot_io_eprintf(NULL, "PackFile_Segment_unpack ok. pos=0x%x\n", pos);
+#endif
 
+        /* BUG: on 64bit reading 32bit lurking here! */
         if (pf->need_wordsize) {
 #if OPCODE_T_SIZE == 8
             if (pf->header->wordsize == 4)
@@ -2010,6 +2062,10 @@
         }
         else
             delta = pos - cursor;
+#if TRACE_PACKFILE == 2
+        Parrot_io_eprintf(NULL, "  delta=%d pos=0x%x cursor=0x%x\n", 
+            delta, pos, cursor);
+#endif
 
         if ((size_t)delta != tmp || dir->segments[i]->op_count != tmp)
             fprintf(stderr, "PackFile_unpack segment '%s' directory length %d "
@@ -3198,6 +3254,10 @@
 
     pf = self->base.pf;
     self->fixup_count = PF_fetch_opcode(pf, &cursor);
+#if TRACE_PACKFILE
+        Parrot_io_eprintf(interp,
+                "PackFile_FixupTable_unpack(): %ld entries\n", self->fixup_count);
+#endif
 
     if (self->fixup_count) {
         self->fixups = (PackFile_FixupEntry **)mem_sys_allocate_zeroed(
@@ -3222,6 +3282,11 @@
             case enum_fixup_sub:
                 entry->name = PF_fetch_cstring(pf, &cursor);
                 entry->offset = PF_fetch_opcode(pf, &cursor);
+#if TRACE_PACKFILE == 2
+        Parrot_io_eprintf(interp,
+                "PackFile_FixupTable_unpack(): type %d, name %s, offset %ld\n", 
+                entry->type, entry->name, entry->offset);
+#endif
                 break;
             case enum_fixup_none:
                 break;
@@ -3462,7 +3527,8 @@
     for (i = 0; i < self->const_count; i++) {
 #if TRACE_PACKFILE
         Parrot_io_eprintf(interp,
-                "PackFile_ConstTable_unpack(): Unpacking constant %ld\n", i);
+                "PackFile_ConstTable_unpack(): Unpacking constant %ld/%ld\n", 
+                i, self->const_count);
 #endif
 
 #if EXEC_CAPABLE
@@ -3659,7 +3725,6 @@
     PackFile * const pf = constt->base.pf;
     const opcode_t type = PF_fetch_opcode(pf, &cursor);
 
-/* #define TRACE_PACKFILE 1 */
 #if TRACE_PACKFILE
     Parrot_io_eprintf(NULL, "PackFile_Constant_unpack(): Type is %ld ('%c')...\n",
             type, (char)type);
@@ -4000,11 +4065,21 @@
 
     /* Unpack keys. */
     self->num_keys = PF_fetch_opcode(seg->pf, &cursor);
+#if TRACE_PACKFILE
+    Parrot_io_eprintf(interp,
+            "PackFile_Annotations_unpack: Unpacking %ld keys\n",
+            self->num_keys);
+#endif
     self->keys     = mem_allocate_n_typed(self->num_keys, PackFile_Annotations_Key *);
     for (i = 0; i < self->num_keys; i++) {
         self->keys[i]       = mem_allocate_typed(PackFile_Annotations_Key);
         self->keys[i]->name = PF_fetch_opcode(seg->pf, &cursor);
         self->keys[i]->type = PF_fetch_opcode(seg->pf, &cursor);
+#if TRACE_PACKFILE == 2
+    Parrot_io_eprintf(interp,
+            "PackFile_Annotations_unpack: key[%d]/%d name=%s type=%d\n",
+            i, self->num_keys, self->keys[i]->name, self->keys[i]->type);
+#endif
     }
 
     /* Unpack groups. */
@@ -4014,6 +4089,11 @@
         self->groups[i]                  = mem_allocate_typed(PackFile_Annotations_Group);
         self->groups[i]->bytecode_offset = PF_fetch_opcode(seg->pf, &cursor);
         self->groups[i]->entries_offset  = PF_fetch_opcode(seg->pf, &cursor);
+#if TRACE_PACKFILE == 2
+    Parrot_io_eprintf(interp,
+            "PackFile_Annotations_unpack: group[%d]/%d bytecode_offset=%d entries_offset=%d\n",
+            i, self->num_groups, self->groups[i]->bytecode_offset, self->groups[i]->entries_offset);
+#endif
     }
 
     /* Unpack entries. */
Index: src/packfile/pf_items.c
===================================================================
--- src/packfile/pf_items.c	(revision 36276)
+++ src/packfile/pf_items.c	(working copy)
@@ -108,7 +108,7 @@
 /* HEADERIZER END: static */
 
 
-#define TRACE_PACKFILE 0
+#define TRACE_PACKFILE 2
 
 /*
  * round val up to whole size, return result in bytes
@@ -469,11 +469,11 @@
     opcode_t o;
     if (!pf || !pf->fetch_op)
         return *(*stream)++;
-#if TRACE_PACKFILE == 2
-    Parrot_io_eprintf(NULL, "PF_fetch_opcode: Reordering.\n");
-#endif
     o = (pf->fetch_op)(*((const unsigned char **)stream));
     *((const unsigned char **) (stream)) += pf->header->wordsize;
+#if TRACE_PACKFILE == 2
+    Parrot_io_eprintf(NULL, "PF_fetch_opcode: 0x%lx (%ld)\n", o, o);
+#endif
     return o;
 }
 
@@ -720,7 +720,6 @@
     /* These may need to be separate */
     size = (size_t)PF_fetch_opcode(pf, cursor);
 
-/* #define TRACE_PACKFILE 1 */
 #if TRACE_PACKFILE
     Parrot_io_eprintf(NULL, "PF_fetch_string(): flags are 0x%04x...\n", flags);
     Parrot_io_eprintf(NULL, "PF_fetch_string(): charset_nr is %ld...\n",
@@ -732,7 +731,7 @@
     charset_name = Parrot_charset_c_name(interp, charset_nr);
     s = string_make(interp, (const char *)*cursor, size, charset_name, flags);
 
-#if TRACE_PACKFILE
+#if TRACE_PACKFILE == 2
     Parrot_io_eprintf(NULL, "PF_fetch_string(): string is: ");
     Parrot_io_putps(interp, Parrot_io_STDERR(interp), s);
     Parrot_io_eprintf(NULL, "\n");
