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 Tue, 15 Aug 2017, Joseph Myers wrote:

> In which case having a volatile integer variable with value 4, declaring a 
> VLA whose size is that variable, and storing a pointer to that VLA in a 
> variable, would be an alternative to alloca to force a frame pointer, but 
> with deallocation happening when the scope ends rather than the function 
> ending (and the syscall macro has its own scope, so using it inside a loop 
> wouldn't be a problem).

 I suspect using volatile variables will cause unnecessary memory traffic.  
Passing the size specifier through an empty `asm' might give better code; 
also I think we can use 0 as the size requested, not to decrease the stack 
pointer unnecessarily, e.g.:

  {
    size_t s = 0;

    asm ("" : "+r" (s));
    {
      char vla[s << 3];

      asm ("" : : "p" (vla));
      /* ... */

This seems to produce reasonable code with GCC 8, taking the necessity to 
align stack as per the ABI requirement into account already, and wasting 
two instructions only in addition to the $sp adjustment itself:

	move	$4,$0
	sll	$4,$4,3
# ...
	subu	$sp,$sp,$4
	
 Also I wonder if there's actually a dependable way to have GCC itself 
allocate the argument space we require.  For example if we set `s' to 1 
above instead for `internal_syscall6', then would `0($sp)' and `4($sp)' be 
valid to place arguments #5 and #6 at respectively without the subsequent 
$sp adjustment we currently have in the syscall `asm' or would it be UB?

  Maciej


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