mercredi 9 octobre 2019

AdressSanitizer link error and autoconf configure script

If you get linking errors like the following when trying to use AddressSanitizer in an autoconf project:
spnego.c:(.text+0x3c): undefined reference to `__asan_option_detect_stack_use_after_return'
/bin/ld: spnego.c:(.text+0x49): undefined reference to `__asan_stack_malloc_1'
/bin/ld: spnego.c:(.text+0xfd): undefined reference to `__asan_report_load16'
/bin/ld: spnego.c:(.text+0x180): undefined reference to `__asan_report_load8'
/bin/ld: spnego.c:(.text+0x1ad): undefined reference to `__asan_report_load8'
/bin/ld: spnego.c:(.text+0x1ff): undefined reference to `__asan_report_load8'
/bin/ld: spnego.c:(.text+0x22e): undefined reference to `__asan_report_load8'


It's because the configure guesses something wrong. You can work around it by providing the answer via an env var like so:

CFLAGS='-fsanitize=address' \
LDFLAGS='-fsanitize=address' \
ac_cv_func_malloc_0_nonnull=yes \
./configure