]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
mips: Add redir for index function in ld.so.1
authorPetar Jovanovic <mips32r2@gmail.com>
Fri, 4 Nov 2016 18:21:22 +0000 (18:21 +0000)
committerPetar Jovanovic <mips32r2@gmail.com>
Fri, 4 Nov 2016 18:21:22 +0000 (18:21 +0000)
Redirect index function in ld.so.1.
Optimize the existing strlen function implementations.
This removes warnings coming from optimized index and strlen functions
in ld.so.1.

Patch by Aleksandar Rikalo.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@16117

coregrind/m_redir.c
coregrind/m_trampoline.S
coregrind/pub_core_trampoline.h

index ff35009a7cc97b04745956bee9291fa8e3ffd179..76fc6749e002880593cd3786f7d456a6d067a9d3 100644 (file)
@@ -1567,10 +1567,15 @@ void VG_(redir_initialise) ( void )
 
       /* this is mandatory - can't sanely continue without it */
       add_hardwired_spec(
-         "ld.so.3", "strlen",
+         "ld.so.1", "strlen",
          (Addr)&VG_(mips32_linux_REDIR_FOR_strlen),
          complain_about_stripped_glibc_ldso
       );
+      add_hardwired_spec(
+         "ld.so.1", "index",
+         (Addr)&VG_(mips32_linux_REDIR_FOR_index),
+         complain_about_stripped_glibc_ldso
+      );
    }
 
 #  elif defined(VGP_mips64_linux)
@@ -1578,10 +1583,15 @@ void VG_(redir_initialise) ( void )
 
       /* this is mandatory - can't sanely continue without it */
       add_hardwired_spec(
-         "ld.so.3", "strlen",
+         "ld.so.1", "strlen",
          (Addr)&VG_(mips64_linux_REDIR_FOR_strlen),
          complain_about_stripped_glibc_ldso
       );
+      add_hardwired_spec(
+         "ld.so.1", "index",
+         (Addr)&VG_(mips64_linux_REDIR_FOR_index),
+         complain_about_stripped_glibc_ldso
+      );
    }
 
 #  elif defined(VGP_tilegx_linux)
index ef7c4e69b3ae0afd0660213b9e0c513f9eebaf2e..da163a3806060d9f394cdacd59eaf84e77f5eeab 100644 (file)
@@ -1269,24 +1269,43 @@ VG_(mips32_linux_SUBST_FOR_rt_sigreturn):
        
 /* There's no particular reason that this needs to be handwritten
    assembly, but since that's what this file contains, here's a
-   simple strlen implementation (written in C and compiled by gcc.)
+   simple index() and strlen() implementations.
 */
+
+.set push
+.set noreorder
+
+.global VG_(mips32_linux_REDIR_FOR_index)
+.type   VG_(mips32_linux_REDIR_FOR_index), @function
+VG_(mips32_linux_REDIR_FOR_index):
+      move $v0, $a0
+   index_loop:
+      lbu $t0, 0($v0)
+      beq $t0, $a1, index_end
+      nop
+      bne $t0, $zero, index_loop
+      addiu $v0, $v0, 1
+      move $v0, $zero
+   index_end:
+      jr $ra
+      nop
+.size VG_(mips32_linux_REDIR_FOR_index), .-VG_(mips32_linux_REDIR_FOR_index)
+
 .global VG_(mips32_linux_REDIR_FOR_strlen)
 .type   VG_(mips32_linux_REDIR_FOR_strlen), @function
 VG_(mips32_linux_REDIR_FOR_strlen):
-      li $v0, 0
-      //la $a0, string
-      j strlen_cond
+      move $v0, $a0
    strlen_loop:
-      addiu $v0, $v0, 1
-      addiu $a0, $a0, 1
-   strlen_cond:
-      lbu $t0, ($a0)
+      lbu $t0, 0($a0)
       bne $t0, $zero, strlen_loop
-    jr $ra
-
+      addiu $a0, $a0, 1
+      subu $v0, $a0, $v0
+      jr $ra
+      addiu $v0, $v0, -1
 .size VG_(mips32_linux_REDIR_FOR_strlen), .-VG_(mips32_linux_REDIR_FOR_strlen)
 
+.set pop
+
 .global VG_(trampoline_stuff_end)
 VG_(trampoline_stuff_end):
 
@@ -1319,30 +1338,43 @@ VG_(mips64_linux_SUBST_FOR_rt_sigreturn):
 
 /* There's no particular reason that this needs to be handwritten
    assembly, but since that's what this file contains, here's a
-   simple strlen implementation (written in C and compiled by gcc.)
+   simple index() and strlen() implementations.
 */
+
+.set push
+.set noreorder
+
+.global VG_(mips64_linux_REDIR_FOR_index)
+.type   VG_(mips64_linux_REDIR_FOR_index), @function
+VG_(mips64_linux_REDIR_FOR_index):
+      move $v0, $a0
+   index_loop:
+      lbu $t0, 0($v0)
+      beq $t0, $a1, index_end
+      nop
+      bne $t0, $zero, index_loop
+      daddiu $v0, $v0, 1
+      move $v0, $zero
+   index_end:
+      jr $ra
+      nop
+.size VG_(mips64_linux_REDIR_FOR_index), .-VG_(mips64_linux_REDIR_FOR_index)
+
 .global VG_(mips64_linux_REDIR_FOR_strlen)
 .type   VG_(mips64_linux_REDIR_FOR_strlen), @function
 VG_(mips64_linux_REDIR_FOR_strlen):
-        lbu $12, 0($4)
-        li  $13, 0
-        beq $12, $0, M01 
-        nop
-
-M02: 
-        addiu $13, $13, 1 
-        addiu $4, $4, 1 
-        lbu $12, 0($4) 
-        bne $12, $0, M02 
-        nop 
-
-M01: 
-        move $2, $13 
-        jr $31 
-        nop
-
+      move $v0, $a0
+   strlen_loop:
+      lbu $t0, 0($a0)
+      bne $t0, $zero, strlen_loop
+      daddiu $a0, $a0, 1
+      dsubu $v0, $a0, $v0
+      jr $ra
+      daddiu $v0, $v0, -1
 .size VG_(mips64_linux_REDIR_FOR_strlen), .-VG_(mips64_linux_REDIR_FOR_strlen)
 
+.set pop
+
 .global VG_(trampoline_stuff_end)
 VG_(trampoline_stuff_end):
 
index 1396519e891b80a3ec1e025da3f0d77ae1c19bdd..3f5516d4397a8b3d66ad91b8cd44ef96f459ece6 100644 (file)
@@ -154,11 +154,13 @@ extern void* VG_(s390x_linux_REDIR_FOR_index) ( void*, Long );
 #if defined(VGP_mips32_linux)
 extern Addr  VG_(mips32_linux_SUBST_FOR_sigreturn);
 extern Addr  VG_(mips32_linux_SUBST_FOR_rt_sigreturn);
+extern Char* VG_(mips32_linux_REDIR_FOR_index)( const Char*, Int );
 extern UInt  VG_(mips32_linux_REDIR_FOR_strlen)( void* );
 #endif
 
 #if defined(VGP_mips64_linux)
 extern Addr  VG_(mips64_linux_SUBST_FOR_rt_sigreturn);
+extern Char* VG_(mips64_linux_REDIR_FOR_index)( const Char*, Int );
 extern UInt  VG_(mips64_linux_REDIR_FOR_strlen)( void* );
 #endif