These are chat archives for Snaipe/Criterion

10th
Aug 2016
Dominik
@kaidowei
Aug 10 2016 11:44

@Snaipe hi there, I ran into a problem using Mimick.

#include <stdlib.h>
#include <assert.h>
#include <mimick.h>

/* Define the blueprint of a mock identified by `malloc_proto`
   that returns a `void *` and takes a `size_t` parameter. */
mmk_mock_define (malloc_mock, void *, size_t);

int main(void) {
    /* Mock the malloc function in the current module using 
       the `malloc_mock` blueprint. */
    mmk_mock("malloc@self", malloc_mock);

    /* Tell the mock to return NULL and set errno to ENOMEM
       whatever the given parameter is. */
    void *result = NULL;
    mmk_when(malloc(mmk_any(size_t)),
            .then_return = &result,
            .then_errno = ENOMEM);

    assert(malloc(42) == result && errno == ENOMEM);

    mmk_reset(malloc);
}

Even the simple example program runs into problems. mimick: Could not find GOT entry for function malloc@self. Aborted (core dumped)

building test with: gcc -o test test.c -L../ -lmimick -I../../include -std=c99 -O0

do you have any idea?
ubuntu 14.04
Franklin Mathieu
@Snaipe
Aug 10 2016 11:47
would you mind sending the compiled ELF file of the sample? I'll see if I can corner the issue
also could you send me the output of gcc --version and /usr/lib/libc.so.6 --version?
Dominik
@kaidowei
Aug 10 2016 11:53
you got mail :)
Franklin Mathieu
@Snaipe
Aug 10 2016 11:53
Thanks!
Franklin Mathieu
@Snaipe
Aug 10 2016 12:11
@kaidowei got it, it's a dumb bug that got in while refactoring
the "self" target doesn't propagate in the core, so don't use "@self" for the time being
Franklin Mathieu
@Snaipe
Aug 10 2016 12:17
Fixed by e7195bd
Dominik
@kaidowei
Aug 10 2016 12:18
so just malloc, not malloc@self will work?
Franklin Mathieu
@Snaipe
Aug 10 2016 12:18
yeah
although now that it's fixed, both work
it was just a refactoring mistake that broke the "self" selector API
Dominik
@kaidowei
Aug 10 2016 13:01
okay
thank you :)
so self works only for the c file I'm calling the mmk_mock in?
Franklin Mathieu
@Snaipe
Aug 10 2016 13:02
it works for the current shared object
so library/executable
Dominik
@kaidowei
Aug 10 2016 13:03
perfect, thanks
btw. can you add an install target to the cmake script?
Franklin Mathieu
@Snaipe
Aug 10 2016 13:04
sure
Franklin Mathieu
@Snaipe
Aug 10 2016 15:01
done in 435f41d