This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH: Update x86-64/sysdep.h


On Mon, May 21, 2012 at 2:22 PM, Roland McGrath <roland@hack.frob.com> wrote:
>> Here is what I implemented. ?Since I need to refine SYSCALL_ERROR_HANDLER
>> anyway, I use it to define my own error handler. ?Does it look OK?
>>
>> I noticed that SYSCALL_ERROR_HANDLER has
>>
>> ? xorl %edx, %edx; ? ? ? ? ? ? ? ? ? ? ? ? ? ?\
>> ? subq %rax, %rdx; ? ? ? ? ? ? ? ? ? ? ? ? ? ?\
>> ? movl %edx, (%rcx); ? ? ? ? ? ? ? ? ? ? ? ? ?\
>> ? orq $-1, %rax; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?\
>> ? jmp L(pseudo_end);
>>
>> Why not simply "neg %rax"?
>
> No idea. ?It appears it was done that way in the first version of this
> file, added by AJ.
>
>> Also why not just "ret" instead of jmp?
>
> Likewise. ?This one seems downright wrong, since theoretically the code at
> the label might not be just "ret". ?That code (i.e. whatever comes after
> the PSEUDO macro invocation) was always meant to be only the code for the
> success case.
>
> Those two changes are unrelated to x32, so you can submit them separately
> and see if anybody has any comment.
>

Here is the patch.  Tested on Linux/x86-64 and Linux/x32.  Any
objections?

Thanks.

-- 
H.J.
---
2012-05-21  H.J. Lu  <hongjiu.lu@intel.com>

	* sysdeps/unix/sysv/linux/x86_64/sysdep.h (SYSCALL_SET_ERRNO): Use
	"neg %eax".
	(SYSCALL_ERROR_HANDLER): Replace "jmp L(pseudo_end)" with "ret".

diff --git a/sysdeps/unix/sysv/linux/x86_64/sysdep.h
b/sysdeps/unix/sysv/linux/x86_64/sysdep.h
index 3f5bdd2..0203f07 100644
--- a/sysdeps/unix/sysv/linux/x86_64/sysdep.h
+++ b/sysdeps/unix/sysv/linux/x86_64/sysdep.h
@@ -115,9 +115,8 @@
 # if defined PIC && defined RTLD_PRIVATE_ERRNO
 #  define SYSCALL_SET_ERRNO			\
   lea rtld_errno(%rip), %RCX_LP;		\
-  xorl %edx, %edx;				\
-  sub %RAX_LP, %RDX_LP;				\
-  movl %edx, (%rcx)
+  neg %eax;					\
+  movl %eax, (%rcx)
 # else
 #  ifndef NOT_IN_libc
 #   define SYSCALL_ERROR_ERRNO __libc_errno
@@ -126,9 +125,8 @@
 #  endif
 #  define SYSCALL_SET_ERRNO			\
   movq SYSCALL_ERROR_ERRNO@GOTTPOFF(%rip), %rcx;\
-  xorl %edx, %edx;				\
-  sub %RAX_LP, %RDX_LP;				\
-  movl %edx, %fs:(%rcx)
+  neg %eax;					\
+  movl %eax, %fs:(%rcx);
 # endif

 # ifndef PIC
@@ -138,7 +136,7 @@
 0:						\
   SYSCALL_SET_ERRNO;				\
   or $-1, %RAX_LP;				\
-  jmp L(pseudo_end);
+  ret;
 # endif	/* PIC */

 /* The Linux/x86-64 kernel expects the system call parameters in


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]