Skip to content

Commit

Permalink
configure now checks for -fsanitize=address, and omits it when not pr…
Browse files Browse the repository at this point in the history
…esent
  • Loading branch information
davidmcgrew committed Feb 10, 2022
1 parent e7ce4ff commit c4220d2
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 9 deletions.
5 changes: 5 additions & 0 deletions Makefile_helper.mk.in
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ COLOR_OFF = "\033[0m"
#
use_no_gnu_unique = @USE_NO_GNU_UNIQUE@

# The variable use_fsanitize controls the compiler option with the
# corresponding name, which is used when present in some build targets
#
use_fsanitize = @USE_FSANITIZE@

CXX = @CXX@
CC = @CC@
CFLAGS = --std=c++17
Expand Down
44 changes: 44 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,7 @@ PYTHON3
PY
LIBOBJS
HAVE_TPACKET_V3
USE_FSANITIZE
USE_NO_GNU_UNIQUE
ac_ct_CXX
CXXFLAGS
Expand Down Expand Up @@ -3931,6 +3932,43 @@ else
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether C compiler accepts -fsanitize=address" >&5
$as_echo_n "checking whether C compiler accepts -fsanitize=address... " >&6; }
if ${ax_cv_check_cflags__Werror__fsanitize_address+:} false; then :
$as_echo_n "(cached) " >&6
else
ax_check_save_flags=$CFLAGS
CFLAGS="$CFLAGS -Werror -fsanitize=address"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int
main ()
{
;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
ax_cv_check_cflags__Werror__fsanitize_address=yes
else
ax_cv_check_cflags__Werror__fsanitize_address=no
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
CFLAGS=$ax_check_save_flags
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ax_cv_check_cflags__Werror__fsanitize_address" >&5
$as_echo "$ax_cv_check_cflags__Werror__fsanitize_address" >&6; }
if test "x$ax_cv_check_cflags__Werror__fsanitize_address" = xyes; then :
USE_FSANITIZE=yes
else
USE_FSANITIZE=no
fi
for ac_header in linux/if_packet.h
do :
ac_fn_c_check_header_mongrel "$LINENO" "linux/if_packet.h" "ac_cv_header_linux_if_packet_h" "$ac_includes_default"
Expand Down Expand Up @@ -4906,6 +4944,12 @@ else
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: valgrind not found; test/Makefile memcheck test will not work" >&5
$as_echo "$as_me: WARNING: valgrind not found; test/Makefile memcheck test will not work" >&2;}
fi
if test "x$USE_FSANITIZE" = xyes; then :
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: -fsanitize not supported; debug targets will not use address sanitization" >&5
$as_echo "$as_me: WARNING: -fsanitize not supported; debug targets will not use address sanitization" >&2;}
fi
ac_config_files="$ac_config_files src/libmerc/Makefile src/Makefile test/Makefile unit_tests/Makefile resources/Makefile Makefile_helper.mk install_mercury/mercury.service"
cat >confcache <<\_ACEOF
Expand Down
4 changes: 4 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ AC_USE_SYSTEM_EXTENSIONS
#AC_PROG_CC
AC_PROG_CXX
AX_CHECK_COMPILE_FLAG([-fno-gnu-unique], [AC_SUBST([USE_NO_GNU_UNIQUE],yes)], [AC_SUBST([USE_NO_GNU_UNIQUE],no)] , [-Werror])
AX_CHECK_COMPILE_FLAG([-fsanitize=address], [AC_SUBST([USE_FSANITIZE],yes)], [AC_SUBST([USE_FSANITIZE],no)] , [-Werror])
AC_CHECK_HEADERS([linux/if_packet.h])
AC_CHECK_MEMBER([struct tpacket_req3.tp_block_size],[AC_SUBST(HAVE_TPACKET_V3,yes)],[AC_MSG_WARN([Linux AF_PACKET's TPACKET V3 is not available])],[[#include <linux/if_packet.h>]])
#AC_CHECK_MEMBER([struct tpacket_req3.tp_block_size],[],[AC_MSG_FAILURE([Linux AF_PACKET's TPACKET V3 is required, but not available])],[[#include <linux/if_packet.h>]])
Expand Down Expand Up @@ -73,5 +74,8 @@ AS_IF([test "x$WGET" = xyes],
AS_IF([test "x$VALGRIND" = xyes],
[],
[AC_MSG_WARN([valgrind not found; test/Makefile memcheck test will not work])])
AS_IF([test "x$USE_FSANITIZE" = xyes],
[],
[AC_MSG_WARN([-fsanitize not supported; debug targets will not use address sanitization])])
AC_CONFIG_FILES(src/libmerc/Makefile src/Makefile test/Makefile unit_tests/Makefile resources/Makefile Makefile_helper.mk install_mercury/mercury.service)
AC_OUTPUT
10 changes: 8 additions & 2 deletions src/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,11 @@ mercury: mercury.c $(MERC_OBJ) $(MERC_H) libmerc.a Makefile.in
$(CXX) $(CFLAGS) mercury.c $(MERC_OBJ) -pthread libmerc/libmerc.a -lz -lcrypto -o mercury
@echo $(COLOR_GREEN) "Build complete; now run 'sudo setcap" $(CAP) "mercury'" $(COLOR_OFF)

ifeq ($(use_fsanitize),yes)
FSANITIZE = -fsanitize=address -static-libasan
endif
debug-mercury: CFLAGS += -DDEBUG -g -O0
debug-mercury: CFLAGS += -fsanitize=address -static-libasan
debug-mercury: CFLAGS += $(FSANITIZE)
debug-mercury: debug-libmerc.a mercury

setcap: mercury
Expand Down Expand Up @@ -153,8 +156,11 @@ unstripped-libmerc:
stripped-libmerc:
$(MAKE) -j --directory=libmerc stripped-libmerc.so

ifeq ($(use_fsanitize),yes)
libmerc_util: CFLAGS += -fsanitize=address
endif
libmerc_util: libmerc_util.cc libmerc_api.h
$(CXX) $(CFLAGS) libmerc_util.cc pcap_file_io.c -fsanitize=address -pthread -ldl -std=c++17 -o libmerc_util
$(CXX) $(CFLAGS) libmerc_util.cc pcap_file_io.c -pthread -ldl -std=c++17 -o libmerc_util

intercept_server: intercept_server.cc
$(CXX) $(CFLAGS) intercept_server.cc -std=c++17 -o intercept_server
Expand Down
2 changes: 2 additions & 0 deletions src/libmerc/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ DBGFLAGS += -g
DBGFLAGS += -ggdb
DBGFLAGS += -O0
DBGFLAGS += -UNDEBUG
ifeq ($(use_fsanitize),yes)
DBGFLAGS += -fsanitize=address
endif
DBGFLAGS += -fno-omit-frame-pointer
DBGFLAGS += -fvisibility=default
# DBGFLAGS += -DDEBUG # this option triggers voluminous detailed output
Expand Down
18 changes: 11 additions & 7 deletions unit_tests/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

include ../Makefile_helper.mk

ifeq ($(use_fsanitize),yes)
FSANITIZE = -fsanitize=address
endif

export LD_LIBRARY_PATH =../src/libmerc

LIBMERC_FOLDER = ../src/libmerc/
Expand Down Expand Up @@ -42,14 +46,14 @@ libmerc_driver_tls_only: debug-libmerc-tls $(UNIT_TESTS_TLS_ONLY) Makefile.in $(
cp $(LIBMERC_SO) $(LIBMERC_SO).alt
cp $(LIBMERC_SO) $(LIBMERC_SO_tls)
mv $(LIBMERC_SO) $(LIBMERC_SO_tls).alt
$(CXX) $(CFLAGS) -I ../src/ -I../src/libmerc $(UNIT_TESTS_TLS_ONLY) -pthread -o libmerc_driver_tls_only -DLIBMERC_SO_PATH="\"$(LIBMERC_SO_tls)\"" -fsanitize=address -L$(LIBMERC_DEBUG_FOLDER) $(LIBMERC_SO_tls) -lcrypto -ldl -lz
$(CXX) $(CFLAGS) -I ../src/ -I../src/libmerc $(UNIT_TESTS_TLS_ONLY) -pthread -o libmerc_driver_tls_only -DLIBMERC_SO_PATH="\"$(LIBMERC_SO_tls)\"" $(FSANITIZE) -L$(LIBMERC_DEBUG_FOLDER) $(LIBMERC_SO_tls) -lcrypto -ldl -lz

libmerc_driver_multiprotocol: debug-libmerc $(UNIT_TESTS_TLS_HTTP_QUIC) Makefile.in $(UNIT_TESTS_H)
@echo "creating copy of libmerc.so for testing purposes"
cp $(LIBMERC_SO) $(LIBMERC_SO).alt
cp $(LIBMERC_SO) $(LIBMERC_SO_multiprotocol)
mv $(LIBMERC_SO) $(LIBMERC_SO_multiprotocol).alt
$(CXX) $(CFLAGS) -I ../src/ -I../src/libmerc $(UNIT_TESTS_TLS_HTTP_QUIC) -pthread -o libmerc_driver_multiprotocol -DLIBMERC_SO_PATH="\"$(LIBMERC_SO_multiprotocol)\"" -fsanitize=address -L$(LIBMERC_DEBUG_FOLDER) $(LIBMERC_SO_multiprotocol) -lcrypto -ldl -lz
$(CXX) $(CFLAGS) -I ../src/ -I../src/libmerc $(UNIT_TESTS_TLS_HTTP_QUIC) -pthread -o libmerc_driver_multiprotocol -DLIBMERC_SO_PATH="\"$(LIBMERC_SO_multiprotocol)\"" $(FSANITIZE) -L$(LIBMERC_DEBUG_FOLDER) $(LIBMERC_SO_multiprotocol) -lcrypto -ldl -lz


libmerc_driver_coverage: libmerc_driver_multiprotocol_coverage libmerc_driver_tls_coverage
Expand All @@ -59,17 +63,17 @@ libmerc_driver_tls_coverage: debug-libmerc_tls_gcov $(UNIT_TESTS_TLS_ONLY) Makef
cp $(LIBMERC_SO) $(LIBMERC_SO).alt
cp $(LIBMERC_SO) $(LIBMERC_SO_tls)
mv $(LIBMERC_SO) $(LIBMERC_SO_tls).alt
$(CXX) $(CFLAGS) -I ../src/ -I../src/libmerc $(UNIT_TESTS_TLS_ONLY) -pthread -o libmerc_driver_tls_only -DLIBMERC_SO_PATH="\"$(LIBMERC_SO_tls)\"" -fsanitize=address -L$(LIBMERC_DEBUG_FOLDER) $(LIBMERC_SO_tls) -lcrypto -ldl -lz --coverage
$(CXX) $(CFLAGS) -I ../src/ -I../src/libmerc $(UNIT_TESTS_TLS_ONLY) -pthread -o libmerc_driver_tls_only -DLIBMERC_SO_PATH="\"$(LIBMERC_SO_tls)\"" $(FSANITIZE) -L$(LIBMERC_DEBUG_FOLDER) $(LIBMERC_SO_tls) -lcrypto -ldl -lz --coverage

libmerc_driver_multiprotocol_coverage: debug-libmerc_gcov $(UNIT_TESTS_TLS_HTTP_QUIC) Makefile.in $(UNIT_TESTS_H)
@echo "creating copy of libmerc.so for testing purposes"
cp $(LIBMERC_SO) $(LIBMERC_SO).alt
cp $(LIBMERC_SO) $(LIBMERC_SO_multiprotocol)
mv $(LIBMERC_SO) $(LIBMERC_SO_multiprotocol).alt
$(CXX) $(CFLAGS) -I ../src/ -I../src/libmerc $(UNIT_TESTS_TLS_HTTP_QUIC) -pthread -o libmerc_driver_multiprotocol -DLIBMERC_SO_PATH="\"$(LIBMERC_SO_multiprotocol)\"" -fsanitize=address -L$(LIBMERC_DEBUG_FOLDER) $(LIBMERC_SO_multiprotocol) -lcrypto -ldl -lz --coverage
$(CXX) $(CFLAGS) -I ../src/ -I../src/libmerc $(UNIT_TESTS_TLS_HTTP_QUIC) -pthread -o libmerc_driver_multiprotocol -DLIBMERC_SO_PATH="\"$(LIBMERC_SO_multiprotocol)\"" $(FSANITIZE) -L$(LIBMERC_DEBUG_FOLDER) $(LIBMERC_SO_multiprotocol) -lcrypto -ldl -lz --coverage

pdu_verifier: debug-libmerc pdu_verifier.cc
$(CXX) $(CFLAGS) -I ../src/ -I ../src/libmerc pdu_verifier.cc ./../src/pcap_file_io.c -fsanitize=address -L./libmerc $(LIBMERC_SO) -lcrypto -ldl -lz -o pdu_verifier
$(CXX) $(CFLAGS) -I ../src/ -I ../src/libmerc pdu_verifier.cc ./../src/pcap_file_io.c $(FSANITIZE) -L./libmerc $(LIBMERC_SO) -lcrypto -ldl -lz -o pdu_verifier

.PHONY: debug-libmerc_tls_gcov
debug-libmerc_tls_gcov:
Expand Down

0 comments on commit c4220d2

Please sign in to comment.