]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
add_hardwired_spec for ld-linux-x86-64.so.2 memcmp
authorMark Wielaard <mark@klomp.org>
Wed, 12 Mar 2025 12:57:19 +0000 (13:57 +0100)
committerMark Wielaard <mark@klomp.org>
Wed, 12 Mar 2025 13:25:24 +0000 (14:25 +0100)
With RPATH processing ld.so compiled for x86-64-v3 uses an optimized
avx2 memcmp (bcmp) which causes (false postive) memcheck invalid reads
of size 32 warnings.

Fix this my adding a hardwire spec with a simpler memcmp for
ld-linux-x86-64.so.2.

https://bugs.kde.org/show_bug.cgi?id=501348

Authored-by: Florian Weimer <fweimer@redhat.com>
(cherry picked from commit 9ffdeb4927b8505cc5a9ea54f608f4972166bb0e)

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

diff --git a/NEWS b/NEWS
index 7f9e005c59f4a64c821f74e9b6b77b9cae2473e0..fe225c666c774c5df9d6471b20daf01e6ebfc6f6 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -11,6 +11,7 @@ The following bugs have been fixed or resolved on this branch.
 498317  FdBadUse is not a valid CoreError type in a suppression
         even though it's generated by --gen-suppressions=yes
 498143  False positive on EVIOCGRAB ioctl
+501348  glibc built with -march=x86-64-v3 does not work due to ld.so memcmp
 
 To see details of a given bug, visit
   https://bugs.kde.org/show_bug.cgi?id=XXXXXX
index f9e8d8801a192e894ae901a30ba525ab490f5ee6..64ebea3b6304c2d68e2b70f44c28e1ee40a33d51 100644 (file)
@@ -1425,6 +1425,15 @@ void VG_(redir_initialise) ( void )
          NULL
 #        else
          complain_about_stripped_glibc_ldso
+#        endif
+      );
+      add_hardwired_spec(
+         "ld-linux-x86-64.so.2", "memcmp",
+         (Addr)&VG_(amd64_linux_REDIR_FOR_memcmp),
+#        ifndef GLIBC_MANDATORY_STRLEN_REDIRECT
+         NULL
+#        else
+         complain_about_stripped_glibc_ldso
 #        endif
       );
    }
index e897963be21a46ae2c8b674cd9d67ed4bb4b82c4..27f1b35d2b0875515f7b542f38b849e37c9cc252 100644 (file)
@@ -241,6 +241,25 @@ VG_(amd64_linux_REDIR_FOR_strcmp):
        ret
 .size VG_(amd64_linux_REDIR_FOR_strcmp), .-VG_(amd64_linux_REDIR_FOR_strcmp)
 
+.global VG_(amd64_linux_REDIR_FOR_memcmp)
+.type   VG_(amd64_linux_REDIR_FOR_memcmp), @function
+VG_(amd64_linux_REDIR_FOR_memcmp):
+       xorl    %ecx, %ecx
+       jmp     2f
+1:
+       movzbl  (%rdi, %rcx), %eax
+       movzbl  (%rsi, %rcx), %r8d
+       addq    $1, %rcx
+       subl    %r8d, %eax
+       jne     3f
+2:
+       cmpq    %rcx, %rdx
+       jne     1b
+       xorl    %eax, %eax
+3:
+       ret
+.size VG_(amd64_linux_REDIR_FOR_memcmp), .-VG_(amd64_linux_REDIR_FOR_memcmp)
+
 .global VG_(amd64_linux_REDIR_FOR_index)
 .type   VG_(amd64_linux_REDIR_FOR_index), @function
 VG_(amd64_linux_REDIR_FOR_index):
index d0bd6b859742263e1da59e24e855e5b2ad19dc9e..3d2f7e9f32b729fe4c191191681f909d0469fa1f 100644 (file)
@@ -82,6 +82,7 @@ extern Addr VG_(amd64_linux_REDIR_FOR_vtime);
 extern Addr VG_(amd64_linux_REDIR_FOR_vgetcpu);
 extern UInt VG_(amd64_linux_REDIR_FOR_strlen)( void* );
 extern Int VG_(amd64_linux_REDIR_FOR_strcmp)( void*, void* );
+extern Int VG_(amd64_linux_REDIR_FOR_memcmp)( void*, void*, SizeT );
 extern Char* VG_(amd64_linux_REDIR_FOR_index) ( const Char*, Int );
 #endif