I managed to get this working. Documenting here in case anyone else encounters this problem.
The issue with undefined references to _NSConcreteStackBlock are due to the following block in ./configure around line 8973:
if test "`echo 'int main(){return ^{return 42;}();}' | ${CC} -o /dev/null -fblocks -x c - 2>&1`" = ""; then
AST_CLANG_BLOCKS_LIBS=""
AST_CLANG_BLOCKS="-Wno-unknown-warning-option -fblocks"
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
elif test "`echo 'int main(){return ^{return 42;}();}' | ${CC} -o /dev/null -fblocks -x c -lBlocksRuntime - 2>&1`" = ""; then
AST_CLANG_BLOCKS_LIBS="-lBlocksRuntime"
AST_CLANG_BLOCKS="-fblocks"
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
else
as_fn_error $? "BlocksRuntime is required for clang, please install libblocksruntime" "$LINENO" 5
fi
The first if condition tests compilation with -fblocks, and with regular clang that will fail if -lBlocksRuntime isn't specified. The elif condition will pass, and therefore AST_CLANG_BLOCKS_LIBS and AST_CLANG_BLOCKS will be set correctly for clang. For some reason with afl-clang/afl-clang-fast/afl-clang-lto the first condition passes, leading to the failures at linking. Forcing the values AST_CLANG_BLOCKS_LIBS="-lBlocksRuntime" and AST_CLANG_BLOCKS="-fblocks" resolves this issue.
The above fixes afl-clang, but builds with afl-clang-fast/lto still fail due to a secondary issue. At final linking for asterisk the following error is thrown:
/usr/bin/ld: asterisk: local symbol `__sanitizer_cov_trace_pc_guard_init' in /AFLplusplus/afl-compiler-rt.o is referenced by DSO
/usr/bin/ld: final link failed: bad value
clang: error: linker command failed with exit code 1 (use -v to see invocation)
This is due to the Makefile specifying a linker version-script which limits the globals for the main executable. This can be avoided by commenting out line 113 of main/Makefile: ASTLINK+=-Wl,--version-script,asterisk.exports
After these changes, builds with afl-clang-fast/lto succeed (and in my limited tests run fine too).
Cheers.