Only pass the minimum number of syscall arguments
Previously, __internal_syscall() compiled into asm-code that unconditionally sets the syscall argument registers a0 to a5. For example, the instruction sequence for a exit syscall looked like this: li a0, 1 # in ther caller of exit() # ... # in newlib: li a1, 0 # unused arguments li a2, 0 li a3, 0 li a4, 0 li a5, 0 li a7, 93 # exit syscall number (i.e. the binary contains then 5 superfluous instructions for this one argument syscall) This commit changes the RISC-V syscall code such that only the required syscall argument registers are set. GCC detects that argc is known at compile time and thus evaluates all the if-statements where argc is used at compile time (tested with -O2 and -Os).
This commit is contained in:
committed by
Corinna Vinschen
parent
2379142bc5
commit
9b51beeb2a
@ -41,13 +41,13 @@ _sbrk(ptrdiff_t incr)
|
||||
|
||||
if (heap_end == 0)
|
||||
{
|
||||
long brk = __internal_syscall (SYS_brk, 0, 0, 0, 0, 0, 0);
|
||||
long brk = __internal_syscall (SYS_brk, 1, 0, 0, 0, 0, 0, 0);
|
||||
if (brk == -1)
|
||||
return (void *)__syscall_error (-ENOMEM);
|
||||
heap_end = brk;
|
||||
}
|
||||
|
||||
if (__internal_syscall (SYS_brk, heap_end + incr, 0, 0, 0, 0, 0) != heap_end + incr)
|
||||
if (__internal_syscall (SYS_brk, 1, heap_end + incr, 0, 0, 0, 0, 0) != heap_end + incr)
|
||||
return (void *)__syscall_error (-ENOMEM);
|
||||
|
||||
heap_end += incr;
|
||||
|
Reference in New Issue
Block a user