summary refs log tree commit diff
diff options
context:
space:
mode:
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>2016-10-18 09:41:56 -0200
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2016-11-17 15:54:22 -0200
commit045c13d18554ae626dfc62f392afb33856c6321d (patch)
tree64964d765a91d1364bbef9838374d67ba4179d39
parentc440d5d58ddef2975d0630bcb0e757d7e697496e (diff)
downloadglibc-045c13d18554ae626dfc62f392afb33856c6321d.tar.gz
glibc-045c13d18554ae626dfc62f392afb33856c6321d.tar.xz
glibc-045c13d18554ae626dfc62f392afb33856c6321d.zip
Consolidate Linux setrlimit and getrlimit implementation
This patch consolidates all Linux setrlimit and getrlimit on the default
sysdeps/unix/sysv/linux/{set,get}rlimit{64}.c.  It contains two exceptions:

  1. mips32 and mips64n32 which requires a versioned symbol for GLIBC 2.19
     and higher due a broken RLIM64_INFINITY constant.
  2. sparc32 does not define a compat symbol for getrlimit64 for old 2GB
     limit. I am not sure if it is required, but a RLIM_INFINITY fix [1]
     change its definition without adding a compat symbol.  This patch does
     not aim to address this possible issue, it follow current symbol
     export.

The default implementation uses prlimit64 for 64 bit rlim_t ({set,get}rlimit64)
and if it fails with ENOSYS it fall back to {get,set}rlimit syscall.  This
code path is only used on kernel older than 2.6.36 (basically now only x86)
and I avoid to user __ASSUME_PRLIMTI64 to simplify the implementation.  Once
x86 moves to be on par with other architectures regarding minimum kernel
supported we can get rid of using old syscalls and default path.

A new type size define is added, __RLIM_T_MATCHES_RLIM64_T, where is set as
default for 64 bits ports.  This allows the default implementation to avoid
{get,set}rlimit building and alias {get,set}rlimit64 to {get,set}rlimit.

Checked on x86_64, i386, armhf, aarch64, and powerpc64le.  I also did a
sanity build plus check-abi on all other supported architectures.

[1] Commit 9c96ff23858b0759e12ad69e3c4599931c90bee8

	Adhemerval Zanella  <adhemerval.zanella@linaro.org>
	Yury Norov  <ynorov@caviumnetworks.com>

	* bits/typesizes.h (__RLIM_T_MATCHES_RLIM64_T): define.
	* sysdeps/unix/sysv/linux/alpha/bits/typesizes.h
	(__RLIM_T_MATCHES_RLIM64_T): Likewise.
	* sysdeps/unix/sysv/linux/generic/bits/typesizes.h
	(__RLIM_T_MATCHES_RLIM64_T): Likewise.
	* sysdeps/unix/sysv/linux/s390/bits/typesizes.h [__s390x__]
	(__RLIM_T_MATCHES_RLIM64_T): Likewise.
	* sysdeps/unix/sysv/linux/sparc/bits/typesizes.h
	[__arch64__ || __sparcv9] (__RLIM_T_MATCHES_RLIM64_T): Likewise.
	* sysdeps/unix/sysv/linux/x86/bits/typesizes.h [__86_64__]
	(__RLIM_T_MATCHES_RLIM64_T): Likewise.
	* sysdeps/unix/sysv/linux/arm/Makefile [$(subdir) = resource]
	(sysdep_routines): Remove oldgetrlimit64.
	* sysdeps/unix/sysv/linux/i386/Makefile [$(subdir) = resource]
	(sysdep_routines): Likewise.
	* sysdeps/unix/sysv/linux/m68k/Makefile [$(subdir) = resource]
	(sysdep_routines): Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/Makefile
	[$(subdir) = resource] (sysdep_routines): Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/Makefile
	[$(subdir) = resource] (sysdep_routines): Likewise.
	* sysdeps/unix/sysv/linux/arm/getrlimit64.c: Remove file.
	* sysdeps/unix/sysv/linux/arm/oldgetrlimit64.c: Likewise.
	* sysdeps/unix/sysv/linux/hppa/getrlimit64.c: Likewise.
	* sysdeps/unix/sysv/linux/i386/getrlimit64.c: Likewise.
	* sysdeps/unix/sysv/linux/i386/oldgetrlimit64.c: Likewise.
	* sysdeps/unix/sysv/linux/m68k/getrlimit64.c: Likewise.
	* sysdeps/unix/sysv/linux/m68k/oldgetrlimit64.c: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/getrlimit64.c: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/oldgetrlimit64.c: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/getrlimit64.c: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/oldgetrlimit64.c: Likewise.
	* sysdeps/unix/sysv/linux/sh/getrlimit64.c: Likewise.
	* sysdeps/unix/sysv/linux/wordsize-64/getrlimit64.c: Likewise.
	* sysdeps/unix/sysv/linux/wordsize-64/setrlimit64.c: Likewise.
	* sysdeps/sysv/linux/generic/wordsize-32/syscalls.list: Remove
	setrlimit and getrlimit.
	* sysdeps/unix/sysv/linux/hppa/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/i386/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/m68k/m680x0/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc32/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/wordsize-64/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/getrlimit.c: New file.
	* sysdeps/unix/sysv/linux/sparc/getrlimit64.c: Likewise.
	* sysdeps/unix/sysv/linux/setrlimit.c: Likewise.
	* sysdeps/unix/sysv/linux/getrlimit64.c (__getrlimit64): Handle
	__RLIM_T_MATCHES_RLIM64_T and add alias if defined.
	(__old_getrlimit64): Add compatibility symbol.
	* sysdeps/unix/sysv/linux/setrlimit64.c (__setrlimit): Likewise.
-rw-r--r--ChangeLog59
-rw-r--r--bits/typesizes.h5
-rw-r--r--sysdeps/unix/sysv/linux/alpha/bits/typesizes.h3
-rw-r--r--sysdeps/unix/sysv/linux/arm/Makefile4
-rw-r--r--sysdeps/unix/sysv/linux/arm/getrlimit64.c1
-rw-r--r--sysdeps/unix/sysv/linux/arm/oldgetrlimit.c1
-rw-r--r--sysdeps/unix/sysv/linux/arm/oldgetrlimit64.c1
-rw-r--r--sysdeps/unix/sysv/linux/arm/oldsetrlimit.c1
-rw-r--r--sysdeps/unix/sysv/linux/generic/bits/typesizes.h5
-rw-r--r--sysdeps/unix/sysv/linux/generic/wordsize-32/syscalls.list2
-rw-r--r--sysdeps/unix/sysv/linux/getrlimit.c56
-rw-r--r--sysdeps/unix/sysv/linux/getrlimit64.c86
-rw-r--r--sysdeps/unix/sysv/linux/hppa/getrlimit64.c1
-rw-r--r--sysdeps/unix/sysv/linux/hppa/syscalls.list2
-rw-r--r--sysdeps/unix/sysv/linux/i386/Makefile4
-rw-r--r--sysdeps/unix/sysv/linux/i386/oldgetrlimit64.c57
-rw-r--r--sysdeps/unix/sysv/linux/i386/syscalls.list2
-rw-r--r--sysdeps/unix/sysv/linux/m68k/Makefile4
-rw-r--r--sysdeps/unix/sysv/linux/m68k/getrlimit64.c1
-rw-r--r--sysdeps/unix/sysv/linux/m68k/m680x0/syscalls.list4
-rw-r--r--sysdeps/unix/sysv/linux/m68k/oldgetrlimit64.c1
-rw-r--r--sysdeps/unix/sysv/linux/powerpc/getrlimit64.c1
-rw-r--r--sysdeps/unix/sysv/linux/powerpc/oldgetrlimit64.c1
-rw-r--r--sysdeps/unix/sysv/linux/powerpc/powerpc32/Makefile4
-rw-r--r--sysdeps/unix/sysv/linux/powerpc/powerpc32/syscalls.list4
-rw-r--r--sysdeps/unix/sysv/linux/powerpc/powerpc64/syscalls.list3
-rw-r--r--sysdeps/unix/sysv/linux/s390/bits/typesizes.h5
-rw-r--r--sysdeps/unix/sysv/linux/s390/s390-32/Makefile4
-rw-r--r--sysdeps/unix/sysv/linux/s390/s390-32/getrlimit64.c1
-rw-r--r--sysdeps/unix/sysv/linux/s390/s390-32/oldgetrlimit64.c1
-rw-r--r--sysdeps/unix/sysv/linux/s390/s390-32/syscalls.list3
-rw-r--r--sysdeps/unix/sysv/linux/setrlimit.c64
-rw-r--r--sysdeps/unix/sysv/linux/setrlimit64.c48
-rw-r--r--sysdeps/unix/sysv/linux/sh/getrlimit64.c1
-rw-r--r--sysdeps/unix/sysv/linux/sparc/bits/typesizes.h5
-rw-r--r--sysdeps/unix/sysv/linux/sparc/getrlimit64.c (renamed from sysdeps/unix/sysv/linux/i386/getrlimit64.c)13
-rw-r--r--sysdeps/unix/sysv/linux/sparc/sparc32/syscalls.list2
-rw-r--r--sysdeps/unix/sysv/linux/syscalls.list1
-rw-r--r--sysdeps/unix/sysv/linux/wordsize-64/getrlimit64.c1
-rw-r--r--sysdeps/unix/sysv/linux/wordsize-64/setrlimit64.c1
-rw-r--r--sysdeps/unix/sysv/linux/wordsize-64/syscalls.list2
-rw-r--r--sysdeps/unix/sysv/linux/x86/bits/typesizes.h5
42 files changed, 323 insertions, 147 deletions
diff --git a/ChangeLog b/ChangeLog
index 721ea68d24..330a631331 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,62 @@
+2016-11-17  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
+	    Yury Norov  <ynorov@caviumnetworks.com>
+
+	* bits/typesizes.h (__RLIM_T_MATCHES_RLIM64_T): define.
+	* sysdeps/unix/sysv/linux/alpha/bits/typesizes.h
+	(__RLIM_T_MATCHES_RLIM64_T): Likewise.
+	* sysdeps/unix/sysv/linux/generic/bits/typesizes.h
+	(__RLIM_T_MATCHES_RLIM64_T): Likewise.
+	* sysdeps/unix/sysv/linux/s390/bits/typesizes.h [__s390x__]
+	(__RLIM_T_MATCHES_RLIM64_T): Likewise.
+	* sysdeps/unix/sysv/linux/sparc/bits/typesizes.h
+	[__arch64__ || __sparcv9] (__RLIM_T_MATCHES_RLIM64_T): Likewise.
+	* sysdeps/unix/sysv/linux/x86/bits/typesizes.h [__86_64__]
+	(__RLIM_T_MATCHES_RLIM64_T): Likewise.
+	* sysdeps/unix/sysv/linux/arm/Makefile [$(subdir) = resource]
+	(sysdep_routines): Remove oldgetrlimit64.
+	* sysdeps/unix/sysv/linux/i386/Makefile [$(subdir) = resource]
+	(sysdep_routines): Likewise.
+	* sysdeps/unix/sysv/linux/m68k/Makefile [$(subdir) = resource]
+	(sysdep_routines): Likewise.
+	* sysdeps/unix/sysv/linux/powerpc/powerpc32/Makefile
+	[$(subdir) = resource] (sysdep_routines): Likewise.
+	* sysdeps/unix/sysv/linux/s390/s390-32/Makefile
+	[$(subdir) = resource] (sysdep_routines): Likewise.
+	* sysdeps/unix/sysv/linux/arm/getrlimit64.c: Remove file.
+	* sysdeps/unix/sysv/linux/arm/oldgetrlimit64.c: Likewise.
+	* sysdeps/unix/sysv/linux/arm/oldgetrlimit.c: Likewise.
+	* sysdeps/unix/sysv/linux/arm/oldsetrlimit.c: Likewise.
+	* sysdeps/unix/sysv/linux/hppa/getrlimit64.c: Likewise.
+	* sysdeps/unix/sysv/linux/i386/getrlimit64.c: Likewise.
+	* sysdeps/unix/sysv/linux/i386/oldgetrlimit64.c: Likewise.
+	* sysdeps/unix/sysv/linux/m68k/getrlimit64.c: Likewise.
+	* sysdeps/unix/sysv/linux/m68k/oldgetrlimit64.c: Likewise.
+	* sysdeps/unix/sysv/linux/powerpc/getrlimit64.c: Likewise.
+	* sysdeps/unix/sysv/linux/powerpc/oldgetrlimit64.c: Likewise.
+	* sysdeps/unix/sysv/linux/s390/s390-32/getrlimit64.c: Likewise.
+	* sysdeps/unix/sysv/linux/s390/s390-32/oldgetrlimit64.c: Likewise.
+	* sysdeps/unix/sysv/linux/sh/getrlimit64.c: Likewise.
+	* sysdeps/unix/sysv/linux/wordsize-64/getrlimit64.c: Likewise.
+	* sysdeps/unix/sysv/linux/wordsize-64/setrlimit64.c: Likewise.
+	* sysdeps/sysv/linux/generic/wordsize-32/syscalls.list: Remove
+	setrlimit and getrlimit.
+	* sysdeps/unix/sysv/linux/hppa/syscalls.list: Likewise.
+	* sysdeps/unix/sysv/linux/i386/syscalls.list: Likewise.
+	* sysdeps/unix/sysv/linux/m68k/m680x0/syscalls.list: Likewise.
+	* sysdeps/unix/sysv/linux/powerpc/powerpc32/syscalls.list: Likewise.
+	* sysdeps/unix/sysv/linux/powerpc/powerpc64/syscalls.list: Likewise.
+	* sysdeps/unix/sysv/linux/s390/s390-32/syscalls.list: Likewise.
+	* sysdeps/unix/sysv/linux/sparc/sparc32/syscalls.list: Likewise.
+	* sysdeps/unix/sysv/linux/syscalls.list: Likewise.
+	* sysdeps/unix/sysv/linux/wordsize-64/syscalls.list: Likewise.
+	* sysdeps/unix/sysv/linux/getrlimit.c: New file.
+	* sysdeps/unix/sysv/linux/sparc/getrlimit64.c: Likewise.
+	* sysdeps/unix/sysv/linux/setrlimit.c: Likewise.
+	* sysdeps/unix/sysv/linux/getrlimit64.c (__getrlimit64): Handle
+	__RLIM_T_MATCHES_RLIM64_T and add alias if defined.
+	(__old_getrlimit64): Add compatibility symbol.
+	* sysdeps/unix/sysv/linux/setrlimit64.c (__setrlimit): Likewise.
+
 2016-11-17  Joseph Myers  <joseph@codesourcery.com>
 
 	* scripts/build-many-glibcs.py (Config.build_gcc): Configure with
diff --git a/bits/typesizes.h b/bits/typesizes.h
index 53047b8531..ff20601046 100644
--- a/bits/typesizes.h
+++ b/bits/typesizes.h
@@ -69,6 +69,11 @@
 
 /* Same for ino_t and ino64_t.  */
 # define __INO_T_MATCHES_INO64_T	1
+
+/* And for rlim_t and rlim64_t.  */
+# define __RLIM_T_MATCHES_RLIM64_T	1
+#else
+# define __RLIM_T_MATCHES_RLIM64_T	0
 #endif
 
 /* Number of descriptors that can fit in an `fd_set'.  */
diff --git a/sysdeps/unix/sysv/linux/alpha/bits/typesizes.h b/sysdeps/unix/sysv/linux/alpha/bits/typesizes.h
index 3cfd887c39..ce96501bdb 100644
--- a/sysdeps/unix/sysv/linux/alpha/bits/typesizes.h
+++ b/sysdeps/unix/sysv/linux/alpha/bits/typesizes.h
@@ -66,6 +66,9 @@
    for C type-checking purposes.  */
 #define __OFF_T_MATCHES_OFF64_T	1
 
+/* And for __rlim_t and __rlim64_t.  */
+#define __RLIM_T_MATCHES_RLIM64_T 1
+
 /* Number of descriptors that can fit in an `fd_set'.  */
 #define	__FD_SETSIZE		1024
 
diff --git a/sysdeps/unix/sysv/linux/arm/Makefile b/sysdeps/unix/sysv/linux/arm/Makefile
index 270cb73f70..b9b8f71721 100644
--- a/sysdeps/unix/sysv/linux/arm/Makefile
+++ b/sysdeps/unix/sysv/linux/arm/Makefile
@@ -12,10 +12,6 @@ ifeq ($(subdir),signal)
 sysdep_routines += sigrestorer
 endif
 
-ifeq ($(subdir),resource)
-sysdep_routines += oldgetrlimit64
-endif
-
 ifeq ($(subdir),stdlib)
 gen-as-const-headers += ucontext_i.sym
 endif
diff --git a/sysdeps/unix/sysv/linux/arm/getrlimit64.c b/sysdeps/unix/sysv/linux/arm/getrlimit64.c
deleted file mode 100644
index fef018f471..0000000000
--- a/sysdeps/unix/sysv/linux/arm/getrlimit64.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/getrlimit64.c>
diff --git a/sysdeps/unix/sysv/linux/arm/oldgetrlimit.c b/sysdeps/unix/sysv/linux/arm/oldgetrlimit.c
deleted file mode 100644
index 6e25b021ab..0000000000
--- a/sysdeps/unix/sysv/linux/arm/oldgetrlimit.c
+++ /dev/null
@@ -1 +0,0 @@
-/* Empty.  */
diff --git a/sysdeps/unix/sysv/linux/arm/oldgetrlimit64.c b/sysdeps/unix/sysv/linux/arm/oldgetrlimit64.c
deleted file mode 100644
index 4c27e957bf..0000000000
--- a/sysdeps/unix/sysv/linux/arm/oldgetrlimit64.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/oldgetrlimit64.c>
diff --git a/sysdeps/unix/sysv/linux/arm/oldsetrlimit.c b/sysdeps/unix/sysv/linux/arm/oldsetrlimit.c
deleted file mode 100644
index 6e25b021ab..0000000000
--- a/sysdeps/unix/sysv/linux/arm/oldsetrlimit.c
+++ /dev/null
@@ -1 +0,0 @@
-/* Empty.  */
diff --git a/sysdeps/unix/sysv/linux/generic/bits/typesizes.h b/sysdeps/unix/sysv/linux/generic/bits/typesizes.h
index c31bba2f7c..f7766c788e 100644
--- a/sysdeps/unix/sysv/linux/generic/bits/typesizes.h
+++ b/sysdeps/unix/sysv/linux/generic/bits/typesizes.h
@@ -70,6 +70,11 @@
 
 /* Same for ino_t and ino64_t.  */
 # define __INO_T_MATCHES_INO64_T	1
+
+/* And for __rlim_t and __rlim64_t.  */
+# define __RLIM_T_MATCHES_RLIM64_T	1
+#else
+# define __RLIM_T_MATCHES_RLIM64_T	0
 #endif
 
 /* Number of descriptors that can fit in an `fd_set'.  */
diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/syscalls.list b/sysdeps/unix/sysv/linux/generic/wordsize-32/syscalls.list
index f055c68519..b775008a37 100644
--- a/sysdeps/unix/sysv/linux/generic/wordsize-32/syscalls.list
+++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/syscalls.list
@@ -1,7 +1,5 @@
 # File name	Caller	Syscall name	# args	Strong name	Weak names
 
 # rlimit APIs
-getrlimit	-	getrlimit	i:ip	__getrlimit	getrlimit
-setrlimit	-	setrlimit	i:ip	__setrlimit	setrlimit
 prlimit64	EXTRA	prlimit64	i:iipp	prlimit64
 fanotify_mark	EXTRA	fanotify_mark	i:iiiiis	fanotify_mark
diff --git a/sysdeps/unix/sysv/linux/getrlimit.c b/sysdeps/unix/sysv/linux/getrlimit.c
new file mode 100644
index 0000000000..bd340fb73e
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/getrlimit.c
@@ -0,0 +1,56 @@
+/* Linux getrlimit implementation (32 bits rlim_t).
+   Copyright (C) 2016 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <sys/resource.h>
+#include <sys/types.h>
+#include <shlib-compat.h>
+
+#if !__RLIM_T_MATCHES_RLIM64_T
+
+/* The __NR_getrlimit compatibility implementation is required iff
+   __NR_ugetrlimit is also defined (meaning an old broken RLIM_INFINITY
+   definition).  */
+# ifndef __NR_ugetrlimit
+#  define __NR_ugetrlimit __NR_getrlimit
+#  undef SHLIB_COMPAT
+#  define SHLIB_COMPAT(a, b, c) 0
+# endif
+
+int
+__new_getrlimit (enum __rlimit_resource resource, struct rlimit *rlim)
+{
+  return INLINE_SYSCALL_CALL (ugetrlimit, resource, rlim);
+}
+weak_alias (__new_getrlimit, __getrlimit)
+hidden_weak (__getrlimit)
+
+# if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
+/* Back compatible 2Gig limited rlimit.  */
+int
+__old_getrlimit (enum __rlimit_resource resource, struct rlimit *rlim)
+{
+  return INLINE_SYSCALL_CALL (getrlimit, resource, rlim);
+}
+compat_symbol (libc, __old_getrlimit, getrlimit, GLIBC_2_0);
+versioned_symbol (libc, __new_getrlimit, getrlimit, GLIBC_2_2);
+# else
+weak_alias (__new_getrlimit, getrlimit)
+# endif
+
+#endif /* __RLIM_T_MATCHES_RLIM64_T  */
diff --git a/sysdeps/unix/sysv/linux/getrlimit64.c b/sysdeps/unix/sysv/linux/getrlimit64.c
index d055a7f839..cb3d0080d8 100644
--- a/sysdeps/unix/sysv/linux/getrlimit64.c
+++ b/sysdeps/unix/sysv/linux/getrlimit64.c
@@ -1,4 +1,5 @@
-/* Copyright (C) 2010-2016 Free Software Foundation, Inc.
+/* Linux getrlimit64 implementation (64 bits rlim_t).
+   Copyright (C) 2010-2016 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -16,29 +17,46 @@
    <http://www.gnu.org/licenses/>.  */
 
 #include <errno.h>
-#include <sys/resource.h>
 #include <sys/types.h>
-#include <sysdep.h>
-#include <kernel-features.h>
+#include <shlib-compat.h>
+
+/* Add this redirection so the strong_alias for __RLIM_T_MATCHES_RLIM64_T
+   linking getlimit64 to {__}getrlimit does not throw a type error.  */
+#undef getrlimit
+#undef __getrlimit
+#define getrlimit getrlimit_redirect
+#define __getrlimit __getrlimit_redirect
+#include <sys/resource.h>
+#undef getrlimit
+#undef __getrlimit
 
 /* Put the soft and hard limits for RESOURCE in *RLIMITS.
    Returns 0 if successful, -1 if not (and sets errno).  */
 int
 __getrlimit64 (enum __rlimit_resource resource, struct rlimit64 *rlimits)
 {
-#ifdef __ASSUME_PRLIMIT64
-  return INLINE_SYSCALL (prlimit64, 4, 0, resource, NULL, rlimits);
-#else
-# ifdef __NR_prlimit64
-  int res = INLINE_SYSCALL (prlimit64, 4, 0, resource, NULL, rlimits);
+#ifdef __NR_prlimit64
+  int res = INLINE_SYSCALL_CALL (prlimit64, 0, resource, NULL, rlimits);
   if (res == 0 || errno != ENOSYS)
     return res;
+#endif
+
+/* The fallback code only makes sense if the platform supports either
+   __NR_ugetrlimit and/or __NR_getrlimit.  */
+#if defined (__NR_ugetrlimit) || defined (__NR_getrlimit)
+# ifndef __NR_ugetrlimit
+#  define __NR_ugetrlimit __NR_getrlimit
 # endif
+# if __RLIM_T_MATCHES_RLIM64_T
+#  define rlimits32 (*rlimits)
+# else
   struct rlimit rlimits32;
+# endif
 
-  if (__getrlimit (resource, &rlimits32) < 0)
+  if (INLINE_SYSCALL_CALL (ugetrlimit, resource, &rlimits32) < 0)
     return -1;
 
+# if !__RLIM_T_MATCHES_RLIM64_T
   if (rlimits32.rlim_cur == RLIM_INFINITY)
     rlimits->rlim_cur = RLIM64_INFINITY;
   else
@@ -47,12 +65,56 @@ __getrlimit64 (enum __rlimit_resource resource, struct rlimit64 *rlimits)
     rlimits->rlim_max = RLIM64_INFINITY;
   else
     rlimits->rlim_max = rlimits32.rlim_max;
+# endif /* !__RLIM_T_MATCHES_RLIM64_T */
+#endif /* defined (__NR_ugetrlimit) || defined (__NR_getrlimit)  */
 
   return 0;
-#endif
 }
 libc_hidden_def (__getrlimit64)
-#ifndef getrlimit64
+
+#if __RLIM_T_MATCHES_RLIM64_T
+/* If both rlim_t and rlimt64_t are essentially the same type we can use
+   alias both interfaces.  */
+strong_alias (__getrlimit64, __GI_getrlimit)
+strong_alias (__getrlimit64, __GI___getrlimit)
+strong_alias (__getrlimit64, __getrlimit)
+weak_alias (__getrlimit64, getrlimit)
+/* And there is no need for compat symbols.  */
+# undef SHLIB_COMPAT
+# define SHLIB_COMPAT(a, b, c) 0
+#endif
+
+#if SHLIB_COMPAT (libc, GLIBC_2_1, GLIBC_2_2)
+/* Back compatible 2GiB limited rlimit.  */
+extern int __new_getrlimit (enum __rlimit_resource, struct rlimit *);
+
+int
+attribute_compat_text_section
+__old_getrlimit64 (enum __rlimit_resource resource, struct rlimit64 *rlimits)
+{
+# if __RLIM_T_MATCHES_RLIM64_T
+#  define rlimits32 (*rlimits)
+# else
+  struct rlimit rlimits32;
+# endif
+
+  if (__new_getrlimit (resource, &rlimits32) < 0)
+    return -1;
+
+  if (rlimits32.rlim_cur == RLIM_INFINITY)
+    rlimits->rlim_cur = RLIM64_INFINITY >> 1;
+  else
+    rlimits->rlim_cur = rlimits32.rlim_cur;
+  if (rlimits32.rlim_max == RLIM_INFINITY)
+    rlimits->rlim_max = RLIM64_INFINITY >> 1;
+  else
+    rlimits->rlim_max = rlimits32.rlim_max;
+
+  return 0;
+}
+versioned_symbol (libc, __getrlimit64, getrlimit64, GLIBC_2_2);
+compat_symbol (libc, __old_getrlimit64, getrlimit64, GLIBC_2_1);
+#else
 weak_alias (__getrlimit64, getrlimit64)
 libc_hidden_weak (getrlimit64)
 #endif
diff --git a/sysdeps/unix/sysv/linux/hppa/getrlimit64.c b/sysdeps/unix/sysv/linux/hppa/getrlimit64.c
deleted file mode 100644
index fef018f471..0000000000
--- a/sysdeps/unix/sysv/linux/hppa/getrlimit64.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/getrlimit64.c>
diff --git a/sysdeps/unix/sysv/linux/hppa/syscalls.list b/sysdeps/unix/sysv/linux/hppa/syscalls.list
index 1f3dfb01e8..a95c3ddf18 100644
--- a/sysdeps/unix/sysv/linux/hppa/syscalls.list
+++ b/sysdeps/unix/sysv/linux/hppa/syscalls.list
@@ -31,8 +31,6 @@ shutdown	-	shutdown	i:ii	__shutdown	shutdown
 socket		-	socket		i:iii	__socket	socket
 socketpair	-	socketpair	i:iiif	__socketpair	socketpair
 
-setrlimit	-	setrlimit	i:ip	__setrlimit	setrlimit
-getrlimit	-	getrlimit	i:ip	__getrlimit	getrlimit
 prlimit64	EXTRA	prlimit64	i:iipp	__prlimit64	prlimit64@@GLIBC_2.17
 fanotify_mark	EXTRA	fanotify_mark	i:iiiiis	__fanotify_mark	fanotify_mark@@GLIBC_2.19
 personality	EXTRA	personality	Ei:i	__personality	personality
diff --git a/sysdeps/unix/sysv/linux/i386/Makefile b/sysdeps/unix/sysv/linux/i386/Makefile
index 2596cdfbb2..9609752256 100644
--- a/sysdeps/unix/sysv/linux/i386/Makefile
+++ b/sysdeps/unix/sysv/linux/i386/Makefile
@@ -49,10 +49,6 @@ libpthread-sysdep_routines += libc-do-syscall
 libpthread-shared-only-routines += libc-do-syscall
 endif
 
-ifeq ($(subdir),resource)
-sysdep_routines += oldgetrlimit64
-endif
-
 ifeq ($(subdir),stdlib)
 gen-as-const-headers += ucontext_i.sym
 endif
diff --git a/sysdeps/unix/sysv/linux/i386/oldgetrlimit64.c b/sysdeps/unix/sysv/linux/i386/oldgetrlimit64.c
deleted file mode 100644
index ad86a07203..0000000000
--- a/sysdeps/unix/sysv/linux/i386/oldgetrlimit64.c
+++ /dev/null
@@ -1,57 +0,0 @@
-/* Copyright (C) 1991-2016 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-/* This is a compatibility file.  If we don't build the libc with
-   versioning don't compile this file.  */
-#include <shlib-compat.h>
-#if SHLIB_COMPAT (libc, GLIBC_2_1, GLIBC_2_2)
-
-#include <errno.h>
-#include <sys/resource.h>
-#include <sys/types.h>
-
-extern int __new_getrlimit (enum __rlimit_resource, struct rlimit *);
-extern int __old_getrlimit64 (enum __rlimit_resource resource,
-			      struct rlimit64 *rlimits);
-
-
-/* Put the soft and hard limits for RESOURCE in *RLIMITS.
-   Returns 0 if successful, -1 if not (and sets errno).  */
-int
-attribute_compat_text_section
-__old_getrlimit64 (enum __rlimit_resource resource, struct rlimit64 *rlimits)
-{
-  struct rlimit rlimits32;
-
-  if (__new_getrlimit (resource, &rlimits32) < 0)
-    return -1;
-
-  if (rlimits32.rlim_cur == RLIM_INFINITY)
-    rlimits->rlim_cur = RLIM64_INFINITY >> 1;
-  else
-    rlimits->rlim_cur = rlimits32.rlim_cur;
-  if (rlimits32.rlim_max == RLIM_INFINITY)
-    rlimits->rlim_max = RLIM64_INFINITY >> 1;
-  else
-    rlimits->rlim_max = rlimits32.rlim_max;
-
-  return 0;
-}
-
-compat_symbol (libc, __old_getrlimit64, getrlimit64, GLIBC_2_1);
-
-#endif /* SHLIB_COMPAT */
diff --git a/sysdeps/unix/sysv/linux/i386/syscalls.list b/sysdeps/unix/sysv/linux/i386/syscalls.list
index 6282ff8e2f..145393f780 100644
--- a/sysdeps/unix/sysv/linux/i386/syscalls.list
+++ b/sysdeps/unix/sysv/linux/i386/syscalls.list
@@ -18,8 +18,6 @@ setfsuid	-	setfsuid32	Ei:i	setfsuid
 modify_ldt	EXTRA	modify_ldt	i:ipi	__modify_ldt	modify_ldt
 vm86old		EXTRA	vm86old		i:p	__vm86old	vm86@GLIBC_2.0
 vm86		-	vm86		i:ip	__vm86		vm86@@GLIBC_2.3.4
-oldgetrlimit	EXTRA	getrlimit	i:ip	__old_getrlimit	getrlimit@GLIBC_2.0
-setrlimit	-	setrlimit	i:ip	__setrlimit	setrlimit@GLIBC_2.0 setrlimit@@GLIBC_2.2
 waitpid		-	waitpid		Ci:ipi	__waitpid	waitpid
 
 prlimit64	EXTRA	prlimit64	i:iipp	prlimit64
diff --git a/sysdeps/unix/sysv/linux/m68k/Makefile b/sysdeps/unix/sysv/linux/m68k/Makefile
index 61c355ac2a..5c50ce6927 100644
--- a/sysdeps/unix/sysv/linux/m68k/Makefile
+++ b/sysdeps/unix/sysv/linux/m68k/Makefile
@@ -18,7 +18,3 @@ sysdep-rtld-routines += m68k-vdso
 sysdep-others += lddlibc4
 install-bin += lddlibc4
 endif
-
-ifeq ($(subdir),resource)
-sysdep_routines += oldgetrlimit64
-endif
diff --git a/sysdeps/unix/sysv/linux/m68k/getrlimit64.c b/sysdeps/unix/sysv/linux/m68k/getrlimit64.c
deleted file mode 100644
index fef018f471..0000000000
--- a/sysdeps/unix/sysv/linux/m68k/getrlimit64.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/getrlimit64.c>
diff --git a/sysdeps/unix/sysv/linux/m68k/m680x0/syscalls.list b/sysdeps/unix/sysv/linux/m68k/m680x0/syscalls.list
deleted file mode 100644
index b0ad68936d..0000000000
--- a/sysdeps/unix/sysv/linux/m68k/m680x0/syscalls.list
+++ /dev/null
@@ -1,4 +0,0 @@
-# File name	Caller	Syscall name	Args	Strong name	Weak names
-
-oldgetrlimit	EXTRA	getrlimit	i:ip	__old_getrlimit	getrlimit@GLIBC_2.0
-setrlimit	-	setrlimit	i:ip	__setrlimit	setrlimit@GLIBC_2.0 setrlimit@@GLIBC_2.2
diff --git a/sysdeps/unix/sysv/linux/m68k/oldgetrlimit64.c b/sysdeps/unix/sysv/linux/m68k/oldgetrlimit64.c
deleted file mode 100644
index 4c27e957bf..0000000000
--- a/sysdeps/unix/sysv/linux/m68k/oldgetrlimit64.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/oldgetrlimit64.c>
diff --git a/sysdeps/unix/sysv/linux/powerpc/getrlimit64.c b/sysdeps/unix/sysv/linux/powerpc/getrlimit64.c
deleted file mode 100644
index fef018f471..0000000000
--- a/sysdeps/unix/sysv/linux/powerpc/getrlimit64.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/getrlimit64.c>
diff --git a/sysdeps/unix/sysv/linux/powerpc/oldgetrlimit64.c b/sysdeps/unix/sysv/linux/powerpc/oldgetrlimit64.c
deleted file mode 100644
index 4c27e957bf..0000000000
--- a/sysdeps/unix/sysv/linux/powerpc/oldgetrlimit64.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/oldgetrlimit64.c>
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/Makefile b/sysdeps/unix/sysv/linux/powerpc/powerpc32/Makefile
index 84324aa7e1..3d6c150582 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/Makefile
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/Makefile
@@ -1,6 +1,2 @@
 # See Makeconfig regarding the use of default-abi.
 default-abi := 32
-
-ifeq ($(subdir),resource)
-sysdep_routines += oldgetrlimit64
-endif
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/syscalls.list b/sysdeps/unix/sysv/linux/powerpc/powerpc32/syscalls.list
index 451d50884b..931374776a 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/syscalls.list
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/syscalls.list
@@ -3,10 +3,6 @@
 chown		-	chown		i:sii	__chown		chown@@GLIBC_2.1
 lchown		-	lchown		i:sii	__lchown	lchown@@GLIBC_2.0 chown@GLIBC_2.0
 
-# System calls with wrappers.
-oldgetrlimit	EXTRA	getrlimit	i:ip	__old_getrlimit	getrlimit@GLIBC_2.0
-setrlimit	-	setrlimit	i:ip	__setrlimit	setrlimit@GLIBC_2.0 setrlimit@@GLIBC_2.2
-
 # Due to 64bit alignment there is a dummy second parameter
 readahead	-	readahead	i:iiiii	__readahead	readahead
 
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/syscalls.list b/sysdeps/unix/sysv/linux/powerpc/powerpc64/syscalls.list
deleted file mode 100644
index 6ba6f9b1e9..0000000000
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/syscalls.list
+++ /dev/null
@@ -1,3 +0,0 @@
-# File name	Caller	Syscall name	# args	Strong name	Weak names
-
-getrlimit	-	ugetrlimit	i:ip	__getrlimit	getrlimit getrlimit64 __getrlimit64
diff --git a/sysdeps/unix/sysv/linux/s390/bits/typesizes.h b/sysdeps/unix/sysv/linux/s390/bits/typesizes.h
index 7ee0cef9fb..62b2418fef 100644
--- a/sysdeps/unix/sysv/linux/s390/bits/typesizes.h
+++ b/sysdeps/unix/sysv/linux/s390/bits/typesizes.h
@@ -75,6 +75,11 @@
 
 /* Same for ino_t and ino64_t.  */
 # define __INO_T_MATCHES_INO64_T	1
+
+/* And for __rlim_t and __rlim64_t.  */
+# define __RLIM_T_MATCHES_RLIM64_T	1
+#else
+# define __RLIM_T_MATCHES_RLIM64_T	0
 #endif
 
 /* Number of descriptors that can fit in an `fd_set'.  */
diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/Makefile b/sysdeps/unix/sysv/linux/s390/s390-32/Makefile
index 626a96f04f..da3b3c76b4 100644
--- a/sysdeps/unix/sysv/linux/s390/s390-32/Makefile
+++ b/sysdeps/unix/sysv/linux/s390/s390-32/Makefile
@@ -10,10 +10,6 @@ ifeq ($(subdir),misc)
 sysdep_headers += sys/elf.h
 endif
 
-ifeq ($(subdir),resource)
-sysdep_routines += oldgetrlimit64
-endif
-
 ifeq ($(subdir),elf)
 ifeq (yes,$(build-shared))
 # This is needed to support g++ v2 and v3.
diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/getrlimit64.c b/sysdeps/unix/sysv/linux/s390/s390-32/getrlimit64.c
deleted file mode 100644
index fef018f471..0000000000
--- a/sysdeps/unix/sysv/linux/s390/s390-32/getrlimit64.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/getrlimit64.c>
diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/oldgetrlimit64.c b/sysdeps/unix/sysv/linux/s390/s390-32/oldgetrlimit64.c
deleted file mode 100644
index 4c27e957bf..0000000000
--- a/sysdeps/unix/sysv/linux/s390/s390-32/oldgetrlimit64.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/oldgetrlimit64.c>
diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/syscalls.list b/sysdeps/unix/sysv/linux/s390/s390-32/syscalls.list
index 141b16523d..300b13dd01 100644
--- a/sysdeps/unix/sysv/linux/s390/s390-32/syscalls.list
+++ b/sysdeps/unix/sysv/linux/s390/s390-32/syscalls.list
@@ -15,9 +15,6 @@ getgroups	-	getgroups32	i:ip	__getgroups	getgroups
 setfsgid	-	setfsgid32	Ei:i	setfsgid
 setfsuid	-	setfsuid32	Ei:i	setfsuid
 
-oldgetrlimit	EXTRA	getrlimit	i:ip	__old_getrlimit	getrlimit@GLIBC_2.0
-setrlimit	-	setrlimit	i:ip	__setrlimit	setrlimit@GLIBC_2.0 setrlimit@@GLIBC_2.2
-
 prlimit64	EXTRA	prlimit64	i:iipp	prlimit64
 fanotify_mark	EXTRA	fanotify_mark	i:iiiiis	fanotify_mark
 personality	EXTRA	personality	Ei:i	__personality	personality
diff --git a/sysdeps/unix/sysv/linux/setrlimit.c b/sysdeps/unix/sysv/linux/setrlimit.c
new file mode 100644
index 0000000000..78a3c33738
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/setrlimit.c
@@ -0,0 +1,64 @@
+/* Linux setrlimit implementation (32 bits off_t).
+   Copyright (C) 2016 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <sys/resource.h>
+#include <sys/types.h>
+#include <shlib-compat.h>
+
+#if !__RLIM_T_MATCHES_RLIM64_T
+
+/* The compatibility symbol is meant to match the old __NR_getrlimit syscall
+   (with broken RLIM_INFINITY definition).  It should be provided iff
+   __NR_getrlimit and __NR_ugetrlimit are both defined.  */
+# ifndef __NR_ugetrlimit
+#  undef SHLIB_COMPAT
+#  define SHLIB_COMPAT(a, b, c) 0
+# endif
+
+int
+__setrlimit (enum __rlimit_resource resource, const struct rlimit *rlim)
+{
+# ifdef __NR_prlimit64
+  struct rlimit64 rlim64;
+
+  if (rlim->rlim_cur == RLIM_INFINITY)
+    rlim64.rlim_cur = RLIM64_INFINITY;
+  else
+    rlim64.rlim_cur = rlim->rlim_cur;
+  if (rlim->rlim_max == RLIM_INFINITY)
+    rlim64.rlim_max = RLIM64_INFINITY;
+  else
+    rlim64.rlim_max = rlim->rlim_max;
+
+  int res = INLINE_SYSCALL_CALL (prlimit64, 0, resource, &rlim64, NULL);
+  if (res == 0 || errno != ENOSYS)
+    return res;
+# endif
+  return INLINE_SYSCALL_CALL (setrlimit, resource, rlim);
+}
+
+# if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
+strong_alias (__setrlimit, __setrlimit_1)
+compat_symbol (libc, __setrlimit, setrlimit, GLIBC_2_0);
+versioned_symbol (libc, __setrlimit_1, setrlimit, GLIBC_2_2);
+# else
+weak_alias (__setrlimit, setrlimit)
+# endif
+
+#endif /* __RLIM_T_MATCHES_RLIM64_T  */
diff --git a/sysdeps/unix/sysv/linux/setrlimit64.c b/sysdeps/unix/sysv/linux/setrlimit64.c
index 5f444d2ae7..8d2f7c6e53 100644
--- a/sysdeps/unix/sysv/linux/setrlimit64.c
+++ b/sysdeps/unix/sysv/linux/setrlimit64.c
@@ -1,4 +1,5 @@
-/* Copyright (C) 2010-2016 Free Software Foundation, Inc.
+/* Linux setrlimit64 implementation (64 bits off_t).
+   Copyright (C) 2010-2016 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -16,25 +17,37 @@
    <http://www.gnu.org/licenses/>.  */
 
 #include <errno.h>
-#include <sys/resource.h>
 #include <sys/types.h>
-#include <sysdep.h>
-#include <kernel-features.h>
+#include <shlib-compat.h>
+
+/* Add this redirection so the strong_alias for __RLIM_T_MATCHES_RLIM64_T
+   linking setlimit64 to {__}setrlimit does not throw a type error.  */
+#undef settrlimit
+#undef __sttrlimit
+#define setrlimit setrlimit_redirect
+#define __setrlimit __setrlimit_redirect
+#include <sys/resource.h>
+#undef setrlimit
+#undef __setrlimit
 
 /* Set the soft and hard limits for RESOURCE to *RLIMITS.
    Only the super-user can increase hard limits.
    Return 0 if successful, -1 if not (and sets errno).  */
 int
-setrlimit64 (enum __rlimit_resource resource, const struct rlimit64 *rlimits)
+__setrlimit64 (enum __rlimit_resource resource, const struct rlimit64 *rlimits)
 {
-#ifdef __ASSUME_PRLIMIT64
-  return INLINE_SYSCALL (prlimit64, 4, 0, resource, rlimits, NULL);
-#else
-# ifdef __NR_prlimit64
-  int res = INLINE_SYSCALL (prlimit64, 4, 0, resource, rlimits, NULL);
+  int res;
+
+#ifdef __NR_prlimit64
+  res = INLINE_SYSCALL_CALL (prlimit64, 0, resource, rlimits, NULL);
   if (res == 0 || errno != ENOSYS)
     return res;
-# endif
+#endif
+
+/* The fallback code only makes sense if the platform supports
+   __NR_setrlimit.  */
+#ifdef __NR_setrlimit
+# if !__RLIM_T_MATCHES_RLIM64_T
   struct rlimit rlimits32;
 
   if (rlimits->rlim_cur >= RLIM_INFINITY)
@@ -45,7 +58,18 @@ setrlimit64 (enum __rlimit_resource resource, const struct rlimit64 *rlimits)
     rlimits32.rlim_max = RLIM_INFINITY;
   else
     rlimits32.rlim_max = rlimits->rlim_max;
+# else
+#  define rlimits32 (*rlimits)
+# endif
 
-  return __setrlimit (resource, &rlimits32);
+  res = INLINE_SYSCALL_CALL (setrlimit, resource, &rlimits32);
 #endif
+
+  return res;
 }
+weak_alias (__setrlimit64, setrlimit64)
+
+#if __RLIM_T_MATCHES_RLIM64_T
+strong_alias (__setrlimit64, __setrlimit)
+weak_alias (__setrlimit64, setrlimit)
+#endif
diff --git a/sysdeps/unix/sysv/linux/sh/getrlimit64.c b/sysdeps/unix/sysv/linux/sh/getrlimit64.c
deleted file mode 100644
index fef018f471..0000000000
--- a/sysdeps/unix/sysv/linux/sh/getrlimit64.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/getrlimit64.c>
diff --git a/sysdeps/unix/sysv/linux/sparc/bits/typesizes.h b/sysdeps/unix/sysv/linux/sparc/bits/typesizes.h
index f98dd83f93..705c8773b3 100644
--- a/sysdeps/unix/sysv/linux/sparc/bits/typesizes.h
+++ b/sysdeps/unix/sysv/linux/sparc/bits/typesizes.h
@@ -69,6 +69,11 @@
 
 /* Same for ino_t and ino64_t.  */
 # define __INO_T_MATCHES_INO64_T	1
+
+/* And for __rlim_t and __rlim64_t.  */
+# define __RLIM_T_MATCHES_RLIM64_T	1
+#else
+# define __RLIM_T_MATCHES_RLIM64_T	0
 #endif
 
 /* Number of descriptors that can fit in an `fd_set'.  */
diff --git a/sysdeps/unix/sysv/linux/i386/getrlimit64.c b/sysdeps/unix/sysv/linux/sparc/getrlimit64.c
index 7f3d227beb..3a198521b6 100644
--- a/sysdeps/unix/sysv/linux/i386/getrlimit64.c
+++ b/sysdeps/unix/sysv/linux/sparc/getrlimit64.c
@@ -1,4 +1,5 @@
-/* Copyright (C) 1999-2016 Free Software Foundation, Inc.
+/* Linux getrlimit64 sparc32 implementation (64 bits rlim_t).
+   Copyright (C) 2016 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -15,11 +16,9 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#define getrlimit64 __new_getrlimit64
+#include <shlib-compat.h>
 
-#include "../getrlimit64.c"
+#undef SHLIB_COMPAT
+#define SHLIB_COMPAT(a,b,c) 0
 
-#undef getrlimit64
-#include <shlib-compat.h>
-versioned_symbol (libc, __getrlimit64, getrlimit64, GLIBC_2_2);
-strong_alias (__getrlimit64, __GI_getrlimit64)
+#include <sysdeps/unix/sysv/linux/getrlimit64.c>
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/syscalls.list b/sysdeps/unix/sysv/linux/sparc/sparc32/syscalls.list
index 6240cd3a52..0b6095ffab 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc32/syscalls.list
+++ b/sysdeps/unix/sysv/linux/sparc/sparc32/syscalls.list
@@ -4,8 +4,6 @@ chown		-	chown32		i:sii	__chown		chown
 lchown		-	lchown32	i:sii	__lchown	lchown
 fchown		-	fchown32	i:iii	__fchown	fchown
 
-setrlimit	-	setrlimit	2	__setrlimit	setrlimit
-getrlimit	-	getrlimit	2	__getrlimit	getrlimit
 getegid		-	getegid32	Ei:	__getegid	getegid
 geteuid		-	geteuid32	Ei:	__geteuid	geteuid
 getgid		-	getgid32	Ei:	__getgid	getgid
diff --git a/sysdeps/unix/sysv/linux/syscalls.list b/sysdeps/unix/sysv/linux/syscalls.list
index 7ae2541f8f..68af897e39 100644
--- a/sysdeps/unix/sysv/linux/syscalls.list
+++ b/sysdeps/unix/sysv/linux/syscalls.list
@@ -26,7 +26,6 @@ getpmsg		-	getpmsg		i:ipppp	getpmsg
 getppid		-	getppid		Ei:	__getppid	getppid
 getresuid	-	getresuid	i:ppp	getresuid
 getresgid	-	getresgid	i:ppp	getresgid
-getrlimit	-	ugetrlimit	i:ip	__new_getrlimit __getrlimit getrlimit@@GLIBC_2.2
 getsid		-	getsid		i:i	getsid
 init_module	EXTRA	init_module	5	init_module
 inotify_add_watch	EXTRA	inotify_add_watch	i:isi	inotify_add_watch
diff --git a/sysdeps/unix/sysv/linux/wordsize-64/getrlimit64.c b/sysdeps/unix/sysv/linux/wordsize-64/getrlimit64.c
deleted file mode 100644
index 9feab0e6b8..0000000000
--- a/sysdeps/unix/sysv/linux/wordsize-64/getrlimit64.c
+++ /dev/null
@@ -1 +0,0 @@
-/* getrlimit64 is the same as getrlimit. */
diff --git a/sysdeps/unix/sysv/linux/wordsize-64/setrlimit64.c b/sysdeps/unix/sysv/linux/wordsize-64/setrlimit64.c
deleted file mode 100644
index 8edcff0086..0000000000
--- a/sysdeps/unix/sysv/linux/wordsize-64/setrlimit64.c
+++ /dev/null
@@ -1 +0,0 @@
-/* setrlimit64 is the same as setrlimit. */
diff --git a/sysdeps/unix/sysv/linux/wordsize-64/syscalls.list b/sysdeps/unix/sysv/linux/wordsize-64/syscalls.list
index 99236ba9bf..e71cd7b156 100644
--- a/sysdeps/unix/sysv/linux/wordsize-64/syscalls.list
+++ b/sysdeps/unix/sysv/linux/wordsize-64/syscalls.list
@@ -3,8 +3,6 @@
 fstatfs		-	fstatfs		i:ip	__fstatfs	fstatfs fstatfs64 __fstatfs64
 statfs		-	statfs		i:sp	__statfs	statfs statfs64
 mmap		-	mmap		b:aniiii __mmap		mmap __mmap64 mmap64
-getrlimit	-	getrlimit	i:ip	__getrlimit	getrlimit getrlimit64 __getrlimit64
-setrlimit	-	setrlimit	i:ip	__setrlimit	setrlimit setrlimit64
 readahead	-	readahead	i:iii	__readahead	readahead
 sendfile	-	sendfile	i:iipi	sendfile	sendfile64
 sync_file_range	-	sync_file_range	Ci:iiii	sync_file_range
diff --git a/sysdeps/unix/sysv/linux/x86/bits/typesizes.h b/sysdeps/unix/sysv/linux/x86/bits/typesizes.h
index 5817ef3f86..1fd90d3e85 100644
--- a/sysdeps/unix/sysv/linux/x86/bits/typesizes.h
+++ b/sysdeps/unix/sysv/linux/x86/bits/typesizes.h
@@ -81,6 +81,11 @@
 
 /* Same for ino_t and ino64_t.  */
 # define __INO_T_MATCHES_INO64_T	1
+
+/* And for __rlim_t and __rlim64_t.  */
+# define __RLIM_T_MATCHES_RLIM64_T	1
+#else
+# define __RLIM_T_MATCHES_RLIM64_T	0
 #endif
 
 /* Number of descriptors that can fit in an `fd_set'.  */