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]

Re: [PATCH] mips/o32: fix internal_syscall5/6/7


On 2017-08-15 16:24, Joseph Myers wrote:
> On Tue, 15 Aug 2017, Adhemerval Zanella wrote:
> 
> > Wouldn't a better option and more compiler optimization proof to route
> > syscall5/6/7 to a out of line symbol call to proper handle the stack
> > pointer as for ARM and i386 (__libc_do_syscall)?
> 
> Indeed (and with a bug filed in Bugzilla as usual since this issue was 
> user-visible in a release).

That's one way to do that, however it does seem correct to me that there
is no way to force the stack pointer to be valid in an asm code. The
stack pointer is used in other asm codes in the glibc, so we need a more
global solution.

For the record, here is the corresponding generated code showing the
issue:

 174:	8e020000 	lw	v0,0(s0)
 178:	30420004 	andi	v0,v0,0x4
 17c:	104000a6 	beqz	v0,418 <__GI___pthread_rwlock_rdlock+0x418>
 180:	02c01825 	move	v1,s6
 184:	92050019 	lbu	a1,25(s0)
 188:	27bdfff0 	addiu	sp,sp,-16

 here the stack pointer is changed

 18c:	8fc60024 	lw	a2,36(s8)
 190:	02002025 	move	a0,s0
 194:	02e5180a 	movz	v1,s7,a1
 198:	27a20010 	addiu	v0,sp,16
 19c:	00003825 	move	a3,zero
 1a0:	afc20020 	sw	v0,32(s8)

 and the original value stored in the fp.

 1a4:	00001025 	move	v0,zero
 1a8:	00602825 	move	a1,v1

 --- begin of asm code

 1ac:	27bdffe0 	addiu	sp,sp,-32
 1b0:	afa20010 	sw	v0,16(sp)
 1b4:	afb20014 	sw	s2,20(sp)
 1b8:	2402108e 	li	v0,4238
 1bc:	0000000c 	syscall
 1c0:	27bd0020 	addiu	sp,sp,32

 --- end of asm code

 1c4:	10e0ffeb 	beqz	a3,174 <__GI___pthread_rwlock_rdlock+0x174>
 1c8:	00021823 	negu	v1,v0


When specifying the stack pointer as clobbered, we end up with the
following code:

 174:	8e020000 	lw	v0,0(s0)
 178:	30420004 	andi	v0,v0,0x4
 17c:	104000a6 	beqz	v0,418 <__GI___pthread_rwlock_rdlock+0x418>
 180:	8fc60024 	lw	a2,36(s8)
 184:	02a0e825 	move	sp,s5

 here the stack pointer is reloaded at each loop (the decrease by 16 is
 done earlier before saving it in s5).

 188:	92050019 	lbu	a1,25(s0)
 18c:	27a20010 	addiu	v0,sp,16
 190:	02002025 	move	a0,s0
 194:	afc20020 	sw	v0,32(s8)
 198:	02c01025 	move	v0,s6
 19c:	02e5100a 	movz	v0,s7,a1
 1a0:	00003825 	move	a3,zero
 1a4:	00402825 	move	a1,v0
 1a8:	00001025 	move	v0,zero

 --- begin of asm code

 1ac:	27bdffe0 	addiu	sp,sp,-32
 1b0:	afa20010 	sw	v0,16(sp)
 1b4:	afb20014 	sw	s2,20(sp)
 1b8:	2402108e 	li	v0,4238
 1bc:	0000000c 	syscall
 1c0:	27bd0020 	addiu	sp,sp,32

 --- end of asm code

 1c4:	10e0ffeb 	beqz	a3,174 <__GI___pthread_rwlock_rdlock+0x174>
 1c8:	00021823 	negu	v1,v0

-- 
Aurelien Jarno                          GPG: 4096R/1DDD8C9B
aurelien@aurel32.net                 http://www.aurel32.net


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