|
From: Paul F. <pa...@so...> - 2025-11-09 20:58:45
|
https://sourceware.org/cgit/valgrind/commit/?id=ed27b47d8101f6d850a8fd50589e750cae09c43e commit ed27b47d8101f6d850a8fd50589e750cae09c43e Author: Paul Floyd <pj...@wa...> Date: Sun Nov 9 21:57:01 2025 +0100 Darwin redirs: add several str* amd mem* redirs to vg_replace_strmem.c Mostly these are _chk variants. I've also undone a change that forced the compiler to not use these variants. Diff: --- memcheck/tests/Makefile.am | 22 ++++++++++++++++++++++ memcheck/tests/filter_libc_variants | 2 +- memcheck/tests/memccpy2.c | 8 ++++---- memcheck/tests/overlap.c | 10 +++++----- memcheck/tests/overlap.vgtest | 1 + shared/vg_replace_strmem.c | 15 ++++++++------- 6 files changed, 41 insertions(+), 17 deletions(-) diff --git a/memcheck/tests/Makefile.am b/memcheck/tests/Makefile.am index 6343b1b7c8..5cdc2082c9 100644 --- a/memcheck/tests/Makefile.am +++ b/memcheck/tests/Makefile.am @@ -814,7 +814,13 @@ origin4_many_CFLAGS = $(AM_CFLAGS) -O @FLAG_W_NO_USE_AFTER_FREE@ @FLAG_W_NO_UNIN # Apply -O so as to run in reasonable time. origin5_bz2_CFLAGS = $(AM_CFLAGS) -O -Wno-inline +if VGCONF_OS_IS_DARWIN +origin5_bz2_CFLAGS += -fno-inline +endif origin6_fp_CFLAGS = $(AM_CFLAGS) -O +if VGCONF_OS_IS_DARWIN +origin6_fp_CFLAGS += -fno-inline +endif # Don't allow GCC to inline memcpy() and strcpy(), # because then we can't intercept it @@ -876,11 +882,27 @@ wrap6_CFLAGS = $(AM_CFLAGS) -O2 # To make it a bit more realistic, have some optimisation enabled # for the varinfo tests. We still expect sane results. varinfo1_CFLAGS = $(AM_CFLAGS) -O @FLAG_W_NO_MAYBE_UNINITIALIZED@ +if VGCONF_OS_IS_DARWIN +varinfo1_CFLAGS += -fno-inline +endif varinfo2_CFLAGS = $(AM_CFLAGS) -O -Wno-shadow @FLAG_W_NO_MAYBE_UNINITIALIZED@ +if VGCONF_OS_IS_DARWIN +varinfo2_CFLAGS += -fno-inline +endif varinfo3_CFLAGS = $(AM_CFLAGS) -O @FLAG_W_NO_MAYBE_UNINITIALIZED@ +if VGCONF_OS_IS_DARWIN +varinfo3_CFLAGS += -fno-inline +endif varinfo4_CFLAGS = $(AM_CFLAGS) -O @FLAG_W_NO_MAYBE_UNINITIALIZED@ +if VGCONF_OS_IS_DARWIN +varinfo4_CFLAGS += -fno-inline +endif varinfo5_CFLAGS = $(AM_CFLAGS) -O varinfo6_CFLAGS = $(AM_CFLAGS) -O @FLAG_W_NO_MAYBE_UNINITIALIZED@ +if VGCONF_OS_IS_DARWIN +varinfo6_CFLAGS += -fno-inline +endif + # Build shared object for varinfo5 varinfo5_SOURCES = varinfo5.c diff --git a/memcheck/tests/filter_libc_variants b/memcheck/tests/filter_libc_variants index bfffa84689..3ecf1fb808 100755 --- a/memcheck/tests/filter_libc_variants +++ b/memcheck/tests/filter_libc_variants @@ -2,4 +2,4 @@ ./filter_stderr "$@" | -sed 's/ _platform_memcmp / memcmp /;s/ bcmp / memcmp /;s/ _platform_memccpy / memccpy /' +sed 's/ _platform_memcmp / memcmp /;s/ bcmp / memcmp /;s/ _platform_memccpy / memccpy /;s/ __memccpy_chk / memccpy /;s/ __strncat_chk / strncat /;s/ __strncpy_chk / strncpy /;s/ __strcpy_chk / strcpy /' diff --git a/memcheck/tests/memccpy2.c b/memcheck/tests/memccpy2.c index be7808d5fd..9473245817 100644 --- a/memcheck/tests/memccpy2.c +++ b/memcheck/tests/memccpy2.c @@ -8,9 +8,9 @@ int main(void) { char* astring = strdup("this is a string # with something to seek"); size_t len = strlen(astring); - (memccpy)(astring+10, astring, '#', len-10); + memccpy(astring+10, astring, '#', len-10); sprintf(astring, "this is a string # with something to seek"); - (memccpy)(astring, astring+10, '#', len); + memccpy(astring, astring+10, '#', len); sprintf(astring, "this is a string # with something to seek"); /* @@ -23,10 +23,10 @@ int main(void) assert(res && *res == 'g'); sprintf(astring, "this is a string # with something to seek"); /* length is 0, nothing copied, returns NULL */ - res = (memccpy)(astring, "abcdefhhijklmnopqrstuvwxy", 'z', 0); + res = memccpy(astring, "abcdefhhijklmnopqrstuvwxy", 'z', 0); assert(NULL == res); /* 'z' not found so 20 bytes copied, returns NULL */ - res = (memccpy)(astring, "abcdefhhijklmnopqrstuvwxy", 'z', 20); + res = memccpy(astring, "abcdefhhijklmnopqrstuvwxy", 'z', 20); assert(NULL == res); free(astring); } diff --git a/memcheck/tests/overlap.c b/memcheck/tests/overlap.c index 649b1e34d3..d868886f38 100644 --- a/memcheck/tests/overlap.c +++ b/memcheck/tests/overlap.c @@ -42,16 +42,16 @@ int main(void) memcpy(x, x+20, 21); // overlap strncpy(x+20, x, 20); // ok - (strncpy)(x+20, x, 21); // overlap + strncpy(x+20, x, 21); // overlap strncpy(x, x+20, 20); // ok - (strncpy)(x, x+20, 21); // overlap + strncpy(x, x+20, 21); // overlap x[39] = '\0'; strcpy(x, x+20); // ok x[39] = 39; x[40] = '\0'; - (strcpy)(x, x+20); // overlap + strcpy(x, x+20); // overlap x[19] = '\0'; strcpy(x+20, x); // ok @@ -109,8 +109,8 @@ int main(void) always run forever, I think... */ for ( i = 0; i < 2; i++) - (strncat)(a+20, a, 21); // run twice to check 2nd error isn't shown - (strncat)(a, a+20, 21); + strncat(a+20, a, 21); // run twice to check 2nd error isn't shown + strncat(a, a+20, 21); /* This is ok, but once gave a warning when strncpy() was wrong, and used 'n' for the length, even when the src was shorter than 'n' */ diff --git a/memcheck/tests/overlap.vgtest b/memcheck/tests/overlap.vgtest index 7e49d95c80..166bf73f7e 100644 --- a/memcheck/tests/overlap.vgtest +++ b/memcheck/tests/overlap.vgtest @@ -2,3 +2,4 @@ prog: overlap vgopts: -q # https://bugs.kde.org/show_bug.cgi?id=402833 prereq: ! ../../tests/os_test linux || ! ../../tests/arch_test amd64 +stderr_filter: filter_libc_variants diff --git a/shared/vg_replace_strmem.c b/shared/vg_replace_strmem.c index 5ef4884efa..d9de90b411 100644 --- a/shared/vg_replace_strmem.c +++ b/shared/vg_replace_strmem.c @@ -386,7 +386,8 @@ static inline void my_exit ( int x ) STRNCAT(VG_Z_LIBC_SONAME, strncat) #elif defined(VGO_darwin) - //STRNCAT(VG_Z_LIBC_SONAME, strncat) + STRNCAT(VG_Z_LIBSYSTEM_C_SONAME, strncat) + STRNCAT(VG_Z_LIBSYSTEM_C_SONAME, __strncat_chk) //STRNCAT(VG_Z_DYLD, strncat) #elif defined(VGO_solaris) @@ -572,9 +573,8 @@ static inline void my_exit ( int x ) #elif defined(VGO_darwin) STRCPY(VG_Z_LIBC_SONAME, strcpy) -# if DARWIN_VERS == DARWIN_10_9 - STRCPY(VG_Z_LIBSYSTEM_C_SONAME, strcpy) -# endif + STRCPY(VG_Z_LIBSYSTEM_C_SONAME, strcpy) + STRCPY(VG_Z_LIBSYSTEM_C_SONAME, __strcpy_chk) #elif defined(VGO_solaris) STRCPY(VG_Z_LIBC_SONAME, strcpy) @@ -620,9 +620,8 @@ static inline void my_exit ( int x ) #elif defined(VGO_darwin) STRNCPY(VG_Z_LIBC_SONAME, strncpy) -# if DARWIN_VERS >= DARWIN_10_9 - STRNCPY(VG_Z_LIBSYSTEM_C_SONAME, strncpy) -# endif + STRNCPY(VG_Z_LIBSYSTEM_C_SONAME, strncpy) + STRNCPY(VG_Z_LIBSYSTEM_C_SONAME, __strncpy_chk) #elif defined(VGO_solaris) STRNCPY(VG_Z_LIBC_SONAME, strncpy) @@ -1175,6 +1174,7 @@ static inline void my_exit ( int x ) # endif MEMCPY(VG_Z_LIBC_SONAME, memcpyZDVARIANTZDsse3x) /* memcpy$VARIANT$sse3x */ MEMCPY(VG_Z_LIBC_SONAME, memcpyZDVARIANTZDsse42) /* memcpy$VARIANT$sse42 */ + MEMCPY(VG_Z_LIBSYSTEM_C_SONAME, __memcpy_chk) #elif defined(VGO_solaris) MEMCPY(VG_Z_LIBC_SONAME, memcpy) @@ -2383,6 +2383,7 @@ static inline void my_exit ( int x ) #if defined(VGO_linux) || defined(VGO_freebsd) || defined(VGO_solaris) MEMCCPY(VG_Z_LIBC_SONAME, memccpy) #elif defined(VGO_darwin) + MEMCCPY(VG_Z_LIBSYSTEM_C_SONAME, __memccpy_chk) MEMCCPY(VG_Z_LIBSYSTEM_PLATFORM_SONAME, _platform_memccpy) #endif |