The flags that meson adds to targets for coverage are (a) not passed to the compiler "behavioural" test methods such as links() or has_function(), and (b) are not (AFAIK) available in some other way to pass manually.
This makes it impossible to test for the availability of Gcov functions like __gcov_dump() before trying to compile in extra source files to use it.
#include <gcov.h>
int main(void) {
__gcov_dump();
return 0;
}
If I configure with:
meson setup build
...then in the output I see:
Checking if "gcov" : links: NO
Build targets in project: 0
...as expected. However, with:
meson setup -Db_coverage=true build
...I also see:
Checking if "gcov" : links: NO
Build targets in project: 0
If I remove the check, the target builds with this configuration without error.
For the latter case, looking in build/meson-logs/meson-log.txt, I see:
Command line: `cc /home/jason/Code/meson-cov-test/build/meson-private/tmp92d42xau/testfile.c -o /home/jason/Code/meson-cov-test/build/meson-private/tmp92d42xau/output.exe -D_FILE_OFFSET_BITS=64 -O0 -std=c11` -> 1
stderr:
/usr/bin/ld: /tmp/ccU80lfd.o: in function `main':
testfile.c:(.text+0x9): undefined reference to `__gcov_dump'
collect2: error: ld returned 1 exit status
Note that the command line only includes the flags -D_FILE_OFFSET_BITS=64 -O0 -std=c11. However, if a target were actually generated with that configuration, it would also have the --coverage flag (or whatever Meson deemed appropriate for the compiler).
Expected behavior
The flags used for c_compiler.links() should be the same as for other targets before c_args are added in ie. they should contain Meson's internally computed, compiler-tailored instrumentation flags.
This seems to affect both coverage and sanitizer flags in the same way: __asan_init() fails in the same way as __gcov_dump() if one specifies -Db_sanitize=address.
The flags that meson adds to targets for coverage are (a) not passed to the compiler "behavioural" test methods such as
links()
orhas_function()
, and (b) are not (AFAIK) available in some other way to pass manually.This makes it impossible to test for the availability of Gcov functions like
__gcov_dump()
before trying to compile in extra source files to use it.Example
meson.build
:main.c
:If I configure with:
...then in the output I see:
...as expected. However, with:
...I also see:
If I remove the check, the target builds with this configuration without error.
For the latter case, looking in
build/meson-logs/meson-log.txt
, I see:Note that the command line only includes the flags
-D_FILE_OFFSET_BITS=64 -O0 -std=c11
. However, if a target were actually generated with that configuration, it would also have the--coverage
flag (or whatever Meson deemed appropriate for the compiler).Expected behavior
The flags used for
c_compiler.links()
should be the same as for other targets beforec_args
are added in ie. they should contain Meson's internally computed, compiler-tailored instrumentation flags.System parameters