|
From: Paul F. <pa...@so...> - 2025-11-01 16:04:56
|
https://sourceware.org/cgit/valgrind/commit/?id=87631266a5375a5fad1e6e0cb20c93ed8b7ef43f commit 87631266a5375a5fad1e6e0cb20c93ed8b7ef43f Author: Paul Floyd <pj...@wa...> Date: Sat Nov 1 16:56:20 2025 +0100 Darwin regtest: add an expected for duplicate_align_size_errors Also start trying to del with some redir issues. For some libc functions the plain function gets replaced by a checked version (not sure if this is only for debug builds). For instance in /usr/include/secure/_string.h there are a load of macros that look like /* void *memccpy(void *dst, const void *src, int c, size_t n) */ __builtin___memccpy_chk (dest, __VA_ARGS__, __darwin_obsz0 (dest)) To defeat these macros I've put the function name in parens. That hasn't solved the issue. In addition these seems to be an ifunc like mechanism that resolves calls to platform functions. For instance nm /usr/lib/system/*dylib | grep memcc 0000000000081e14 T ___memccpy_chk U __platform_memccpy I _memccpy (indirect for __platform_memccpy) 0000000000004eb4 T __platform_memccpy That matches what I see in lldb (memccpy then function lookup code then _platform_memccpy). Need to look at how indirects work. Diff: --- memcheck/tests/Makefile.am | 1 + .../duplicate_align_size_errors.stderr.out-darwin | 22 ++++++++++++++++++++++ memcheck/tests/memccpy2.c | 8 ++++---- memcheck/tests/overlap.c | 10 +++++----- 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/memcheck/tests/Makefile.am b/memcheck/tests/Makefile.am index fd3f89cd28..755f422ee5 100644 --- a/memcheck/tests/Makefile.am +++ b/memcheck/tests/Makefile.am @@ -168,6 +168,7 @@ EXTRA_DIST = \ cxx17_aligned_new.stdout.exp \ duplicate_align_size_errors.stderr.exp \ duplicate_align_size_errors.stderr.exp-memalign \ + duplicate_align_size_errors.stderr.exp-darwin \ duplicate_align_size_errors.vgtest \ sized_aligned_new_delete_args.stderr.exp \ sized_aligned_new_delete_args.vgtest \ diff --git a/memcheck/tests/duplicate_align_size_errors.stderr.out-darwin b/memcheck/tests/duplicate_align_size_errors.stderr.out-darwin new file mode 100644 index 0000000000..93faa3d16a --- /dev/null +++ b/memcheck/tests/duplicate_align_size_errors.stderr.out-darwin @@ -0,0 +1,22 @@ +Invalid alignment value: 0 (should be non-zero and a power of 2) + at 0x........: operator new(unsigned long, std::align_val_t, std::nothrow_t const&) (vg_replace_malloc.c:...) + by 0x........: main (duplicate_align_size_errors.cpp:19) + +Invalid alignment value: 0 (should be non-zero and a power of 2) + at 0x........: operator delete(void*, std::align_val_t, std::nothrow_t const&) (vg_replace_malloc.c:...) + by 0x........: main (duplicate_align_size_errors.cpp:20) + +Mismatched new/delete size value: 33 + at 0x........: operator delete(void*, unsigned long, std::align_val_t) (vg_replace_malloc.c:...) + by 0x........: main (duplicate_align_size_errors.cpp:43) + Address 0x........ is 0 bytes inside a block of size 32 alloc'd + at 0x........: operator new(unsigned long, std::align_val_t) (vg_replace_malloc.c:...) + by 0x........: main (duplicate_align_size_errors.cpp:42) + +Mismatched new[]/delete[] alignment alloc value: 64 dealloc value: 128 + at 0x........: operator delete[](void*, unsigned long, std::align_val_t) (vg_replace_malloc.c:...) + by 0x........: main (duplicate_align_size_errors.cpp:48) + Address 0x........ is 0 bytes inside a block of size 32 alloc'd + at 0x........: operator new[](unsigned long, std::align_val_t) (vg_replace_malloc.c:...) + by 0x........: main (duplicate_align_size_errors.cpp:47) + diff --git a/memcheck/tests/memccpy2.c b/memcheck/tests/memccpy2.c index 9473245817..be7808d5fd 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 d868886f38..649b1e34d3 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' */ |