[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnu-arch-users] 64-bit cleaning [PATCH]

From: John Goerzen
Subject: [Gnu-arch-users] 64-bit cleaning [PATCH]
Date: Sat, 06 Sep 2003 15:59:11 -0500
User-agent: Gnus/5.1002 (Gnus v5.10.2) XEmacs/21.4 (Rational FORTRAN, linux)


I spent some time cleaning up tla to work well on 64-bit platforms.
Tom, I believe these patches should be applied to your tree if you

Archive: address@hidden

Two areas have patches, with names corresponding to Tom's archive:

All parts of tla except libneon were compiled with -Wall -Werror on
Alpha, a 64-bit platform, and appropriate changes made so that the
entire application builds with these settings.  In my experience
porting apps to Alpha, this typically finds 95% or better of
32-bit-isms.  (-Wall is very useful on gcc)

Problems Found
These were the most common problems:

 * Preprocessor directives using integer math for long computations.

   One area was trying to determine if a long was 8 bytes and did
   something akin to this in a #if:

   0xffffffff << 8 + 0xffffffff

   On Alpha, int is 32 bit and long is 64 bit.  That expression uses
   ints and thus overflows.  I just made it 0xffffffffLU, and that
   works fine.  (32-bit users don't hit that code due to
   #if statements)

 * Casting ints to void * and back (int is not the same size as
   pointers on Alpha)

   My fix: cast longs instead of ints since they are the same size
   on every modern Unix I'm aware of.

   (Some debate exists on the proper way to do this; some advocate
    the size_t type instead, but in my experience, long is most
    portable.  Ideally, though, ints should not be casted to pointers
    at all; a pointer to the int should be passed, or a union
    created to hold them both.  I tried to keep my changes as
    minimal as possible, and thus took neither of these actions.)

 * Using non-ints as args to printf precision specifiers
   printf takes only ints there.  cast as appropriate.

 * Using %d to format size_t args.
   Use #ifdef for C99; if present, use %z; else cast to long and use %ld

 * Missing #includes
   Sometimes you can get by with this on platforms where ints and
   pointers are the same size, as the compiler's implicit default
   will work because of that.  However, this behavior is far less
   reliable on platforms where they are different sizes.
   Fix: add appropriate #includes

These are all common problems in 32-bit code; nothing at all unusual
here.  Note that some of the things fixed may not have actually caused
me breakage, but they still have the potential to do so, and I believe
the fixes just.


 * The new tla seems to work for things that old one did not on Alpha
   -- archive-mirror for one.

 * Compiles without warnings or errors on Alpha, i386, and ia64 (Itanium).
   (libneon excepted)

 * Used for regular development with no problems.

 * Robert Collins' example problem does not exist on Alpha.

However, the segfault DID persist on ia64.  It may will be that the
fault lies with neon.


For hackerlab:

# do not edit -- automatically generated by arch changelog
# tag: address@hidden/hackerlab--devo--1.0

2003-09-06 18:13:14 GMT John Goerzen <address@hidden>   patch-12

      size_t standardization

    Several places in the code, the same variable (most often nsub) would be
    treated as size_t, and other places, as int.  I standardized all the code
    using nsub to use size_t as it is defined in POSIX.
    On some 64-bit platforms, size_t is not the same size as an int, so passing
    a pointer to an int to a function expecting a pointer to a size_t can be a
    Bad Thing.

    modified files:
     ./rx-posix/posix.c ./rx-posix/re8-parse.c
     ./rx-posix/re8-parse.h ./tests/rx-posix-tests/test-dbug.c

2003-09-06 14:30:17 GMT John Goerzen <address@hidden>   patch-11

      Added missing #includes

    unit-regex.c uses system's exit(); #include <stdlib.h>

    modified files:

2003-09-06 14:02:53 GMT John Goerzen <address@hidden>   patch-10

      Fixed more pointer <-> int casts

    See log for patch-6 for more details.

    modified files:

2003-09-06 13:58:44 GMT John Goerzen <address@hidden>   patch-9

      More printf formatting fixes

    (Same process as in patch-2)
    printf was attempting to use %d to print the resule of a sizeof(), a size_t
    argument.  This is not the same size arg on Alpha.  (sizeof() returns a
    long, but %d prints an int)
    Now, use a test... if C99 is available, render with %z.  Otherwise, cast it
    to an int and use %d.  (No need to cast to a long this time since sizeof is
    not going to be that big in this case!)

    modified files:

2003-09-06 13:53:23 GMT John Goerzen <address@hidden>   patch-8

      Added missing #include

    unit-alloc-limits.c and unit-must-malloc.c both use the system's time()
    call, but do not include time.h.  Fixed.

    modified files:

2003-09-06 04:30:25 GMT John Goerzen <address@hidden>   patch-7

      Cast field precision to int for printf; Fix inet_addr retval

    According to standards, field precisions must be specified as ints when
    they're given as args to printf with *.  Cast them as such.
    inet_addr() returns INADDR_NONE for invalid input.  On x86, this happens to
    be equal to -1 as seen in the code, but not necessarily elsewhere (it's
    really most places).  Fortunately, INADDR_NONE is provided
    to test this case, so I just modified the code to use that.

    modified files:
     ./cmd/opt.c ./vu-network/url-socket.c

2003-09-06 04:20:03 GMT John Goerzen <address@hidden>   patch-6

      Fixed pointer<->int casts

    On 32-bit i386 machines, casting pointers to ints works because both are 32
    bits.  However, there are more permutations than that out there.  These
    pointer size int size long size example platform
    ------------ -------- --------- ----------------
    32           32       32        i386
    64           32       64        Alpha
    64           64       64        Sparc64?  Itanium?
    In general, long is more likely to be the same size as the pointer, and
    while ideally the public interfaces of all functions that work with pointers
    in this way should be chnaged to use long, I wanted to keep my changes as
    minimal as possible.
    Therefore, I modified to code to, in some cases, cast things twice, to make
    sure I used a defined path.  On Alpha, for instance, casting from int to
    long is a defined process, and from long to void *, but from int to void *
    may work (if you're lucky).  So two casts will do it.

    modified files:
     ./rx/dfa-iso8859-1.c ./rx/dfa-utf16.c ./rx/dfa-utf8.c
     ./rx/dfa.c ./vu/vu-virtual-null.c

2003-09-06 03:44:02 GMT John Goerzen <address@hidden>   patch-5

      Add more missing #includes

    vu-sys.c: Include <stdio.h> for rename

    modified files:

2003-09-06 03:42:11 GMT John Goerzen <address@hidden>   patch-4

      Added missing #include for memcpy prototype

    vfdbuf.c calls the system's memcpy (hackerlab does not provide this), but
    fails to #include <string.h>.  Fixed.

    modified files:

2003-09-05 22:39:24 GMT John Goerzen <address@hidden>   patch-3

      Fixed a trigraph

    A conforming C compiler translates the sequence ??) to ] anywhere, including
    a string.  Escaped this sequence to prevent ambiguity and a gcc warning.

    modified files:

2003-09-05 22:02:01 GMT John Goerzen <address@hidden>   patch-2

      Fixed printf formatting

    printf was attempting to use %d to print a size_t argument.  This is not the
    same size arg on Alpha.
    Now, use a test... if C99 is available, render with %z.  Otherwise, cast it
    to a long and use %ld.

    modified files:

2003-09-05 21:50:30 GMT John Goerzen <address@hidden>   patch-1

      64-bit: Fix long size tests

    Several files here used expressions like this to test for the size of long:
      0xffffffff << n
    On Alpha, int is 4 bytes and long is 8.  The above code generates an int at
    its maximum, then tries to make it larger, which overflows the preprocessor.
    I changed it to 0xffffffffUL, which makes the system treat it as an unsigned
    long from the start, leading to the desired result.
    I am as yet unclear as to why this test is even needed, given that configure
    has already detected this and sizeof(long) could always be used...

    modified files:
     ./bitsets/bitset.h ./machine/types.h

2003-09-05 19:56:43 GMT John Goerzen <address@hidden>   base-0

      tag of address@hidden/hackerlab--devo--1.0--patch-21

    (automatically generated log message)

    new patches:


For tla:

# do not edit -- automatically generated by arch changelog
# tag: address@hidden/tla--devo--1.1

2003-09-06 18:29:36 GMT John Goerzen <address@hidden>   patch-3

      Fix pointer casting, missing includes, printf precision

    Include time.h due to call to system's time()
    Fix casting int to void *
    More printf precision casting to ints

    modified files:
     ./libarch/commit.c ./libarch/import.c ./libarch/library-txn.c
     ./libarch/replay.c ./libarch/star-merge.c ./libarch/undo.c

2003-09-06 18:25:20 GMT John Goerzen <address@hidden>   patch-2

      Fix some strings and printf precision

    Cast all printf precicions to ints.
    Eliminate ambiguous trigraphs by escaping question marks.

    modified files:
     ./libarch/changelogs.c ./libarch/cmd-ancestry.c
     ./libarch/cmd-help.c ./libarch/cmd-my-id.c ./libarch/commit.c

2003-09-06 18:18:26 GMT John Goerzen <address@hidden>   patch-1

      Fixed int cast to void *

    Cast to long first, which is the same size as void * more places.

    modified files:

2003-09-05 16:28:35 GMT John Goerzen <address@hidden>   base-0

      tag of address@hidden/tla--devo--1.1--patch-153

    (automatically generated log message)

    new patches:

reply via email to

[Prev in Thread] Current Thread [Next in Thread]