https://bugs.kde.org/show_bug.cgi?id=392855

David Rankin <drankina...@suddenlinkmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|INVALID                     |---
     Ever confirmed|0                           |1
             Status|RESOLVED                    |REOPENED

--- Comment #2 from David Rankin <drankina...@suddenlinkmail.com> ---
There is definitely a problem with either valgrind or libc. For Example,

OpenSuSE Leap 42.3 correctly reports the number of allocations and the amount
of memory allocated.

$ valgrind ./bin/vgtest2
==4142== Memcheck, a memory error detector
==4142== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==4142== Using Valgrind-3.12.0 and LibVEX; rerun with -h for copyright info
==4142== Command: ./bin/vgtest2
==4142==
a: 5
==4142==
==4142== HEAP SUMMARY:
==4142==     in use at exit: 0 bytes in 0 blocks
==4142==   total heap usage: 1 allocs, 1 frees, 4 bytes allocated
==4142==
==4142== All heap blocks were freed -- no leaks are possible
==4142==
==4142== For counts of detected and suppressed errors, rerun with: -v
==4142== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

That is with:
gcc --version
gcc (SUSE Linux) 4.8.5
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


The assembly generated is:

$ gcc -S -Ofast -o vgtest2.asm vgtest2.c

$ cat vgtest2.asm
        .file   "vgtest2.c"
        .section        .rodata.str1.1,"aMS",@progbits,1
.LC0:
        .string "a: %d\n"
        .section        .text.startup,"ax",@progbits
        .p2align 4,,15
        .globl  main
        .type   main, @function
main:
.LFB21:
        .cfi_startproc
        pushq   %rbx
        .cfi_def_cfa_offset 16
        .cfi_offset 3, -16
        movl    $4, %edi
        call    malloc
        movl    $5, %esi
        movq    %rax, %rbx
        movl    $5, (%rax)
        movl    $.LC0, %edi
        xorl    %eax, %eax
        call    printf
        movq    %rbx, %rdi
        call    free
        popq    %rbx
        .cfi_def_cfa_offset 8
        ret
        .cfi_endproc
.LFE21:
        .size   main, .-main
        .ident  "GCC: (SUSE Linux) 4.8.5"
        .section        .note.GNU-stack,"",@progbits

Now on Archlinux, valgrind incorrectly reports the amount of memory allocated:

$ gcc --version
gcc (GCC) 7.3.1 20180406
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ valgrind ./bin/vgtest2
==8639== Memcheck, a memory error detector
==8639== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==8639== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==8639== Command: ./bin/vgtest2
==8639==
a: 5
==8639==
==8639== HEAP SUMMARY:
==8639==     in use at exit: 0 bytes in 0 blocks
==8639==   total heap usage: 1 allocs, 1 frees, 1,024 bytes allocated
==8639==
==8639== All heap blocks were freed -- no leaks are possible
==8639==
==8639== For counts of detected and suppressed errors, rerun with: -v
==8639== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

The generated assembly is different:
gcc -S -Ofast -o vgtest2.asm vgtest2.c

$ cat vgtest2.asm
        .file   "vgtest2.c"
        .text
        .section        .rodata.str1.1,"aMS",@progbits,1
.LC0:
        .string "a: %d\n"
        .section        .text.startup,"ax",@progbits
        .p2align 4,,15
        .globl  main
        .type   main, @function
main:
.LFB24:
        .cfi_startproc
        leaq    .LC0(%rip), %rdi
        subq    $8, %rsp
        .cfi_def_cfa_offset 16
        movl    $5, %esi
        xorl    %eax, %eax
        call    printf@PLT
        xorl    %eax, %eax
        addq    $8, %rsp
        .cfi_def_cfa_offset 8
        ret
        .cfi_endproc
.LFE24:
        .size   main, .-main
        .ident  "GCC: (GNU) 7.3.1 20180406"
        .section        .note.GNU-stack,"",@progbits


Now something is broken in the valgrind reporting of memory allocated. It can't
work correctly -- and then not work correctly -- and ho, hum, something must
have change.... Yes, there is a bug somewhere.

If this isn't a valgrind bug, then I would appreciate suggestions on who the
proper owner for the bug is.

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to