This is the mail archive of the
libc-ports@sources.redhat.com
mailing list for the libc-ports project.
Fix ARM syscall argument loading
- From: "Joseph S. Myers" <joseph at codesourcery dot com>
- To: libc-ports at sourceware dot org
- Date: Tue, 25 Nov 2008 16:40:12 +0000 (UTC)
- Subject: Fix ARM syscall argument loading
This patch fixes a problem observed with ARM syscall argument loading for
Thumb-2, where a call to sched_getaffinity in
sysdeps/unix/sysv/linux/sched_setaffinity.c has getpid () as one of the
arguments, and calling getpid () clobbers registers into which some of the
arguments have been loaded. The GCC manual has warnings about using
register variables for call clobbered registers as asm arguments with such
initializers, and this patch implements the recommended fix of computing
all the arguments before loading them in the registers. The structure of
the macros used to do this is similar to that in
sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep.h. Committed.
(Although Thumb-2 support isn't presently in FSF ports, this seems equally
relevant to ARM mode, with it just being chance of code generation
affecting whether or not it applies to a particular build.)
Index: ChangeLog.arm
===================================================================
RCS file: /cvs/glibc/ports/ChangeLog.arm,v
retrieving revision 1.81
diff -u -r1.81 ChangeLog.arm
--- ChangeLog.arm 19 Aug 2008 15:59:07 -0000 1.81
+++ ChangeLog.arm 25 Nov 2008 16:37:03 -0000
@@ -1,3 +1,10 @@
+2008-11-25 Joseph Myers <joseph@codesourcery.com>
+
+ * sysdeps/unix/sysv/linux/arm/sysdep.h (LOAD_ARGS_1, LOAD_ARGS_2,
+ LOAD_ARGS_3, LOAD_ARGS_4, LOAD_ARGS_5, LOAD_ARGS_6, LOAD_ARGS_7):
+ Load all arguments into temporary variables before loading into
+ registers.
+
2008-08-19 Joseph Myers <joseph@codesourcery.com>
* data/c++-types-arm-linux-gnueabi.data: New.
Index: sysdeps/unix/sysv/linux/arm/sysdep.h
===================================================================
RCS file: /cvs/glibc/ports/sysdeps/unix/sysv/linux/arm/sysdep.h,v
retrieving revision 1.32
diff -u -r1.32 sysdep.h
--- sysdeps/unix/sysv/linux/arm/sysdep.h 23 Jan 2007 16:47:28 -0000 1.32
+++ sysdeps/unix/sysv/linux/arm/sysdep.h 25 Nov 2008 16:37:03 -0000
@@ -238,32 +238,39 @@
#define LOAD_ARGS_0()
#define ASM_ARGS_0
#define LOAD_ARGS_1(a1) \
- _a1 = (int) (a1); \
- LOAD_ARGS_0 ()
+ int _a1tmp = (int) (a1); \
+ LOAD_ARGS_0 () \
+ _a1 = _a1tmp;
#define ASM_ARGS_1 ASM_ARGS_0, "r" (_a1)
#define LOAD_ARGS_2(a1, a2) \
- register int _a2 asm ("a2") = (int) (a2); \
- LOAD_ARGS_1 (a1)
+ int _a2tmp = (int) (a2); \
+ LOAD_ARGS_1 (a1) \
+ register int _a2 asm ("a2") = _a2tmp;
#define ASM_ARGS_2 ASM_ARGS_1, "r" (_a2)
#define LOAD_ARGS_3(a1, a2, a3) \
- register int _a3 asm ("a3") = (int) (a3); \
- LOAD_ARGS_2 (a1, a2)
+ int _a3tmp = (int) (a3); \
+ LOAD_ARGS_2 (a1, a2) \
+ register int _a3 asm ("a3") = _a3tmp;
#define ASM_ARGS_3 ASM_ARGS_2, "r" (_a3)
#define LOAD_ARGS_4(a1, a2, a3, a4) \
- register int _a4 asm ("a4") = (int) (a4); \
- LOAD_ARGS_3 (a1, a2, a3)
+ int _a4tmp = (int) (a4); \
+ LOAD_ARGS_3 (a1, a2, a3) \
+ register int _a4 asm ("a4") = _a4tmp;
#define ASM_ARGS_4 ASM_ARGS_3, "r" (_a4)
#define LOAD_ARGS_5(a1, a2, a3, a4, a5) \
- register int _v1 asm ("v1") = (int) (a5); \
- LOAD_ARGS_4 (a1, a2, a3, a4)
+ int _v1tmp = (int) (a5); \
+ LOAD_ARGS_4 (a1, a2, a3, a4) \
+ register int _v1 asm ("v1") = _v1tmp;
#define ASM_ARGS_5 ASM_ARGS_4, "r" (_v1)
#define LOAD_ARGS_6(a1, a2, a3, a4, a5, a6) \
- register int _v2 asm ("v2") = (int) (a6); \
- LOAD_ARGS_5 (a1, a2, a3, a4, a5)
+ int _v2tmp = (int) (a6); \
+ LOAD_ARGS_5 (a1, a2, a3, a4, a5) \
+ register int _v2 asm ("v2") = _v2tmp;
#define ASM_ARGS_6 ASM_ARGS_5, "r" (_v2)
#define LOAD_ARGS_7(a1, a2, a3, a4, a5, a6, a7) \
- register int _v3 asm ("v3") = (int) (a7); \
- LOAD_ARGS_6 (a1, a2, a3, a4, a5, a6)
+ int _v3tmp = (int) (a7); \
+ LOAD_ARGS_6 (a1, a2, a3, a4, a5, a6) \
+ register int _v3 asm ("v3") = _v3tmp;
#define ASM_ARGS_7 ASM_ARGS_6, "r" (_v3)
/* We can't implement non-constant syscalls directly since the syscall
--
Joseph S. Myers
joseph@codesourcery.com