From 7bdb7270cf3e3273937affb0ff55f2dd3a7b2070 Mon Sep 17 00:00:00 2001 From: winlin Date: Sat, 31 Dec 2022 19:27:21 +0800 Subject: [PATCH] Asan: Refine asan warning message for macOS. --- trunk/auto/auto_headers.sh | 5 +++++ trunk/configure | 2 ++ trunk/src/main/srs_main_server.cpp | 7 +++++++ 3 files changed, 14 insertions(+) diff --git a/trunk/auto/auto_headers.sh b/trunk/auto/auto_headers.sh index 7f6365d61..95c9d1f92 100755 --- a/trunk/auto/auto_headers.sh +++ b/trunk/auto/auto_headers.sh @@ -149,6 +149,11 @@ if [[ $SRS_GPERF_CP == YES ]]; then else srs_undefine_macro "SRS_GPERF_CP" $SRS_AUTO_HEADERS_H fi +if [ $SRS_SANITIZER == YES ]; then + srs_define_macro "SRS_SANITIZER" $SRS_AUTO_HEADERS_H +else + srs_undefine_macro "SRS_SANITIZER" $SRS_AUTO_HEADERS_H +fi if [ $SRS_SANITIZER_LOG == YES ]; then srs_define_macro "SRS_SANITIZER_LOG" $SRS_AUTO_HEADERS_H else diff --git a/trunk/configure b/trunk/configure index 961d1fd9a..dc934ac35 100755 --- a/trunk/configure +++ b/trunk/configure @@ -586,6 +586,7 @@ ffmpeg: END +# Generate Makefile entry for srs-server. cat << END >> ${SRS_MAKEFILE} server: _prepare_dir @echo "Build the SRS server, JOBS=\${JOBS}, FORCE_MAKE_JOBS=${SRS_FORCE_MAKE_JOBS}" @@ -593,6 +594,7 @@ server: _prepare_dir @bash objs/_srs_build_summary.sh END + # generate all modules entry for SRS_MODULE in ${SRS_MODULES[*]}; do . $SRS_WORKDIR/auto/reset_module.sh && . $SRS_MODULE/config diff --git a/trunk/src/main/srs_main_server.cpp b/trunk/src/main/srs_main_server.cpp index fe1061e72..e42093fe3 100644 --- a/trunk/src/main/srs_main_server.cpp +++ b/trunk/src/main/srs_main_server.cpp @@ -96,6 +96,13 @@ srs_error_t do_main(int argc, char** argv, char** envp) // TODO: Might fail if change working directory. _srs_binary = argv[0]; + // For sanitizer on macOS, to avoid the warning on startup. +#if defined(SRS_OSX) && defined(SRS_SANITIZER) + if (!getenv("MallocNanoZone")) { + fprintf(stderr, "Asan: Please setup the env MallocNanoZone=0 to disable the warning, see https://stackoverflow.com/a/70209891/17679565\n"); + } +#endif + // Initialize global and thread-local variables. if ((err = srs_global_initialize()) != srs_success) { return srs_error_wrap(err, "global init");