Clobber ecx for clang x86 leak tests

The assembler for leak-cases.c on x86 with clang for f() ends with

  40198b:       c7 04 24 00 00 00 00    movl   $0x0,(%esp)
  401992:       e8 c9 fe ff ff          call   401860 <mk>
  401997:       89 04 24                mov    %eax,(%esp)
  40199a:       e8 c1 fe ff ff          call   401860 <mk>
  40199f:       a3 74 40 40 00          mov    %eax,0x404074
  4019a4:       a1 74 40 40 00          mov    0x404074,%eax
  4019a9:       8b 08                   mov    (%eax),%ecx
  4019ab:       83 c1 08                add    $0x8,%ecx
  4019ae:       89 08                   mov    %ecx,(%eax)
  4019b0:       c7 05 74 40 40 00 00    movl   $0x0,0x404074
  4019b7:       00 00 00
  4019ba:       83 c4 04                add    $0x4,%esp
  4019bd:       5d                      pop    %ebp
  4019be:       c3                      ret

If I've read that correctly, at the enc ECX contains the pointer
to allocated memory returned by mk() plus 8.

main() doesn't clobber ECX either, so this shows up in the
leak checks.

Clobbering ECX fixes the following testcases on FreeBSD 13.1 x86 with clang 13

< gdbserver_tests/mcblocklistsearch        (stderrB)
< memcheck/tests/leak-cases-full           (stderr)
< memcheck/tests/leak-cases-summary        (stderr)
< memcheck/tests/leak-cycle                (stderr)
< memcheck/tests/leak-tree                 (stderr)
< memcheck/tests/lks                       (stderr)
This commit is contained in:
Paul Floyd 2022-05-19 22:40:03 +02:00
parent c10e4e864f
commit 98774bffd2

View File

@ -143,6 +143,11 @@
"$8", "$9", "$10", "$11", "$12", "$13", \
"$14", "$15", "$24", "$25", "$31"); \
} while (0)
#elif defined (__clang__) && defined(VGA_x86)
#define CLEAR_CALLER_SAVED_REGS \
do { \
__asm__ __volatile__ ("movl $0, %ecx\n\t"); \
} while (0)
#else
#define CLEAR_CALLER_SAVED_REGS /*nothing*/
#endif