6048 RLIM_INFINITY (et al) should be unsigned for _LP64

Review Request #71 — Created July 4, 2015 and submitted — Latest diff uploaded

risto3
illumos-gate
6048
1d28bbc...
general

6048 RLIM_INFINITY (et al) should be unsigned for _LP64

building gcc with gcc for 64-bits (-m64) identifies an issue in /usr/include/sys/resource.h
with the definition of RLIM_INFINITY.

The warnings are:

../../gcc-4.9.3/libiberty/stack-limit.c: In function 'stack_limit_increase':
../../gcc-4.9.3/libiberty/stack-limit.c:53:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       && rlim.rlim_cur != RLIM_INFINITY
../../gcc-4.9.3/libiberty/stack-limit.c:55:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       && (rlim.rlim_max == RLIM_INFINITY || rlim.rlim_cur < rlim.rlim_max))
../../gcc-4.9.3/libiberty/stack-limit.c:58:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       if (rlim.rlim_max != RLIM_INFINITY && rlim.rlim_cur > rlim.rlim_max)

Currently the gate defines as follows:

#if defined(_LP64)

typedef unsigned long   rlim_t;

#define RLIM_INFINITY   (-3l)
#define RLIM_SAVED_MAX  (-2l)
#define RLIM_SAVED_CUR  (-1l)

#else   /* _LP64 */

/*
 * The definitions of the following types and constants differ between the
 * regular and large file compilation environments.
 */
#if _FILE_OFFSET_BITS == 32

typedef unsigned long   rlim_t;

#define RLIM_INFINITY   0x7fffffff
#define RLIM_SAVED_MAX  0x7ffffffe
#define RLIM_SAVED_CUR  0x7ffffffd

#else   /* _FILE_OFFSET_BITS == 32 */

typedef u_longlong_t    rlim_t;

#define RLIM_INFINITY   ((rlim_t)-3)
#define RLIM_SAVED_MAX  ((rlim_t)-2)
#define RLIM_SAVED_CUR  ((rlim_t)-1)

#endif  /* _FILE_OFFSET_BITS == 32 */

#endif  /* _LP64 */

Notice the omission of the cast '(rlim_t)' upon '-3l' for 64-bit RLIM_INFINITY.

I took this code piece to verify that the warnings go away if corrected

#include <stdint.h>
#include <sys/resource.h>

#ifdef OVERRIDE
#undef RLIM_INFINITY
#define RLIM_INFINITY ((rlim_t)-3)
#endif

void
stack_limit_increase (unsigned long pref)
{
  struct rlimit rlim;
  if (getrlimit (RLIMIT_STACK, &rlim) == 0
      && rlim.rlim_cur != RLIM_INFINITY
      && rlim.rlim_cur < pref
      && (rlim.rlim_max == RLIM_INFINITY || rlim.rlim_cur < rlim.rlim_max))
    {
      rlim.rlim_cur = pref;
      if (rlim.rlim_max != RLIM_INFINITY && rlim.rlim_cur > rlim.rlim_max)
    rlim.rlim_cur = rlim.rlim_max;
      setrlimit (RLIMIT_STACK, &rlim);
    }
}

which gives the following:

richard@omnis:/home/richard/src/tstack$ /opt/gcc-4.8.1/bin/gcc -m64 -c -o stack-limit.o stack-limit.c -W 
stack-limit.c: In function ‘stack_limit_increase’:
stack-limit.c:14:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       && rlim.rlim_cur != RLIM_INFINITY
                        ^
stack-limit.c:16:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       && (rlim.rlim_max == RLIM_INFINITY || rlim.rlim_cur < rlim.rlim_max))
                         ^
stack-limit.c:19:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       if (rlim.rlim_max != RLIM_INFINITY && rlim.rlim_cur > rlim.rlim_max)
                         ^
richard@omnis:/home/richard/src/tstack$ /opt/gcc-4.8.1/bin/gcc -m64 -c -o stack-limit.o stack-limit.c -W -DOVERRIDE
richard@omnis:/home/richard/src/tstack$ /opt/gcc-4.8.1/bin/gcc -m32 -c -o stack-limit.o stack-limit.c -W 
richard@omnis:/home/richard/src/tstack$ /opt/gcc-4.8.1/bin/gcc -m32 -c -o stack-limit.o stack-limit.c -W -DOVERRIDE
richard@omnis:/home/richard/src/tstack$

using -save-temps without and with -DOVERRIDE, the generated code is identical.

So the _LP64 definition should be corrected to correspond to the _FILE_OFFSET_BITS == 64 32-bit definition,

Loading...