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