swtv-kaist / cs458-spring24

7 stars 0 forks source link

[HW4] Including headers in `.i` files does not seem to work..? #28

Closed hotmandu closed 5 months ago

hotmandu commented 5 months ago

To make sure some header are included, I wrote #include directives at the beginning of the output -cov.c files. (Following from this discussion) However, when I try to compile it, gcc refuses because of conflictions by duplicate declarations. Below is the part of the compilation log.

In file included from /usr/include/x86_64-linux-gnu/bits/pthreadtypes.h:23,
                 from /usr/include/x86_64-linux-gnu/sys/types.h:227,
                 from /usr/include/stdlib.h:395,
                 from ../grep/grep.c:48:
/usr/include/x86_64-linux-gnu/bits/thread-shared-types.h:94:8: error: redefinition of ‘struct __pthread_cond_s’
   94 | struct __pthread_cond_s
      |        ^~~~~~~~~~~~~~~~
In file included from /usr/include/x86_64-linux-gnu/bits/pthreadtypes.h:23,
                 from /usr/include/x86_64-linux-gnu/sys/types.h:227,
                 from /usr/include/stdlib.h:395,
                 from /usr/include/errno.h:38,
                 from ../grep/grep.c:35:
/usr/include/x86_64-linux-gnu/bits/thread-shared-types.h:94:8: note: originally defined here
   94 | struct __pthread_cond_s
      |        ^~~~~~~~~~~~~~~~

The solution provided does not works... Could you give a hint on this?

leejy12 commented 5 months ago

I solved the issue by checking if adding #include directives to original source file is necessary.

For example, try to look for differences between *.i files that does or does not include <stdio.h>.

hotmandu commented 5 months ago

Thanks! I've solved the issue by manually checking. But I still wonder if there exists simpler way to do this..

3-24 commented 5 months ago

There is no simple way to deal with this problem in general. One way is to copy the library code, rename the variables with common prefixes(such as __kcov_), and let kcov to instrument it. However, it's still complicated.