Created attachment 1554772 [details] Reproducer Description of problem: Valgrind finds multiple invalid writes in programs which use libcmocka and are compiled on arm architecture. See log and reproducer in attachments. Version-Release number of selected component (if applicable): libcmocka-1.1.5-1.fc29.armv7hl valgrind-1:3.14.0-10.fc29.armv7hl gcc-8.3.1-2.fc29.armv7hl How reproducible: Compile reproducer from attachments on arm and run valgrind on it. Steps to Reproduce: 1. $ gcc cmocka_reproducer.c -o cmocka_reproducer -lcmocka 2. $ valgrind ./cmocka_reproducer Actual results: Multiple messages with invalid writes. Expected results: No messages. Additional info:
Created attachment 1554773 [details] Valgrind's logs
==10538== Invalid write of size 4 ==10538== at 0x4867360: _assert_string_equal (cmocka.c:1815) ==10538== by 0x104A3: main (in /home/tkorbar/cmocka_reproducer) ==10538== Address 0xbde1eab0 is on thread 1's stack ==10538== 24 bytes below stack pointer Looking at the code, I'm not sure were a invalid write of 4 should be here: 1814 void _assert_string_equal(const char * const a, const char * const b, 1815 const char * const file, const int line) { ==10538== Invalid write of size 4 ==10538== at 0x48649F0: cm_print_error (cmocka.c:2251) ==10538== by 0x4867393: string_equal_display_error (cmocka.c:1299) ==10538== by 0x4867393: _assert_string_equal (cmocka.c:1816) ==10538== by 0x104A3: main (in /home/tkorbar/cmocka_reproducer) ==10538== Address 0xbde1eaa0 is on thread 1's stack ==10538== 16 bytes below stack pointer 2250 void cm_print_error(const char * const format, ...) 2251 { This also points to a bogus line. This is either a bug in valgrind or a bug in gcc on ARM.
I noticed the same problem om Mageia. All the invalid writes are on the { line of the function so my guess would be some code added by gcc (I believe -fstack-protector would add some code when the function is entered)
I noticed cmocka gets built with -fstack-clash-protection so this is probably https://bugzilla.redhat.com/show_bug.cgi?id=1522678
I have confirmed the problem goes away with this (ugly, just for testing :) ) patch: --- cmocka-1.1.5/CompilerChecks.cmake.sav 2019-09-30 08:58:18.445946241 +0000 +++ cmocka-1.1.5/CompilerChecks.cmake 2019-09-30 08:58:45.066525089 +0000 @@ -84,11 +84,6 @@ endif() endif (WITH_STACK_PROTECTOR_STRONG) - check_c_compiler_flag_ssp("-fstack-clash-protection" WITH_STACK_CLASH_PROTECTION) - if (WITH_STACK_CLASH_PROTECTION) - list(APPEND SUPPORTED_COMPILER_FLAGS "-fstack-clash-protection") - endif() - if (PICKY_DEVELOPER) add_c_compiler_flag("-Wno-error=deprecated-declarations" SUPPORTED_COMPILER_FLAGS) add_c_compiler_flag("-Wno-error=tautological-compare" SUPPORTED_COMPILER_FLAGS)
So this is either compiler issue (-fstack-clash-protection not implemented correctly on ARM) or a valgrind issue seeing things which don't exist. Closing as comment #5 confirms it is not a cmocka bug.