Ticket #254: tt254-64bit-2.patch

File tt254-64bit-2.patch, 12.9 KB (added by rurban, 13 years ago)

This fixes now the 64bit issues. one major, one minor bug

  • src/packfile.c

    old new  
    148148PARROT_CANNOT_RETURN_NULL 
    149149static const opcode_t * directory_unpack(PARROT_INTERP, 
    150150    ARGMOD(PackFile_Segment *segp), 
    151     ARGIN(const opcode_t *cursor)) 
     151    ARGMOD(opcode_t *cursor)) 
    152152        __attribute__nonnull__(1) 
    153153        __attribute__nonnull__(2) 
    154154        __attribute__nonnull__(3) 
    155         FUNC_MODIFIES(*segp); 
     155        FUNC_MODIFIES(*segp) 
     156        FUNC_MODIFIES(*cursor); 
    156157 
    157158PARROT_WARN_UNUSED_RESULT 
    158159PARROT_CAN_RETURN_NULL 
     
    453454    extern int Parrot_exec_run; 
    454455#endif 
    455456 
    456 /* TODO: This is broken on 64/32 transformations. See TT #254 */ 
    457 #define ROUND_16(val) (((val) & 0xf) ? 16 - ((val) & 0xf) : 0) 
    458 #define ALIGN_16(st, cursor) \ 
    459     (cursor) += ROUND_16((const char *)(cursor) - (const char *)(st))/sizeof (opcode_t) 
    460457/* offset not in ptr diff, but in byte */ 
    461 #define OFFS(cursor) ((pf) ? ((const char *)(cursor) - (const char *)(pf->src)) : 0) 
     458#define OFFS(pf, cursor) ((pf) ? ((const char *)(cursor) - (const char *)(pf->src)) : 0) 
     459/** 
     460 * Possible values for ALIGN_16 
     461 *   4 (32bit): 0 1 2 3 
     462 *   8 (64bit): 0 1 
     463 * e.g. reading 4 byte wordsize on 8 byte wordsize: possible ptrs end in 0 4 8 c. 
     464 *   offs(c)/8 => 4/8 = 0 => impossible to align with 8 byte ptr. 
     465 * Limitation TT #254: ALIGN_16  may only be used native, e.g. in the writer, 
     466 * but not with 64bit reading 32bit! 
     467 */ 
     468#define ROUND_16(val) (((val) & 0xf) ? 16 - ((val) & 0xf) : 0) 
     469#define ALIGN_16(pf, cursor)                                    \ 
     470    (cursor) += ROUND_16(OFFS(pf, cursor))/sizeof (opcode_t) 
     471/* pad to 16 in bytes */ 
     472#define PAD_16_B(size) ((size) % 16 ? 16 - (size) % 16 : 0) 
    462473 
    463474#if TRACE_PACKFILE 
    464475void 
     
    854865    ASSERT_ARGS(do_sub_pragmas) 
    855866    PackFile_FixupTable * const ft = self->fixups; 
    856867    PackFile_ConstTable * const ct = self->const_table; 
    857 #if TRACE_PACKFILE 
    858868    PackFile            * const pf = self->base.pf; 
    859 #endif 
    860869    opcode_t i; 
    861870 
    862871    TRACE_PRINTF(("PackFile: do_sub_pragmas (action=%d)\n", action)); 
     
    9971006    } 
    9981007    else if (header->uuid_type == 1) { 
    9991008        /* Read in the UUID. We'll put it in a NULL-terminated string, just in 
    1000          * case pepole use it that way. */ 
     1009         * case people use it that way. */ 
    10011010        header->uuid_data = (unsigned char *) 
    10021011            mem_sys_allocate(header->uuid_size + 1); 
    10031012 
     
    10151024    /* Set cursor to position after what we've read, allowing for padding to a 
    10161025     * 16 byte boundary. */ 
    10171026    header_read_length  = PACKFILE_HEADER_BYTES + header->uuid_size; 
    1018     header_read_length += header_read_length % 16 ? 
    1019         16 - header_read_length % 16 : 0; 
     1027    header_read_length += PAD_16_B(header_read_length); 
    10201028    cursor              = packed + (header_read_length / sizeof (opcode_t)); 
     1029    TRACE_PRINTF(("PackFile_unpack: pad=%d\n", 
     1030                  (char *)cursor - (char *)packed)); 
    10211031 
    10221032    /* Set what transforms we need to do when reading the rest of the file. */ 
    10231033    PackFile_assign_transforms(self); 
     
    14451455    } 
    14461456    else { 
    14471457        int i; 
     1458        TRACE_PRINTF(("default_unpack: pre-fetch %d ops into data\n", 
     1459                      self->size)); 
    14481460        for (i = 0; i < (int)self->size; i++) { 
    14491461            self->data[i] = PF_fetch_opcode(self->pf, &cursor); 
    14501462            TRACE_PRINTF(("default_unpack: transformed op[#%d]/%d %u\n", 
     
    17841796        ARGIN(opcode_t *cursor)) 
    17851797{ 
    17861798    ASSERT_ARGS(PackFile_Segment_pack) 
    1787     const size_t align             = 16 / sizeof (opcode_t); 
     1799    /*const size_t align             = 16 / sizeof (opcode_t);*/ 
    17881800    PackFile_Segment_pack_func_t f = 
    17891801        self->pf->PackFuncs[self->type].pack; 
     1802#if TRACE_PACKFILE 
     1803    PackFile * const pf  = self->pf; 
     1804#endif 
    17901805 
    17911806    cursor = default_pack(self, cursor); 
    17921807 
    17931808    if (f) 
    17941809        cursor = (f)(interp, self, cursor); 
    17951810 
    1796     if (align && (cursor - self->pf->src) % align) 
    1797         cursor += align - (cursor - self->pf->src) % align; 
     1811    TRACE_PRINTF_ALIGN(("-ALIGN_16: offset=0x%x src=0x%x cursor=0x%x\n", 
     1812                        OFFS(pf, cursor), pf->src, cursor)); 
     1813    ALIGN_16(self->pf, cursor); 
     1814    /*if (align && (cursor - self->pf->src) % align) 
     1815      cursor += align - (cursor - self->pf->src) % align;*/ 
     1816    TRACE_PRINTF_ALIGN(("+ALIGN_16: offset=0x%x src=0x%x cursor=0x%x\n", 
     1817                      OFFS(pf, cursor), pf->src, cursor)); 
    17981818 
    17991819    return cursor; 
    18001820} 
     
    18241844{ 
    18251845    ASSERT_ARGS(PackFile_Segment_unpack) 
    18261846    PackFile_Segment_unpack_func_t f = self->pf->PackFuncs[self->type].unpack; 
     1847    int offs; 
    18271848#if TRACE_PACKFILE 
    18281849    PackFile * const pf  = self->pf; 
    18291850#endif 
     
    18411862            return NULL; 
    18421863    } 
    18431864 
    1844     TRACE_PRINTF_ALIGN(("-ALIGN_16: offset=0x%x src=0x%x cursor=0x%x\n", 
    1845                       OFFS(cursor), pf->src, cursor)); 
    1846     /* FIXME on 64bit reading 32bit */ 
    1847     ALIGN_16(self->pf->src, cursor); 
    1848     TRACE_PRINTF_ALIGN(("+ALIGN_16: offset=0x%x src=0x%x cursor=0x%x\n", 
    1849                       OFFS(cursor), pf->src, cursor)); 
     1865    offs = OFFS(self->pf, cursor); 
     1866    TRACE_PRINTF_ALIGN(("-S ALIGN_16: offset=0x%x src=0x%x cursor=0x%x\n", 
     1867                        offs, self->pf->src, cursor)); 
     1868    offs += PAD_16_B(offs); 
     1869    cursor = (const char *)(self->pf->src) + offs; 
     1870    TRACE_PRINTF_ALIGN(("+S ALIGN_16: offset=0x%x src=0x%x cursor=0x%x\n", 
     1871                        offs, self->pf->src, cursor)); 
    18501872    return cursor; 
    18511873} 
    18521874 
     
    19511973PARROT_WARN_UNUSED_RESULT 
    19521974PARROT_CANNOT_RETURN_NULL 
    19531975static const opcode_t * 
    1954 directory_unpack(PARROT_INTERP, ARGMOD(PackFile_Segment *segp), ARGIN(const opcode_t *cursor)) 
     1976directory_unpack(PARROT_INTERP, ARGMOD(PackFile_Segment *segp), ARGMOD(opcode_t *cursor)) 
    19551977{ 
    19561978    ASSERT_ARGS(directory_unpack) 
    19571979    PackFile_Directory * const dir = (PackFile_Directory *) segp; 
    19581980    PackFile           * const pf  = dir->base.pf; 
    19591981    const opcode_t            *pos; 
    19601982    size_t                     i; 
     1983    int                        offs; 
    19611984 
    19621985    dir->num_segments = PF_fetch_opcode(pf, &cursor); 
    19631986    TRACE_PRINTF(("directory_unpack: %ld num_segments\n", dir->num_segments)); 
     
    20032026                return 0; 
    20042027            } 
    20052028            TRACE_PRINTF_VAL(("Segment offset: new pos 0x%x " 
    2006                 "(src=0x%x cursor=0x%x).\n", pos - pf->src, pf->src, cursor)); 
     2029                              "(src=0x%x cursor=0x%x).\n", 
     2030                              OFFS(pf, pos), pf->src, cursor)); 
    20072031        } 
    20082032        else 
    20092033            pos = pf->src + seg->file_offset; 
     
    20302054        seg->dir         = dir; 
    20312055    } 
    20322056 
     2057    offs = OFFS(pf, cursor); 
    20332058    TRACE_PRINTF_ALIGN(("-ALIGN_16: offset=0x%x src=0x%x cursor=0x%x\n", 
    2034                       OFFS(cursor), pf->src, cursor)); 
    2035     /* FIXME on 64bit reading 32bit */ 
    2036     ALIGN_16(pf->src, cursor); 
     2059                      offs, pf->src, cursor)); 
     2060    offs += PAD_16_B(offs); 
     2061    cursor = (const char *)(pf->src) + offs; 
    20372062    TRACE_PRINTF_ALIGN(("+ALIGN_16: offset=0x%x src=0x%x cursor=0x%x\n", 
    2038                       OFFS(cursor), pf->src, cursor)); 
     2063                      offs, pf->src, cursor)); 
    20392064 
    20402065    /* and now unpack contents of dir */ 
    20412066    for (i = 0; cursor && i < dir->num_segments; i++) { 
     
    20732098        else 
    20742099            delta = pos - cursor; 
    20752100 
    2076         TRACE_PRINTF_VAL(("  delta=%d pos=0x%x cursor=0x%x\n", 
     2101        TRACE_PRINTF_VAL(("  delta=%d, pos=0x%x, cursor=0x%x\n", 
    20772102                          delta, pos, cursor)); 
    20782103 
    20792104        if ((size_t)delta != tmp || dir->segments[i]->op_count != tmp) 
     
    22332258    ASSERT_ARGS(directory_pack) 
    22342259    PackFile_Directory * const dir      = (PackFile_Directory *)self; 
    22352260    const size_t               num_segs = dir->num_segments; 
    2236     const size_t               align    = 16/sizeof (opcode_t); 
     2261    /*const size_t               align    = 16/sizeof (opcode_t);*/ 
    22372262    size_t i; 
     2263    PackFile           * const pf       = self->pf; 
    22382264 
    22392265    *cursor++ = num_segs; 
    22402266 
     
    22462272        *cursor++ = seg->op_count; 
    22472273    } 
    22482274 
    2249     if (align && (cursor - self->pf->src) % align) 
    2250         cursor += align - (cursor - self->pf->src) % align; 
     2275    TRACE_PRINTF_ALIGN(("-ALIGN_16: offset=0x%x src=0x%x cursor=0x%x\n", 
     2276                      OFFS(pf, cursor), pf->src, cursor)); 
     2277    ALIGN_16(pf, cursor); 
     2278    TRACE_PRINTF_ALIGN(("+ALIGN_16: offset=0x%x src=0x%x cursor=0x%x\n", 
     2279                      OFFS(pf, cursor), pf->src, cursor)); 
     2280    /*if (align && (cursor - self->pf->src) % align) 
     2281      cursor += align - (cursor - self->pf->src) % align;*/ 
    22512282 
    22522283    /* now pack all segments into new format */ 
    22532284    for (i = 0; i < dir->num_segments; i++) { 
  • src/packfile/pf_items.c

    old new  
    231231/* 
    232232 * offset not in ptr diff, but in byte 
    233233 */ 
    234 #define OFFS(cursor) ((pf) ? ((const char *)(cursor) - (const char *)(pf->src)) : 0) 
     234#define OFFS(pf, cursor) ((pf) ? ((const char *)(cursor) - (const char *)(pf->src)) : 0) 
    235235 
    236236/* 
    237237 * low level FLOATVAL fetch and convert functions 
     
    456456 
    457457Converts IEEE 754 16-byte long double to IEEE 754 8 byte double. 
    458458 
    459 Tested ok. 
     459First variant ok, 2nd not ok. 
    460460 
    461461=cut 
    462462 
     
    478478 
    479479    } 
    480480    else { 
    481  
     481        /* FIXME: This codepath fails */ 
    482482        int expo, i, s; 
    483483#ifdef __LCC__ 
    484484        int expo2; 
     
    970970    fetch_buf_le_4(u.buf, b); 
    971971#if PARROT_BIGENDIAN 
    972972#  if OPCODE_T_SIZE == 8 
    973     return u.o >> 32; 
     973    return (Parrot_Int4)(u.o >> 32); 
    974974#  else 
    975975    return (opcode_t) fetch_iv_be((INTVAL)u.o); 
    976976#  endif 
    977977#else 
    978978#  if OPCODE_T_SIZE == 8 
    979     return u.o & 0xffffffff; 
     979    /* without the cast we would not get a negative int, the vtable indices */ 
     980    return (Parrot_Int4)(u.o & 0xffffffff); 
    980981#  else 
    981982    return u.o; 
    982983#  endif 
     
    10371038        return *(*stream)++; 
    10381039    o = (pf->fetch_op)(*((const unsigned char **)stream)); 
    10391040    TRACE_PRINTF_VAL(("  PF_fetch_opcode: 0x%lx (%ld), at 0x%x\n", 
    1040                       o, o, OFFS(*stream))); 
     1041                      o, o, OFFS(pf, *stream))); 
    10411042    *((const unsigned char **) (stream)) += pf->header->wordsize; 
    10421043    return o; 
    10431044} 
     
    11071108        return *(*stream)++; 
    11081109    i = (pf->fetch_iv)(*((const unsigned char **)stream)); 
    11091110    TRACE_PRINTF_VAL(("  PF_fetch_integer: 0x%x (%d) at 0x%x\n", i, i, 
    1110                       OFFS(*stream))); 
     1111                      OFFS(pf, *stream))); 
    11111112    /* XXX assume sizeof (opcode_t) == sizeof (INTVAL) on the 
    11121113     * machine producing this PBC. 
    11131114     * 
     
    11821183        TRACE_PRINTF(("PF_fetch_number: Native [%d bytes]\n", 
    11831184                      sizeof (FLOATVAL))); 
    11841185        memcpy(&f, (const char *)*stream, sizeof (FLOATVAL)); 
    1185         TRACE_PRINTF_VAL(("PF_fetch_number: %f at 0x%x\n", f, OFFS(*stream))); 
     1186        TRACE_PRINTF_VAL(("PF_fetch_number: %f at 0x%x\n", f, OFFS(pf, *stream))); 
    11861187        (*stream) += (sizeof (FLOATVAL) + sizeof (opcode_t) - 1)/ 
    11871188            sizeof (opcode_t); 
    11881189        return f; 
    11891190    } 
    11901191    f = (FLOATVAL) 0; 
    1191     TRACE_PRINTF(("PF_fetch_number at 0x%x: Converting...\n", OFFS(*stream))); 
     1192    TRACE_PRINTF(("PF_fetch_number at 0x%x: Converting...\n", OFFS(pf, *stream))); 
    11921193    /* 12->8 has a messy cast. */ 
    11931194    if (NUMVAL_SIZE == 8 && pf->header->floattype == FLOATTYPE_12) { 
    11941195        (pf->fetch_nv)((unsigned char *)&d, (const unsigned char *) *stream); 
     
    13091310 
    13101311    /* print only printable characters */ 
    13111312    TRACE_PRINTF_VAL(("PF_fetch_string(): string is '%s' at 0x%x\n", 
    1312                       s->strstart, OFFS(*cursor))); 
     1313                      s->strstart, OFFS(pf, *cursor))); 
    13131314 
    13141315/*    s = string_make(interp, *cursor, size, 
    13151316            encoding_lookup_index(encoding), 
     
    13181319                        (const char *)*cursor + size, size, wordsize)); 
    13191320    size = ROUND_UP_B(size, wordsize); 
    13201321    TRACE_PRINTF(("PF_fetch_string(): round size up to %ld.\n", size)); 
    1321     *((const unsigned char **) (cursor)) += size; 
     1322    *((const unsigned char **)(cursor)) += size; 
    13221323    TRACE_PRINTF_ALIGN(("+s ROUND_UP_B: cursor=0x%x, size=%d\n", *cursor, size)); 
    13231324    return s; 
    13241325} 
     
    14321433    TRACE_PRINTF(("PF_fetch_cstring(): size is %ld...\n", str_len)); 
    14331434    strcpy(p, (const char*) (*cursor)); 
    14341435    TRACE_PRINTF_VAL(("PF_fetch_cstring(): string is '%s' at 0x%x\n", 
    1435                       p, OFFS(*cursor))); 
     1436                      p, OFFS(pf, *cursor))); 
    14361437    TRACE_PRINTF_ALIGN(("-s ROUND_UP_B: cursor=0x%x, size=%d, wordsize=%d (cstring)\n", 
    14371438                        *cursor, str_len, wordsize)); 
    14381439    *((const unsigned char **) (cursor)) += ROUND_UP_B(str_len, wordsize); 
    14391440    TRACE_PRINTF_ALIGN(("+s ROUND_UP_B: cursor=0x%x, offset=0x%x\n", 
    1440                         *cursor, OFFS(*cursor))); 
     1441                        *cursor, OFFS(pf, *cursor))); 
    14411442 
    14421443    return p; 
    14431444}