waf: apply coverage flags after the configure checks have run

The coverage flags were added in configure_env, so every probe program
built by cfg.check() was compiled with -fprofile-arcs and linked with
-lgcov.  On boards which also link with -Wl,--wrap,malloc (SITL, Linux,
QURT) libgcov's malloc call is rewritten to __wrap_malloc, which the
probe does not define, so the probe fails to link and the feature under
test is silently recorded as absent.  Under --coverage every header
check ("endian.h", "byteswap.h", the cmath checks, memrchr) reported
"not found"; HAVE_BYTESWAP_H was never defined and the fallback in
AP_Common/missing/byteswap.h was compiled instead.  That fallback
collides with glibc's own __bswap_16/32/64 as soon as a translation
unit also includes netinet/in.h, which broke build.unit_tests in the
weekly coverage workflow.

Move the flags into Board.configure_coverage() and call it from the
top-level configure once the checks are done, so the probes are never
instrumented and the coverage configuration produces the same
ap_config.h as a normal one.

Co-authored-by: Pierre Kancir <pierre.kancir.emn@gmail.com>
This commit is contained in:
Peter Barker
2026-09-23 08:37:53 +10:00
committed by Peter Barker
co-authored by Pierre Kancir
parent e71227ca24
commit b3c52b2fcb
2 changed files with 19 additions and 17 deletions
+18 -17
View File
@@ -248,6 +248,24 @@ class Board:
return (int(major) < want_major or
(int(major) == want_major and int(minor) <= want_minor))
def configure_coverage(self, cfg):
"""Apply the coverage flags.
Called after the configure checks have run, rather than from
configure_env: cfg.check() links small probe programs, and
instrumenting those drags in libgcov, whose malloc call
-Wl,--wrap,malloc rewrites into an undefined __wrap_malloc. The
probe then fails to link and waf records the feature it was
probing for as missing.
"""
if not cfg.env.COVERAGE:
return
cfg.env.CFLAGS += ['-fprofile-arcs', '-ftest-coverage']
cfg.env.CXXFLAGS += ['-fprofile-arcs', '-ftest-coverage']
cfg.env.LINKFLAGS += ['-lgcov', '-coverage']
# cfg.env is post-merge, where DEFINES is a list of NAME=value
cfg.env.DEFINES += ['HAL_COVERAGE_BUILD=1']
def configure_env(self, cfg, env):
# Use a dictionary instead of the conventional list for definitions to
# make easy to override them. Convert back to list before consumption.
@@ -342,23 +360,6 @@ class Board:
env.CFLAGS += [
'-g',
]
if cfg.env.COVERAGE:
env.CFLAGS += [
'-fprofile-arcs',
'-ftest-coverage',
]
env.CXXFLAGS += [
'-fprofile-arcs',
'-ftest-coverage',
]
env.LINKFLAGS += [
'-lgcov',
'-coverage',
]
env.DEFINES.update(
HAL_COVERAGE_BUILD = 1,
)
if cfg.options.bootloader:
# don't let bootloaders try and pull scripting in
cfg.options.disable_scripting = True
+1
View File
@@ -628,6 +628,7 @@ def configure(cfg):
else:
cfg.end_msg('disabled', color='YELLOW')
cfg.get_board().configure_coverage(cfg)
cfg.start_msg('Coverage build')
if cfg.env.COVERAGE:
cfg.end_msg('enabled')