]> 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:12:43 +0000 (14:12 +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>
NEWS
coregrind/m_redir.c
coregrind/m_trampoline.S
coregrind/pub_core_trampoline.h

diff --git a/NEWS b/NEWS
index 16cfeef2a4f77f33ac82e5dcb13e5f16cb3cba11..7025d61af7f6fc673b54ccf5d1df6db5e950346e 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -58,6 +58,7 @@ are not entered into bugzilla tend to get forgotten about or ignored.
 499212  mmap() with MAP_ALIGNED() returns unaligned pointer
 501119  memcheck/tests/pointer-trace fails when run on NFS filesystem
 501194  Fix ML_(check_macho_and_get_rw_loads) so that it is correct for any number of segment commands
+501348 glibc built with -march=x86-64-v3 does not work due to ld.so memcmp
 
 
 To see details of a given bug, visit
index 5e7bc42f9757f2b7cb8b816cb44cf57924797523..63172b97178eb9c67ad51ef2e3fd9c61459c62a5 100644 (file)
@@ -1431,6 +1431,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 4860a2259f0bc587abb8173f5bb49b7c0933a210..2c2cc0dc2a3d2f0e017bc670a677d884a41242c0 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 db497c51a51c35188c29ed9dcc8881154c7972d7..11d791df7c89e4414124137cddd32cc9244d120c 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