This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH 3/6] i386: Remove syscall assembly codes with 6 arguments
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: GNU C Library <libc-alpha at sourceware dot org>
- Date: Fri, 21 Aug 2015 04:57:19 -0700
- Subject: Re: [PATCH 3/6] i386: Remove syscall assembly codes with 6 arguments
- Authentication-results: sourceware.org; auth=none
- References: <20150814121724 dot GC28610 at gmail dot com> <CAMe9rOqNURKknCY9rMkSeSaP+0ccFWsiSFKRFxaCQ+_Y5kxW2A at mail dot gmail dot com>
On Fri, Aug 14, 2015 at 10:34 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Fri, Aug 14, 2015 at 5:17 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>> OK for master?
>>
>> H.J.
>> ---
>> This patch removes i386 assembly implementation for epoll_wait, mmap,
>> mmap64, semtimeop now that i386 have 6 argument syscall support from
>> C code and GCC 5 can inline syscalls with 6 argument. We also compile
>> epoll_pwait.c, mmap.c, mmap64.c and semtimedop.c with -fomit-frame-pointer
>> since %ebp may be used to pass the 6th argument to syscall.
>>
>> Fo sysdeps/unix/sysv/linux/i386/mmap.c, with -O2 -march=i686
>> -mtune=generic, GCC 5.2 now generates:
>>
>> <__mmap>:
>> 0: sub $0x10,%esp
>> 3: mov 0x28(%esp),%eax
>> 7: mov %ebx,(%esp)
>> a: mov 0x18(%esp),%ecx
>> e: mov %esi,0x4(%esp)
>> 12: mov 0x14(%esp),%ebx
>> 16: mov %edi,0x8(%esp)
>> 1a: mov 0x1c(%esp),%edx
>> 1e: test $0xfff,%eax
>> 23: mov 0x20(%esp),%esi
>> 27: mov %ebp,0xc(%esp)
>> 2b: mov 0x24(%esp),%edi
>> 2f: jne 60 <__mmap+0x60>
>> 31: sar $0xc,%eax
>> 34: mov %eax,%ebp
>> 36: mov $0xc0,%eax
>> 3b: call *%gs:0x10
>> 42: cmp $0xfffff000,%eax
>> 47: ja 65 <__mmap+0x65>
>> 49: mov (%esp),%ebx
>> 4c: mov 0x4(%esp),%esi
>> 50: mov 0x8(%esp),%edi
>> 54: mov 0xc(%esp),%ebp
>> 58: add $0x10,%esp
>> 5b: ret
>> 5c: lea 0x0(%esi,%eiz,1),%esi
>> 60: mov $0xffffffea,%eax
>> 65: mov (%esp),%ebx
>> 68: mov 0x4(%esp),%esi
>> 6c: mov 0x8(%esp),%edi
>> 70: mov 0xc(%esp),%ebp
>> 74: add $0x10,%esp
>> 77: jmp 78 <__mmap+0x78> 78: R_386_PC32 __syscall_error
>>
>> vs sysdeps/unix/sysv/linux/i386/mmap.S:
>>
>> <__mmap>:
>> 0: push %ebp
>> 1: push %ebx
>> 2: push %esi
>> 3: push %edi
>> 4: mov 0x14(%esp),%ebx
>> 8: mov 0x18(%esp),%ecx
>> c: mov 0x1c(%esp),%edx
>> 10: mov 0x20(%esp),%esi
>> 14: mov 0x24(%esp),%edi
>> 18: mov 0x28(%esp),%ebp
>> 1c: test $0xfff,%ebp
>> 22: mov $0xffffffea,%eax
>> 27: jne 38 <__mmap+0x38>
>> 29: shr $0xc,%ebp
>> 2c: mov $0xc0,%eax
>> 31: call *%gs:0x10
>> 38: pop %edi
>> 39: pop %esi
>> 3a: pop %ebx
>> 3b: pop %ebp
>> 3c: cmp $0xfffff000,%eax
>> 41: ja 44 <__mmap+0x44>
>> 43: ret
>> 44: call 45 <__mmap+0x45> 45: R_386_PC32 __x86.get_pc_thunk.cx
>> 49: add $0x2,%ecx 4b: R_386_GOTPC _GLOBAL_OFFSET_TABLE_
>> 4f: mov 0x0(%ecx),%ecx 51: R_386_TLS_GOTIE __libc_errno
>> 55: neg %eax
>> 57: mov %eax,%gs:(%ecx)
>> 5a: or $0xffffffff,%eax
>> 5d: ret
>>
>> The C version has:
>>
>> 3: mov 0x28(%esp),%eax
>> ...
>> 1e: test $0xfff,%eax
>> ...
>> 31: sar $0xc,%eax
>> 34: mov %eax,%ebp
>>
>> is due to missing $ebx register constraint for inline asm. We have
>> to use "r" constraint with
>>
>> register unsigned int _a6 asm ("ebp") = (unsigned int) (arg6);
>>
>> and compiler chose %eax for offset (arg6) in
>>
>> if (offset & ((1 << MMAP_PAGE_SHIFT) - 1))
>>
>> * sysdeps/unix/sysv/linux/i386/Makefile (CFLAGS-epoll_pwait.c):
>> Add -fomit-frame-pointer.
>> (CFLAGS-mmap.c): Likewise.
>> (CFLAGS-mmap64.c): Likewise.
>> (CFLAGS-semtimedop.c): Likewise.
>> * sysdeps/unix/sysv/linux/i386/mmap.c: New file.
>> * sysdeps/unix/sysv/linux/i386/epoll_pwait.S: Remove file.
>> * sysdeps/unix/sysv/linux/i386/mmap.S: Likewise.
>> * sysdeps/unix/sysv/linux/i386/mmap64.S: Likewise.
>> * sysdeps/unix/sysv/linux/i386/semtimedop.S: Likewise.
>
> Here is the patch for updated INLINE_SYSCALL_RETURN and
> INLINE_SYSCALL_ERROR_RETURN. OK for master?
I will check it in next Monday if there are no objections.
--
H.J.