Index: Makefile.inc1 =================================================================== --- Makefile.inc1 +++ Makefile.inc1 @@ -1643,6 +1643,11 @@ .if ${MK_USB} != "no" _usb_tools= sys/boot/usb/tools .endif +.if ${MK_ASAN} != "no" +_asan_libs= lib/libclang_rt/asan-preinit \ + lib/libclang_rt/asan \ + lib/libclang_rt/asan_cxx +.endif cross-tools: .MAKE .PHONY .for _tool in \ @@ -1654,7 +1659,8 @@ ${_cc} \ ${_btxld} \ ${_crunchide} \ - ${_usb_tools} + ${_usb_tools} \ + ${_asan_libs} ${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all,install)"; \ cd ${.CURDIR}/${_tool}; \ ${MAKE} DIRPRFX=${_tool}/ obj; \ Index: contrib/bmake/make.h =================================================================== --- contrib/bmake/make.h +++ contrib/bmake/make.h @@ -435,7 +435,7 @@ * We cannot vfork() in a child of vfork(). * Most systems do not enforce this but some do. */ -#define vFork() ((getpid() == myPid) ? vfork() : fork()) +#define vFork() fork() extern pid_t myPid; #define MAKEFLAGS ".MAKEFLAGS" Index: contrib/compiler-rt/lib/asan/asan_linux.cc =================================================================== --- contrib/compiler-rt/lib/asan/asan_linux.cc +++ contrib/compiler-rt/lib/asan/asan_linux.cc @@ -94,6 +94,12 @@ if (!info->dlpi_name || info->dlpi_name[0] == 0) return 0; + // The dl_iterate_phdr from FreeBSD iterates over all ELF objects, + // not only the shared objects. So we skip everything else which has + // not a PT_LOAD type. + if (info->dlpi_phdr->p_type != PT_LOAD) + return 0; + // Ignore vDSO if (internal_strncmp(info->dlpi_name, "linux-", sizeof("linux-") - 1) == 0) return 0; Index: contrib/llvm/utils/TableGen/TableGen.cpp =================================================================== --- contrib/llvm/utils/TableGen/TableGen.cpp +++ contrib/llvm/utils/TableGen/TableGen.cpp @@ -181,7 +181,7 @@ #ifdef __has_feature #if __has_feature(address_sanitizer) -#include +//#include // Disable LeakSanitizer for this binary as it has too many leaks that are not // very interesting to fix. See compiler-rt/include/sanitizer/lsan_interface.h . int __lsan_is_turned_off() { return 1; } Index: contrib/mdocml/mdoc_macro.c =================================================================== --- contrib/mdocml/mdoc_macro.c +++ contrib/mdocml/mdoc_macro.c @@ -31,6 +31,14 @@ #include "libmdoc.h" #include "libmandoc.h" +#define CHECK_TOK \ + do { \ + if (tok >= MDOC_MAX) { \ + fprintf(stderr, "DIMDBG %s(%d) %s: tok=%d, MDOC_MAX=%d\n", \ + __FILE__, __LINE__, __func__, tok, MDOC_MAX); \ + } \ + } while (0) + static void blk_full(MACRO_PROT_ARGS); static void blk_exp_close(MACRO_PROT_ARGS); static void blk_part_exp(MACRO_PROT_ARGS); @@ -454,6 +462,7 @@ char *p; enum mdoct ntok; + CHECK_TOK; p = buf + ppos; ntok = MDOC_MAX; if (*p == '"') @@ -1061,6 +1070,7 @@ continue; } + CHECK_TOK; if (macro_or_word(mdoc, tok, line, la, pos, buf, parsed)) break; } @@ -1152,6 +1162,7 @@ if (body == NULL) body = mdoc_body_alloc(mdoc, line, ppos, tok); + CHECK_TOK; if (macro_or_word(mdoc, tok, line, la, pos, buf, 1)) break; } @@ -1243,6 +1254,7 @@ continue; } + CHECK_TOK; if (macro_or_word(mdoc, tok, line, la, pos, buf, 1)) break; } @@ -1417,6 +1429,7 @@ la = *pos; if (mdoc_args(mdoc, line, pos, buf, tok, NULL) == ARGS_EOLN) return(0); + CHECK_TOK; if (macro_or_word(mdoc, tok, line, la, pos, buf, 1)) return(1); } Index: gnu/usr.bin/diff/Makefile =================================================================== --- gnu/usr.bin/diff/Makefile +++ gnu/usr.bin/diff/Makefile @@ -11,7 +11,7 @@ PROG= diff SRCS= analyze.c context.c diff.c dir.c ed.c ifdef.c io.c \ normal.c side.c util.c \ - xmalloc.c strtoumax.c cmpbuf.c exitfail.c error.c quotesys.c \ + xmalloc.c cmpbuf.c exitfail.c error.c quotesys.c \ strftime.c c-stack.c basename.c exclude.c hard-locale.c \ file-type.c posixver.c prepargs.c version-etc.c Index: gnu/usr.bin/sdiff/Makefile =================================================================== --- gnu/usr.bin/sdiff/Makefile +++ gnu/usr.bin/sdiff/Makefile @@ -7,7 +7,7 @@ PROG= sdiff SRCS= sdiff.c version-etc.c \ - error.c xmalloc.c c-stack.c basename.c strtoumax.c \ + error.c xmalloc.c c-stack.c basename.c \ exitfail.c # Important for ctype macros! Index: kerberos5/lib/libasn1/Makefile =================================================================== --- kerberos5/lib/libasn1/Makefile +++ kerberos5/lib/libasn1/Makefile @@ -1,7 +1,7 @@ # $FreeBSD$ LIB= asn1 -LDFLAGS= -Wl,--no-undefined +LDFLAGS= ${LD_NO_UNDEF} INCS= asn1_err.h asn1-common.h heim_asn1.h der.h der-protos.h der-private.h LIBADD= com_err roken VERSION_MAP= ${.CURDIR}/version.map Index: kerberos5/lib/libgssapi_krb5/Makefile =================================================================== --- kerberos5/lib/libgssapi_krb5/Makefile +++ kerberos5/lib/libgssapi_krb5/Makefile @@ -1,7 +1,7 @@ # $FreeBSD$ LIB= gssapi_krb5 -LDFLAGS= -Wl,-Bsymbolic -Wl,--no-undefined +LDFLAGS= -Wl,-Bsymbolic ${LD_NO_UNDEF} LIBADD= gssapi krb5 crypto roken asn1 com_err SHLIB_MAJOR= 10 Index: kerberos5/lib/libgssapi_ntlm/Makefile =================================================================== --- kerberos5/lib/libgssapi_ntlm/Makefile +++ kerberos5/lib/libgssapi_ntlm/Makefile @@ -1,7 +1,7 @@ # $FreeBSD$ LIB= gssapi_ntlm -LDFLAGS= -Wl,-Bsymbolic -Wl,--no-undefined +LDFLAGS= -Wl,-Bsymbolic ${LD_NO_UNDEF} LIBADD= crypto gssapi krb5 heimntlm roken SHLIB_MAJOR= 10 Index: kerberos5/lib/libgssapi_spnego/Makefile =================================================================== --- kerberos5/lib/libgssapi_spnego/Makefile +++ kerberos5/lib/libgssapi_spnego/Makefile @@ -1,7 +1,7 @@ # $FreeBSD$ LIB= gssapi_spnego -LDFLAGS= -Wl,-Bsymbolic -Wl,--no-undefined +LDFLAGS= -Wl,-Bsymbolic ${LD_NO_UNDEF} LIBADD= gssapi heimbase asn1 roken SHLIB_MAJOR= 10 Index: kerberos5/lib/libhdb/Makefile =================================================================== --- kerberos5/lib/libhdb/Makefile +++ kerberos5/lib/libhdb/Makefile @@ -1,7 +1,7 @@ # $FreeBSD$ LIB= hdb -LDFLAGS= -Wl,--no-undefined ${LDAPLDFLAGS} +LDFLAGS= ${LD_NO_UNDEF} ${LDAPLDFLAGS} VERSION_MAP= ${KRB5DIR}/lib/hdb/version-script.map LIBADD= asn1 com_err krb5 roken sqlite3 LDADD= ${LDAPLDADD} Index: kerberos5/lib/libheimbase/Makefile =================================================================== --- kerberos5/lib/libheimbase/Makefile +++ kerberos5/lib/libheimbase/Makefile @@ -1,7 +1,7 @@ #$FreeBSD$ LIB= heimbase -LDFLAGS= -Wl,--no-undefined +LDFLAGS= ${LD_NO_UNDEF} LIBADD= pthread VERSION_MAP= ${KRB5DIR}/base/version-script.map Index: kerberos5/lib/libheimntlm/Makefile =================================================================== --- kerberos5/lib/libheimntlm/Makefile +++ kerberos5/lib/libheimntlm/Makefile @@ -1,7 +1,7 @@ # $FreeBSD$ LIB= heimntlm -LDFLAGS= -Wl,--no-undefined +LDFLAGS= ${LD_NO_UNDEF} LIBADD= crypto com_err krb5 roken SRCS= ntlm.c ntlm_err.c INCS= heimntlm.h heimntlm-protos.h ntlm_err.h Index: kerberos5/lib/libhx509/Makefile =================================================================== --- kerberos5/lib/libhx509/Makefile +++ kerberos5/lib/libhx509/Makefile @@ -1,7 +1,7 @@ # $FreeBSD$ LIB= hx509 -LDFLAGS= -Wl,--no-undefined +LDFLAGS= ${LD_NO_UNDEF} VERSION_MAP= ${KRB5DIR}/lib/hx509/version-script.map LIBADD= asn1 com_err crypto roken wind Index: kerberos5/lib/libkadm5clnt/Makefile =================================================================== --- kerberos5/lib/libkadm5clnt/Makefile +++ kerberos5/lib/libkadm5clnt/Makefile @@ -1,7 +1,7 @@ # $FreeBSD$ LIB= kadm5clnt -LDFLAGS= -Wl,--no-undefined +LDFLAGS= ${LD_NO_UNDEF} LIBADD= com_err krb5 roken INCS= admin.h \ Index: kerberos5/lib/libkadm5srv/Makefile =================================================================== --- kerberos5/lib/libkadm5srv/Makefile +++ kerberos5/lib/libkadm5srv/Makefile @@ -1,7 +1,7 @@ # $FreeBSD$ LIB= kadm5srv -LDFLAGS= -Wl,--no-undefined +LDFLAGS= ${LD_NO_UNDEF} LIBADD= com_err hdb krb5 roken VERSION_MAP= ${KRB5DIR}/lib/kadm5/version-script.map MAN= kadm5_pwcheck.3 Index: kerberos5/lib/libkafs5/Makefile =================================================================== --- kerberos5/lib/libkafs5/Makefile +++ kerberos5/lib/libkafs5/Makefile @@ -1,7 +1,7 @@ # $FreeBSD$ LIB= kafs5 -LDFLAGS= -Wl,--no-undefined +LDFLAGS= ${LD_NO_UNDEF} LIBADD= asn1 krb5 roken INCS= kafs.h MAN= kafs5.3 Index: kerberos5/lib/libkdc/Makefile =================================================================== --- kerberos5/lib/libkdc/Makefile +++ kerberos5/lib/libkdc/Makefile @@ -1,7 +1,7 @@ #$FreeBSD$ LIB= kdc -LDFLAGS= -Wl,--no-undefined +LDFLAGS= ${LD_NO_UNDEF} VERSION_MAP= ${KRB5DIR}/kdc/version-script.map LIBADD= roken hdb hx509 krb5 heimntlm asn1 crypto Index: kerberos5/lib/libkrb5/Makefile =================================================================== --- kerberos5/lib/libkrb5/Makefile +++ kerberos5/lib/libkrb5/Makefile @@ -1,7 +1,7 @@ # $FreeBSD$ LIB= krb5 -LDFLAGS= -Wl,--no-undefined +LDFLAGS= ${LD_NO_UNDEF} VERSION_MAP= ${KRB5DIR}/lib/krb5/version-script.map LIBADD= asn1 com_err crypt crypto hx509 roken wind heimbase heimipcc Index: kerberos5/lib/libwind/Makefile =================================================================== --- kerberos5/lib/libwind/Makefile +++ kerberos5/lib/libwind/Makefile @@ -1,7 +1,7 @@ #$FreeBSD$ LIB= wind -LDFLAGS= -Wl,--no-undefined +LDFLAGS= ${LD_NO_UNDEF} VERSION_MAP= ${KRB5DIR}/lib/wind/version-script.map LIBADD= com_err roken Index: lib/libc/Makefile =================================================================== --- lib/libc/Makefile +++ lib/libc/Makefile @@ -163,6 +163,8 @@ SUBDIR+= tests .endif +MK_ASAN= no + .include .if !defined(_SKIP_BUILD) Index: lib/libclang_rt/Makefile.inc =================================================================== --- lib/libclang_rt/Makefile.inc +++ lib/libclang_rt/Makefile.inc @@ -8,12 +8,12 @@ CLANGDIR=/usr/lib/clang/3.7.1 LIBDIR=${CLANGDIR}/lib/freebsd -NO_PIC= MK_PROFILE=no +MK_SSP=no +MK_ASAN=no WARNS?=0 -SSP_CFLAGS= CFLAGS+=-DNDEBUG CFLAGS+=${PICFLAG} CFLAGS+=-fno-builtin Index: lib/libclang_rt/asan-dynamic/Makefile =================================================================== --- lib/libclang_rt/asan-dynamic/Makefile +++ lib/libclang_rt/asan-dynamic/Makefile @@ -2,7 +2,7 @@ .include -LIB= clang_rt.asan-${CRTARCH} +SHLIB_NAME= libclang_rt.asan-${CRTARCH}.so .PATH: ${CRTSRC}/lib/asan\ ${CRTSRC}/lib/interception\ @@ -10,8 +10,7 @@ ${CRTSRC}/lib/lsan\ ${CRTSRC}/lib/ubsan -SRCS= asan_preinit.cc\ - asan_allocator.cc\ +SRCS= asan_allocator.cc\ asan_activation.cc\ asan_debugging.cc\ asan_fake_stack.cc\ @@ -32,6 +31,11 @@ asan_suppressions.cc\ asan_thread.cc\ asan_win.cc\ + asan_new_delete.cc\ + ubsan_handlers_cxx.cc\ + ubsan_type_hash.cc\ + ubsan_type_hash_itanium.cc\ + ubsan_type_hash_win.cc\ interception_linux.cc\ interception_mac.cc\ interception_win.cc\ @@ -85,4 +89,16 @@ ubsan_handlers.cc\ ubsan_value.cc +# Kludge around a bsd.lib.mk shortcoming: when SHLIB_NAME is defined, but LIB +# and LIB_CXX are undefined (which forces building only a shared library), +# there is no way to tell it to use ${CXX} for linking. Since the files for +# this library are all C++ anyway, simply set CC to CXX. +CC= ${CXX} + .include + +CXXFLAGS.ubsan_handlers_cxx.cc= -frtti +CXXFLAGS.ubsan_type_hash.cc= -frtti +CXXFLAGS.ubsan_type_hash_itanium.cc= -frtti +CXXFLAGS.ubsan_type_hash_win.cc= -frtti +CXXFLAGS+= ${CXXFLAGS.${.IMPSRC:T}} Index: lib/libclang_rt/asan-preinit/Makefile =================================================================== --- lib/libclang_rt/asan-preinit/Makefile +++ lib/libclang_rt/asan-preinit/Makefile @@ -2,7 +2,8 @@ .include -LIB= clang_rt.asan-preinit-${CRTARCH} +LIB_CXX=clang_rt.asan-preinit-${CRTARCH} +NO_PIC= .PATH: ${CRTSRC}/lib/asan Index: lib/libclang_rt/asan/Makefile =================================================================== --- lib/libclang_rt/asan/Makefile +++ lib/libclang_rt/asan/Makefile @@ -2,7 +2,8 @@ .include -LIB= clang_rt.asan-${CRTARCH} +LIB_CXX=clang_rt.asan-${CRTARCH} +NO_PIC= .PATH: ${CRTSRC}/lib/asan\ ${CRTSRC}/lib/interception\ Index: lib/libclang_rt/asan_cxx/Makefile =================================================================== --- lib/libclang_rt/asan_cxx/Makefile +++ lib/libclang_rt/asan_cxx/Makefile @@ -2,7 +2,8 @@ .include -LIB= clang_rt.asan_cxx-${CRTARCH} +LIB_CXX=clang_rt.asan_cxx-${CRTARCH} +NO_PIC= CXXFLAGS+=-frtti Index: lib/libclang_rt/profile/Makefile =================================================================== --- lib/libclang_rt/profile/Makefile +++ lib/libclang_rt/profile/Makefile @@ -3,6 +3,7 @@ .include LIB= clang_rt.profile-${CRTARCH} +NO_PIC= .PATH: ${CRTSRC}/lib/profile Index: lib/libclang_rt/safestack/Makefile =================================================================== --- lib/libclang_rt/safestack/Makefile +++ lib/libclang_rt/safestack/Makefile @@ -2,7 +2,8 @@ .include -LIB= clang_rt.safestack-${CRTARCH} +LIB_CXX=clang_rt.safestack-${CRTARCH} +NO_PIC= .PATH: ${CRTSRC}/lib/interception\ ${CRTSRC}/lib/sanitizer_common\ Index: lib/libclang_rt/ubsan_standalone/Makefile =================================================================== --- lib/libclang_rt/ubsan_standalone/Makefile +++ lib/libclang_rt/ubsan_standalone/Makefile @@ -2,7 +2,8 @@ .include -LIB= clang_rt.ubsan_standalone-${CRTARCH} +LIB_CXX=clang_rt.ubsan_standalone-${CRTARCH} +NO_PIC= .PATH: ${CRTSRC}/lib/sanitizer_common\ ${CRTSRC}/lib/ubsan Index: lib/libclang_rt/ubsan_standalone_cxx/Makefile =================================================================== --- lib/libclang_rt/ubsan_standalone_cxx/Makefile +++ lib/libclang_rt/ubsan_standalone_cxx/Makefile @@ -2,9 +2,8 @@ .include -LIB= clang_rt.ubsan_standalone_cxx-${CRTARCH} - -CXXFLAGS+=-frtti +LIB_CXX=clang_rt.ubsan_standalone_cxx-${CRTARCH} +NO_PIC= .PATH: ${CRTSRC}/lib/ubsan @@ -13,4 +12,6 @@ ubsan_type_hash_itanium.cc\ ubsan_type_hash_win.cc +CXXFLAGS+=-frtti + .include Index: lib/libcom_err/Makefile =================================================================== --- lib/libcom_err/Makefile +++ lib/libcom_err/Makefile @@ -7,7 +7,7 @@ COM_ERRDIR= ${.CURDIR}/../../contrib/com_err CFLAGS+= -I${COM_ERRDIR} -LDFLAGS= -Wl,--no-undefined +LDFLAGS= ${LD_NO_UNDEF} VERSION_MAP= ${COM_ERRDIR}/version-script.map .include Index: lib/libproc/tests/Makefile =================================================================== --- lib/libproc/tests/Makefile +++ lib/libproc/tests/Makefile @@ -6,7 +6,7 @@ SRCS_target_prog= target_prog.c BINDIR_target_prog= ${TESTSDIR} -LIBADD= elf proc rtld_db util +LIBADD= elf proc cxxrt rtld_db util # Ensure that symbols aren't stripped from the test program, as they're needed # for testing symbol lookup. Index: lib/ncurses/config.mk =================================================================== --- lib/ncurses/config.mk +++ lib/ncurses/config.mk @@ -4,6 +4,8 @@ NCURSES_DIR= ${.CURDIR}/../../../contrib/ncurses +MK_ASAN= no + .if defined(ENABLE_WIDEC) LIB_SUFFIX= w CFLAGS+= -D_XOPEN_SOURCE_EXTENDED -DENABLE_WIDEC Index: libexec/ftpd/Makefile =================================================================== --- libexec/ftpd/Makefile +++ libexec/ftpd/Makefile @@ -33,4 +33,8 @@ LIBADD+= pam .endif +.if ${MK_ASAN} != "no" +CFLAGS+=-Dgetline=get_line +.endif + .include Index: rescue/rescue/Makefile =================================================================== --- rescue/rescue/Makefile +++ rescue/rescue/Makefile @@ -5,6 +5,7 @@ MAN= MK_SSP= no +CRUNCHENV= MK_TESTS=no MK_SSP=no PROG= rescue BINDIR?=/rescue Index: share/mk/bsd.lib.mk =================================================================== --- share/mk/bsd.lib.mk +++ share/mk/bsd.lib.mk @@ -76,25 +76,25 @@ PO_FLAG=-pg .c.o: - ${CC} ${STATIC_CFLAGS} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET} + ${CC} ${STATIC_CFLAGS} ${CFLAGS:N-fsanitize=*} -DASAN_IS_DISABLED_FOR_NOW -c ${.IMPSRC} -o ${.TARGET} ${CTFCONVERT_CMD} .c.po: - ${CC} ${PO_FLAG} ${STATIC_CFLAGS} ${PO_CFLAGS} -c ${.IMPSRC} -o ${.TARGET} + ${CC} ${PO_FLAG} ${STATIC_CFLAGS} ${PO_CFLAGS:N-fsanitize=*} -DASAN_IS_DISABLED_FOR_NOW -c ${.IMPSRC} -o ${.TARGET} ${CTFCONVERT_CMD} .c.So: - ${CC} ${PICFLAG} -DPIC ${SHARED_CFLAGS} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET} + ${CC} ${PICFLAG} -DPIC ${SHARED_CFLAGS} ${CFLAGS:N-fsanitize=*} -DASAN_IS_DISABLED_FOR_NOW -c ${.IMPSRC} -o ${.TARGET} ${CTFCONVERT_CMD} .cc.o .C.o .cpp.o .cxx.o: - ${CXX} ${STATIC_CXXFLAGS} ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET} + ${CXX} ${STATIC_CXXFLAGS} ${CXXFLAGS:N-fsanitize=*} -DASAN_IS_DISABLED_FOR_NOW -c ${.IMPSRC} -o ${.TARGET} .cc.po .C.po .cpp.po .cxx.po: - ${CXX} ${PO_FLAG} ${STATIC_CXXFLAGS} ${PO_CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET} + ${CXX} ${PO_FLAG} ${STATIC_CXXFLAGS} ${PO_CXXFLAGS:N-fsanitize=*} -DASAN_IS_DISABLED_FOR_NOW -c ${.IMPSRC} -o ${.TARGET} .cc.So .C.So .cpp.So .cxx.So: - ${CXX} ${PICFLAG} -DPIC ${SHARED_CXXFLAGS} ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET} + ${CXX} ${PICFLAG} -DPIC ${SHARED_CXXFLAGS} ${CXXFLAGS:N-fsanitize=*} -DASAN_IS_DISABLED_FOR_NOW -c ${.IMPSRC} -o ${.TARGET} .f.po: ${FC} -pg ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC} @@ -109,23 +109,23 @@ ${CTFCONVERT_CMD} .asm.po: - ${CC:N${CCACHE_BIN}} -x assembler-with-cpp -DPROF ${PO_CFLAGS} \ - ${ACFLAGS} -c ${.IMPSRC} -o ${.TARGET} + ${CC:N${CCACHE_BIN}} -x assembler-with-cpp -DPROF ${PO_CFLAGS:N-fsanitize=*} ${ACFLAGS:N-fsanitize=*} -DASAN_IS_DISABLED_FOR_NOW -c ${.IMPSRC} -o ${.TARGET} ${CTFCONVERT_CMD} .asm.So: - ${CC:N${CCACHE_BIN}} -x assembler-with-cpp ${PICFLAG} -DPIC \ - ${CFLAGS} ${ACFLAGS} -c ${.IMPSRC} -o ${.TARGET} + ${CC:N${CCACHE_BIN}} -x assembler-with-cpp ${PICFLAG} -DPIC ${CFLAGS:N-fsanitize=*} ${ACFLAGS:N-fsanitize=*} -DASAN_IS_DISABLED_FOR_NOW -c ${.IMPSRC} -o ${.TARGET} + ${CTFCONVERT_CMD} + +.S.o: + ${CC:N${CCACHE_BIN}} ${CFLAGS:N-fsanitize=*} ${ACFLAGS:N-fsanitize=*} -DASAN_IS_DISABLED_FOR_NOW -c ${.IMPSRC} -o ${.TARGET} ${CTFCONVERT_CMD} .S.po: - ${CC:N${CCACHE_BIN}} -DPROF ${PO_CFLAGS} ${ACFLAGS} -c ${.IMPSRC} \ - -o ${.TARGET} + ${CC:N${CCACHE_BIN}} -DPROF ${PO_CFLAGS:N-fsanitize=*} ${ACFLAGS:N-fsanitize=*} -DASAN_IS_DISABLED_FOR_NOW -c ${.IMPSRC} -o ${.TARGET} ${CTFCONVERT_CMD} .S.So: - ${CC:N${CCACHE_BIN}} ${PICFLAG} -DPIC ${CFLAGS} ${ACFLAGS} \ - -c ${.IMPSRC} -o ${.TARGET} + ${CC:N${CCACHE_BIN}} ${PICFLAG} -DPIC ${CFLAGS:N-fsanitize=*} ${ACFLAGS:N-fsanitize=*} -DASAN_IS_DISABLED_FOR_NOW -c ${.IMPSRC} -o ${.TARGET} ${CTFCONVERT_CMD} .if !defined(_SKIP_BUILD) Index: share/mk/bsd.sys.mk =================================================================== --- share/mk/bsd.sys.mk +++ share/mk/bsd.sys.mk @@ -164,6 +164,17 @@ CFLAGS+= ${SSP_CFLAGS} .endif # SSP && !ARM && !MIPS +.if ${MK_ASAN} != "no" && ${MK_SSP} != "no" && ${SSP_CFLAGS} != "" && \ + (!defined(NO_SHARED) || ${NO_SHARED} == "no" || ${NO_SHARED} == "NO") +ASANFLAGS?= -fsanitize=address +CFLAGS+= ${ASANFLAGS} +CXXFLAGS+= ${ASANFLAGS} +LDFLAGS+= ${ASANFLAGS} +LD_NO_UNDEF= +.else +LD_NO_UNDEF= -Wl,--no-undefined +.endif + # Allow user-specified additional warning flags, plus compiler specific flag overrides. # Unless we've overriden this... .if ${MK_WARNS} != "no" Index: share/mk/src.libnames.mk =================================================================== --- share/mk/src.libnames.mk +++ share/mk/src.libnames.mk @@ -282,7 +282,7 @@ _DP_ucl= m _DP_vmmapi= util _DP_ctf= z -_DP_dtrace= ctf elf proc pthread rtld_db +_DP_dtrace= ctf elf proc cxxrt pthread rtld_db _DP_xo= util # The libc dependencies are not strictly needed but are defined to make the # assert happy. Index: share/mk/src.opts.mk =================================================================== --- share/mk/src.opts.mk +++ share/mk/src.opts.mk @@ -175,6 +175,7 @@ ZONEINFO __DEFAULT_NO_OPTIONS = \ + ASAN \ BSD_GREP \ CLANG_EXTRAS \ DTRACE_TESTS \ Index: share/mk/sys.mk =================================================================== --- share/mk/sys.mk +++ share/mk/sys.mk @@ -172,8 +172,8 @@ LFLAGS ?= LD ?= ld -LDFLAGS ?= # LDFLAGS is for CC, -_LDFLAGS = ${LDFLAGS:S/-Wl,//g} # strip -Wl, for LD +LDFLAGS ?= # LDFLAGS is for CC, +_LDFLAGS = ${LDFLAGS:N-fsanitize=*:S/-Wl,//g} # strip -Wl, for LD LINT ?= lint LINTFLAGS ?= -cghapbx Index: usr.bin/ctags/Makefile =================================================================== --- usr.bin/ctags/Makefile +++ usr.bin/ctags/Makefile @@ -1,8 +1,14 @@ # @(#)Makefile 8.1 (Berkeley) 6/6/93 # $FreeBSD$ +.include + PROG= ctags SRCS= C.c ctags.c fortran.c lisp.c print.c tree.c yacc.c CFLAGS+=-I${.CURDIR} +.if ${MK_ASAN} != "no" +CFLAGS+=-Dgetline=get_line +.endif + .include Index: usr.bin/tar/tests/Makefile =================================================================== --- usr.bin/tar/tests/Makefile +++ usr.bin/tar/tests/Makefile @@ -5,9 +5,9 @@ ATF_TESTS_SH+= functional_test BINDIR= ${TESTSDIR} +NO_SHARED= CFLAGS+= -DPLATFORM_CONFIG_H=\"${SRCTOP}/lib/libarchive/config_freebsd.h\" -CFLAGS+= -static CFLAGS+= -I${SRCTOP}/lib/libarchive -I${.OBJDIR} CFLAGS+= -I${_LIBARCHIVEDIR}/tar -I${_LIBARCHIVEDIR}/test_utils Index: usr.sbin/ftp-proxy/Makefile =================================================================== --- usr.sbin/ftp-proxy/Makefile +++ usr.sbin/ftp-proxy/Makefile @@ -1,5 +1,7 @@ # $FreeBSD$ +.include + .PATH: ${.CURDIR}/../../contrib/pf/ftp-proxy PROG= ftp-proxy @@ -9,6 +11,10 @@ CFLAGS+=-I${.CURDIR}/../../contrib/pf/libevent +.if ${MK_ASAN} != "no" +CFLAGS+=-Dgetline=get_line +.endif + LIBADD= event WARNS?= 3 Index: usr.sbin/lpr/Makefile.inc =================================================================== --- usr.sbin/lpr/Makefile.inc +++ usr.sbin/lpr/Makefile.inc @@ -6,4 +6,8 @@ CFLAGS+= -DINET6 .endif +.if ${MK_ASAN} != "no" +CFLAGS+=-Dgetline=get_line +.endif + .include "../Makefile.inc" Index: usr.sbin/rpc.lockd/lockd_lock.c =================================================================== --- usr.sbin/rpc.lockd/lockd_lock.c +++ usr.sbin/rpc.lockd/lockd_lock.c @@ -215,7 +215,6 @@ enum nlm_stats do_unlock(struct file_lock *fl); enum nlm_stats do_lock(struct file_lock *fl); void do_clear(const char *hostname); -size_t strnlen(const char *, size_t); void debuglog(char const *fmt, ...) @@ -371,17 +370,6 @@ dest->l_len = src->l_len; } - -size_t -strnlen(const char *s, size_t len) -{ - size_t n; - - for (n = 0; s[n] != 0 && n < len; n++) - ; - return n; -} - /* * allocate_file_lock: Create a lock with the given parameters */