From: Nick Alcock Date: Wed, 28 Feb 2018 15:20:11 +0000 (+0000) Subject: Add replacements for wmemchr() and wcsnlen() on Linux. X-Git-Tag: VALGRIND_3_14_0~153 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=23185f46a17079fcfca35c2ef335a598812cb23b;p=thirdparty%2Fvalgrind.git Add replacements for wmemchr() and wcsnlen() on Linux. These have gained ifunc support in recent glibc releases, so need replacement. Fixes BZ#388862 Patch by: Nix --- diff --git a/NEWS b/NEWS index 3a180e91ff..5b33424a04 100644 --- a/NEWS +++ b/NEWS @@ -89,6 +89,7 @@ where XXXXXX is the bug number as listed below. 387410 MIPSr6 support 387712 s390x cgijnl reports Conditional jump depends on uninitialised value 387773 .gnu_debugaltlink paths resolve relative to .debug file, not symlink +388862 Add replacements for wmemchr and wcsnlen on Linux 389065 valgrind meets gcc flag -Wlogical-op 390723 make xtree dump files world wide readable, similar to log files diff --git a/shared/vg_replace_strmem.c b/shared/vg_replace_strmem.c index 6c946ce44f..215ab7f5ce 100644 --- a/shared/vg_replace_strmem.c +++ b/shared/vg_replace_strmem.c @@ -101,6 +101,8 @@ 20400 WCSCHR 20410 WCSRCHR 20420 STPNCPY + 20430 WMEMCHR + 20440 WCSNLEN */ #if defined(VGO_solaris) @@ -1843,9 +1845,9 @@ static inline void my_exit ( int x ) #define WCSLEN(soname, fnname) \ SizeT VG_REPLACE_FUNCTION_EZU(20370,soname,fnname) \ - ( const UInt* str ); \ + ( const Int* str ); \ SizeT VG_REPLACE_FUNCTION_EZU(20370,soname,fnname) \ - ( const UInt* str ) \ + ( const Int* str ) \ { \ SizeT i = 0; \ while (str[i] != 0) i++; \ @@ -1862,6 +1864,28 @@ static inline void my_exit ( int x ) #endif +/*---------------------- wcsnlen ----------------------*/ + +#define WCSNLEN(soname, fnname) \ + SizeT VG_REPLACE_FUNCTION_EZU(20440,soname,fnname) \ + ( const Int *s, SizeT n ); \ + SizeT VG_REPLACE_FUNCTION_EZU(20440,soname,fnname) \ + ( const Int *s, SizeT n ) \ + { \ + SizeT i = 0; \ + const Int* p = s; \ + while (i < n && *p != 0) { \ + i++; \ + p++; \ + } \ + return i; \ + } + +#if defined(VGO_linux) + WCSNLEN(VG_Z_LIBC_SONAME, wcsnlen) + WCSNLEN(VG_Z_LIBC_SONAME, __GI_wcsnlen) +#endif + /*---------------------- wcscmp ----------------------*/ // This is a wchar_t equivalent to strcmp. We don't @@ -1971,6 +1995,32 @@ static inline void my_exit ( int x ) WCSRCHR(VG_Z_LIBC_SONAME, wcsrchr) #endif + /*---------------------- wmemchr ----------------------*/ + +// This is a wchar_t equivalent to memchr. We don't +// have wchar_t available here, but in the GNU C Library +// wchar_t is always 32 bits wide. + +#define WMEMCHR(soname, fnname) \ + Int* VG_REPLACE_FUNCTION_EZU(20430,soname,fnname) \ + (const Int *s, Int c, SizeT n); \ + Int* VG_REPLACE_FUNCTION_EZU(20430,soname,fnname) \ + (const Int *s, Int c, SizeT n) \ + { \ + SizeT i; \ + const Int* p = s; \ + for (i = 0; i < n; i++) { \ + if (*p == c) return CONST_CAST(Int *,p); \ + p++; \ + } \ + return NULL; \ + } + +#if defined(VGO_linux) + WMEMCHR(VG_Z_LIBC_SONAME, wmemchr) + WMEMCHR(VG_Z_LIBC_SONAME, __GI_wmemchr) +#endif + /*------------------------------------------------------------*/ /*--- Improve definedness checking of process environment ---*/ /*------------------------------------------------------------*/