Project

General

Profile

Bug #6048

RLIM_INFINITY (et al) should be unsigned for _LP64

Added by Richard PALO over 5 years ago. Updated over 5 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
-
Start date:
2015-07-03
Due date:
% Done:

100%

Estimated time:
Difficulty:
Bite-size
Tags:
needs-triage
Gerrit CR:

Description

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,
that is:

diff --git a/usr/src/uts/common/sys/resource.h b/usr/src/uts/common/sys/resource.h
index d69b23a..2d3800b 100644
--- a/usr/src/uts/common/sys/resource.h
+++ b/usr/src/uts/common/sys/resource.h
@@ -82,9 +82,9 @@ extern "C" {

 typedef        unsigned long   rlim_t;

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

 #else  /* _LP64 */

#1

Updated by Electric Monk over 5 years ago

  • Status changed from New to Closed
  • % Done changed from 0 to 100

git commit d007da4be6a31f5f7c6e3e822eef044a9ac6ae18

commit  d007da4be6a31f5f7c6e3e822eef044a9ac6ae18
Author: Richard PALO <richard@NetBSD.org>
Date:   2015-07-27T14:39:03.000Z

    6048 RLIM_INFINITY (et al) should be unsigned for _LP64
    Reviewed by: Robert Mustacchi <rm@joyent.com>
    Reviewed by: Andy Stormont <astormont@racktopsystems.com>
    Reviewed by: Toomas Soome <tsoome@me.com>
    Reviewed by: Igor Kozhukhov <ikozhukhov@gmail.com>
    Approved by: Dan McDonald <danmcd@omniti.com>

Also available in: Atom PDF