From: Mark Wielaard Date: Wed, 12 Mar 2025 12:57:19 +0000 (+0100) Subject: add_hardwired_spec for ld-linux-x86-64.so.2 memcmp X-Git-Tag: VALGRIND_3_25_0~106 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9ffdeb4927b8505cc5a9ea54f608f4972166bb0e;p=thirdparty%2Fvalgrind.git add_hardwired_spec for ld-linux-x86-64.so.2 memcmp 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 --- diff --git a/NEWS b/NEWS index 16cfeef2a..7025d61af 100644 --- 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 diff --git a/coregrind/m_redir.c b/coregrind/m_redir.c index 5e7bc42f9..63172b971 100644 --- a/coregrind/m_redir.c +++ b/coregrind/m_redir.c @@ -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 ); } diff --git a/coregrind/m_trampoline.S b/coregrind/m_trampoline.S index 4860a2259..2c2cc0dc2 100644 --- a/coregrind/m_trampoline.S +++ b/coregrind/m_trampoline.S @@ -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): diff --git a/coregrind/pub_core_trampoline.h b/coregrind/pub_core_trampoline.h index db497c51a..11d791df7 100644 --- a/coregrind/pub_core_trampoline.h +++ b/coregrind/pub_core_trampoline.h @@ -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