f096bf
commit b39a5966a9e64d343b65d7678e4759aed6860bec
f096bf
Author: mjw <mjw@a5019735-40e9-0310-863c-91ae7b9d1cf9>
f096bf
Date:   Wed Feb 24 11:12:01 2016 +0000
f096bf
f096bf
    Bug 359733 amd64 implement ld.so strchr/index override like x86
f096bf
    
f096bf
    The suppression and redirection for ld.so strchr/index isn't needed for
f096bf
    x86. When testing a newer glibc or calling the ld.so through an alternative
f096bf
    path neither the suppression (doesn't match path/name) nor the redirection
f096bf
    (triggers too late) works. Since there is already an hardwire override for
f096bf
    strlen in amd64 ld.so anyway it makes sense to also hardware index (it is
f096bf
    always called when ld.so loads the preload images).
f096bf
    
f096bf
    This was also explained in the easy hacks Fosdem session.
f096bf
    See https://bugs.kde.org/show_bug.cgi?id=359733 for a pointer.
f096bf
    
f096bf
    git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15812 a5019735-40e9-0310-863c-91ae7b9d1cf9
f096bf
f096bf
diff --git a/coregrind/m_redir.c b/coregrind/m_redir.c
f096bf
index dcf1fb4..dae47f1 100644
f096bf
--- a/coregrind/m_redir.c
f096bf
+++ b/coregrind/m_redir.c
f096bf
@@ -1353,6 +1353,9 @@ void VG_(redir_initialise) ( void )
f096bf
    if (0==VG_(strcmp)("Memcheck", VG_(details).name)) {
f096bf
 
f096bf
       add_hardwired_spec(
f096bf
+         "ld-linux-x86-64.so.2", "index",
f096bf
+         (Addr)&VG_(amd64_linux_REDIR_FOR_index), NULL);
f096bf
+      add_hardwired_spec(
f096bf
          "ld-linux-x86-64.so.2", "strlen",
f096bf
          (Addr)&VG_(amd64_linux_REDIR_FOR_strlen),
f096bf
 #        ifndef GLIBC_MANDATORY_STRLEN_REDIRECT
f096bf
diff --git a/coregrind/m_trampoline.S b/coregrind/m_trampoline.S
f096bf
index cac2288..176ea66 100644
f096bf
--- a/coregrind/m_trampoline.S
f096bf
+++ b/coregrind/m_trampoline.S
f096bf
@@ -220,6 +220,30 @@ VG_(amd64_linux_REDIR_FOR_strlen):
f096bf
 .LfnE5:
f096bf
 .size VG_(amd64_linux_REDIR_FOR_strlen), .-VG_(amd64_linux_REDIR_FOR_strlen)
f096bf
 
f096bf
+.global VG_(amd64_linux_REDIR_FOR_index)
f096bf
+.type   VG_(amd64_linux_REDIR_FOR_index), @function
f096bf
+VG_(amd64_linux_REDIR_FOR_index):
f096bf
+        movzbl  (%rdi), %eax
f096bf
+        movl    %esi, %edx
f096bf
+        cmpb    %sil, %al
f096bf
+        jne     .L4
f096bf
+        jmp     .L5
f096bf
+.L10:
f096bf
+        addq    $1, %rdi
f096bf
+        movzbl  (%rdi), %eax
f096bf
+        cmpb    %dl, %al
f096bf
+        je      .L5
f096bf
+.L4:
f096bf
+        testb   %al, %al
f096bf
+        jne     .L10
f096bf
+        xorl    %eax, %eax
f096bf
+        ret
f096bf
+.L5:
f096bf
+        movq    %rdi, %rax
f096bf
+        ret
f096bf
+.size VG_(amd64_linux_REDIR_FOR_index), .-VG_(amd64_linux_REDIR_FOR_index)
f096bf
+
f096bf
+
f096bf
 
f096bf
 /* A CIE for the above four functions, followed by their FDEs */
f096bf
 	.section .eh_frame,"a",@progbits
f096bf
diff --git a/coregrind/pub_core_trampoline.h b/coregrind/pub_core_trampoline.h
f096bf
index eda5ec6..1396519 100644
f096bf
--- a/coregrind/pub_core_trampoline.h
f096bf
+++ b/coregrind/pub_core_trampoline.h
f096bf
@@ -71,6 +71,7 @@ extern Addr VG_(amd64_linux_REDIR_FOR_vgettimeofday);
f096bf
 extern Addr VG_(amd64_linux_REDIR_FOR_vtime);
f096bf
 extern Addr VG_(amd64_linux_REDIR_FOR_vgetcpu);
f096bf
 extern UInt VG_(amd64_linux_REDIR_FOR_strlen)( void* );
f096bf
+extern Char* VG_(amd64_linux_REDIR_FOR_index) ( const Char*, Int );
f096bf
 #endif
f096bf
 
f096bf
 #if defined(VGP_ppc32_linux)
f096bf
diff --git a/shared/vg_replace_strmem.c b/shared/vg_replace_strmem.c
f096bf
index 005b679..8de085a 100644
f096bf
--- a/shared/vg_replace_strmem.c
f096bf
+++ b/shared/vg_replace_strmem.c
f096bf
@@ -247,7 +247,7 @@ static inline void my_exit ( int x )
f096bf
  STRCHR(VG_Z_LIBC_SONAME,          __strchr_sse2)
f096bf
  STRCHR(VG_Z_LIBC_SONAME,          __strchr_sse2_no_bsf)
f096bf
  STRCHR(VG_Z_LIBC_SONAME,          index)
f096bf
-# if !defined(VGP_x86_linux)
f096bf
+# if !defined(VGP_x86_linux) && !defined(VGP_amd64_linux)
f096bf
   STRCHR(VG_Z_LD_LINUX_SO_2,        strchr)
f096bf
   STRCHR(VG_Z_LD_LINUX_SO_2,        index)
f096bf
   STRCHR(VG_Z_LD_LINUX_X86_64_SO_2, strchr)