tinymux/tests/netaddr
Stephen Dennis ea11bae860 build(asan): tests/netaddr must honour the tree's sanitizer flags (#1522)
`make test-asan` could not get past its second leg.  tests/netaddr is the only
island that links an object built by the MAIN build --

    NETADDR_O = ../../mux/src/netmux-netaddr.o

-- and on a tree configured --enable-sanitizers that object is instrumented,
so it carries undefined sanitizer-runtime references while the island itself
compiles and links without -fsanitize.  The failure is in ld, before anything
runs, which is why the LD_PRELOAD from #1471 cannot help: that is a runtime
remedy for a link-time problem.

tests/format, tests/alarm and tests/dbt build every object themselves and link
libmux as a shared library, so they never see undefined sanitizer symbols.
That is why the leg ordering hid this -- test-format passes first and looks
like evidence the preload worked.

Fixed by reading the flags out of the tree's own config.status, which is the
same file test-asan already greps to decide whether the tree is instrumented
at all.  An ordinary tree yields an empty string and builds exactly as before;
a tree configured with a different sanitizer selection gets that selection.
Instrumenting the island is also the more useful answer, since the code under
test (mux_subnet::compare_to, parse_subnet) then runs instrumented, which is
the point of a sanitizer run.

## Verified before and after, on macOS arm64

Reproduced first, so the fix is not being credited for a green that was
already there.  The symptom differs by platform -- the report was
`__asan_stack_malloc_1` on aarch64/gcc, here it is the UBSan handlers:

    __ubsan_handle_type_mismatch_v1
    __ubsan_handle_sub_overflow
    __ubsan_handle_shift_out_of_bounds

Same class, same cause.

One thing worth recording so the next reader is not sent chasing it: the
macOS linker also prints `cf_log_syntax(...) in netmux-netaddr.o` 32 times in
that error, which reads like a second missing symbol.  It is not.  ld names
the *referencing* function under each undefined symbol, and cf_log_syntax is
defined in that very object (`nm` shows it as T).  Only the sanitizer handlers
are actually undefined.

With the fix, `make test-asan` runs to completion:

    format    31744 passed, 0 failed
    netaddr      61 passed, 0 failed     <- previously failed to link
    alarm         8 passed, 0 failed
    dbt        chain 48 / cache 14 / interp 593 / exec 960+2, all passed
    ganl         14 passed, 0 failed, 5 skipped
    jit-qreg, jit-ifelse, lua-ecall, scenario   all passed
    smoke (compiled route)  1509 passed, 315/315 dispatched
    smoke (AST route)       1509 passed, 315/315 dispatched

    rc=0, and ZERO sanitizer reports in the entire run.

(315 rather than 316 is ASAN_SMOKE_EXCLUDE dropping rvbench_fn, by design.)

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-27 05:54:15 -06:00
..
.gitignore tests: add netaddr subnet-comparator unit harness (locks #799) 2026-06-10 19:19:10 -06:00
Makefile build(asan): tests/netaddr must honour the tree's sanitizer flags (#1522) 2026-07-27 05:54:15 -06:00
test_netaddr.cpp build(win32): build the tests/ harnesses with MSVC, and fix what that found (#1441) 2026-07-26 19:12:25 -06:00