This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Committed: Fix ABI abuse in RX version of strncat
- From: Nick Clifton <nickc at redhat dot com>
- To: binutils at sourceware dot org
- Date: Fri, 20 Nov 2009 15:10:20 +0000
- Subject: Committed: Fix ABI abuse in RX version of strncat
Hi Guys,
I am checking in the patch below as an obvious fix for a problem
with RX assembler implementation of the strncat function - it was
using the r6 register without preserving its value. This violates
the RX ABI which specifies that r6 is a call-saved register. The
patch replaces all uses of r6 with uses of r154 instead, which is a
call-clobbered register.
Cheers
Nick
newlib/ChangeLog
2009-11-20 Nick Clifton <nickc@redhat.com>
* libc/machine/rx/strncat.S (_strncat): Replace use of r6
(call-saved) with r14 (call-used).
Index: libc/machine/rx/strncat.S
===================================================================
RCS file: /cvs/src/src/newlib/libc/machine/rx/strncat.S,v
retrieving revision 1.1
diff -c -3 -p -r1.1 strncat.S
*** libc/machine/rx/strncat.S 26 Oct 2009 10:05:23 -0000 1.1
--- libc/machine/rx/strncat.S 20 Nov 2009 12:48:49 -0000
*************** _strncat:
*** 10,34 ****
mov r1, r4 ; Save a copy of the dest pointer.
mov r2, r5 ; Save a copy of the source pointer.
! mov r3, r6 ; Save a copy of the byte count.
mov #0, r2 ; Search for the NUL byte.
mov #-1, r3 ; Search until we run out of memory.
suntil.b ; Find the end of the destination string.
sub #1, r1 ; suntil.b leaves r1 pointing to the byte beyond the NUL.
! mov r6, r3 ; Restore the limit on the number of bytes copied.
mov r5, r2 ; Restore the source pointer.
mov r1, r5 ; Save a copy of the dest pointer.
smovu ; Copy source to destination.
! add #0, r6, r3 ; Restore the number of bytes to copy (again), but this time set the Z flag as well.
beq 1f ; If we copied 0 bytes then we already know that the dest string is NUL terminated, so we do not have to do anything.
mov #0, r2 ; Otherwise we must check to see if a NUL byte
mov r5, r1 ; was included in the bytes that were copied.
suntil.b
beq 1f ; Z flag is set if a match was found.
! add r6, r5 ; Point at byte after end of copied bytes.
mov.b #0, [r5] ; Store a NUL there.
1:
mov r4, r1 ; Return the original dest pointer.
--- 10,34 ----
mov r1, r4 ; Save a copy of the dest pointer.
mov r2, r5 ; Save a copy of the source pointer.
! mov r3, r14 ; Save a copy of the byte count.
mov #0, r2 ; Search for the NUL byte.
mov #-1, r3 ; Search until we run out of memory.
suntil.b ; Find the end of the destination string.
sub #1, r1 ; suntil.b leaves r1 pointing to the byte beyond the NUL.
! mov r14, r3 ; Restore the limit on the number of bytes copied.
mov r5, r2 ; Restore the source pointer.
mov r1, r5 ; Save a copy of the dest pointer.
smovu ; Copy source to destination.
! add #0, r14, r3 ; Restore the number of bytes to copy (again), but this time set the Z flag as well.
beq 1f ; If we copied 0 bytes then we already know that the dest string is NUL terminated, so we do not have to do anything.
mov #0, r2 ; Otherwise we must check to see if a NUL byte
mov r5, r1 ; was included in the bytes that were copied.
suntil.b
beq 1f ; Z flag is set if a match was found.
! add r14, r5 ; Point at byte after end of copied bytes.
mov.b #0, [r5] ; Store a NUL there.
1:
mov r4, r1 ; Return the original dest pointer.