autoconf and valgrind goes crazy

autoconf and valgrind goes crazy

From: Kyryl Melekhin
To: dev
Hello kiss community!

This is my first message ever to this mailing list.

I am currently experiencing a weird bug in valgrind, where it
mistakenly does not recognize realloc function and also produces
weird warnings.

Consider this simple C program:

#include "stdio.h"
#include "stdlib.h"

int main()
{
        char *mem = malloc(123);
        *mem = 5;
        *(mem+1) = 5;
        *(mem+2) = 5;

        mem = realloc(mem, 400);
        *(mem+1) = 5;
        *(mem+2) = 5;
        free(mem);
        return 0;
}

As you can see there can't be any bugs in this code, everything is
within bounds.

However when I run
$ valgrind ./a.out
==486== Memcheck, a memory error detector
==486== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==486== Using Valgrind-3.18.0.GIT and LibVEX; rerun with -h for copyright info
==486== Command: ./a.out
==486==
==486== Invalid free() / delete / delete[] / realloc()
==486==    at 0x48C589F: realloc (vg_replace_malloc.c:1192)
==486==    by 0x109298: main (in /root/test/a.out)
==486==  Address 0x48baf80 is in a rw- mapped file
/usr/local/libexec/valgrind/vgpreload_core-amd64-linux.so segment
==486==
==486== Invalid write of size 1
==486==    at 0x1092A5: main (in /root/test/a.out)
==486==  Address 0x1 is not stack'd, malloc'd or (recently) free'd
==486==
==486==
==486== Process terminating with default action of signal 11 (SIGSEGV)
==486==  Access not within mapped region at address 0x1
==486==    at 0x1092A5: main (in /root/test/a.out)
==486==  If you believe this happened as a result of a stack
==486==  overflow in your program's main thread (unlikely but
==486==  possible), you can try to increase the size of the
==486==  main thread stack using the --main-stacksize= flag.
==486==  The main thread stack size used in this run was 8388608.
==486==
==486== HEAP SUMMARY:
==486==     in use at exit: 0 bytes in 0 blocks
==486==   total heap usage: 1 allocs, 1 frees, 400 bytes allocated
==486==
==486== All heap blocks were freed -- no leaks are possible
==486==
==486== For lists of detected and suppressed errors, rerun with: -s
==486== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)
Segmentation fault

This happens.

musl version is 1.2.2 from KISS linux
https://github.com/kiss-community/repo-main/tree/master/core/musl

I built valgrind myself from source without any special
configuration. I also tested it on Valgrind-3.16.0.RC1 940ec1ca6 and same
results.

$ autogen.sh
$ configure
$ make install

OK. Now when I use the chroot from void linux musl and run the same program
this should be the correct output from valgrind. Note that I use their
void's package
here. But the same build from source does not bug either.

==918== Memcheck, a memory error detector
==918== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==918== Using Valgrind-3.16.1 and LibVEX; rerun with -h for copyright info
==918== Command: ./a.out
==918==
==918==
==918== HEAP SUMMARY:
==918==     in use at exit: 468 bytes in 4 blocks
==918==   total heap usage: 7 allocs, 3 frees, 1,031 bytes allocated
==918==
==918== LEAK SUMMARY:
==918==    definitely lost: 0 bytes in 0 blocks
==918==    indirectly lost: 0 bytes in 0 blocks
==918==      possibly lost: 0 bytes in 0 blocks
==918==    still reachable: 468 bytes in 4 blocks
==918==         suppressed: 0 bytes in 0 blocks
==918== Rerun with --leak-check=full to see details of leaked memory
==918==
==918== For lists of detected and suppressed errors, rerun with: -s
==918== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)


I don't know what to do anymore and what could be causing this weird
behavior from valgrind, it's like it fails to track the free/malloc/realloc
calls properly for some reason. I recall some time ago this was a non issue.


Also - valgrind is not an official kiss package right now, however it's very
important for developers like myself.

Here is some interesting output I get from just running kiss's autoconf:

configure.ac:117: warning: The macro `AC_PROG_CC_C99' is obsolete.
configure.ac:117: You should run autoupdate.
./lib/autoconf/c.m4:1659: AC_PROG_CC_C99 is expanded from...
configure.ac:117: the top level
configure.ac:4020: warning: The macro `AC_HEADER_STDC' is obsolete.
configure.ac:4020: You should run autoupdate.
./lib/autoconf/headers.m4:704: AC_HEADER_STDC is expanded from...
configure.ac:4020: the top level
configure.ac:4066: warning: The macro `AC_HEADER_TIME' is obsolete.
configure.ac:4066: You should run autoupdate.
./lib/autoconf/headers.m4:743: AC_HEADER_TIME is expanded from...
configure.ac:4066: the top level

But on void this output is not existent.

I suspect that this can screw with the build process for valgrind. Or kiss
musl version is somehow broken.

Re: autoconf and valgrind goes crazy

From: Nihal Jere
Cc: dev
Hi,

If you take a look at the musl package, there are some lines in the
build file that say to uncomment if using something like valgrind.
Have you tried doing this?

Nihal