Refactore the compiler/linker options to add asan only on executables
This commit is contained in:
parent
8ed4cc43a9
commit
b8483a1601
|
@ -110,7 +110,6 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
|
|||
|
||||
$<$<CONFIG:DEBUG>:-fno-omit-frame-pointer>
|
||||
$<$<CONFIG:RELEASE>:-fomit-frame-pointer>
|
||||
$<$<CONFIG:DEBUG>:-fsanitize=address>
|
||||
|
||||
$<$<CONFIG:RELEASE>:-O3>
|
||||
$<$<CONFIG:RELEASE>:-fmerge-all-constants>
|
||||
|
@ -120,8 +119,6 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
|
|||
# We enforce the lld linker
|
||||
-fuse-ld=lld
|
||||
-Wl,-gc-sections
|
||||
$<$<CONFIG:RELEASE>:-fsanitize-address-globals-dead-stripping>
|
||||
$<$<CONFIG:DEBUG>:-fsanitize=address>
|
||||
$<$<CONFIG:RELEASE>:-s>
|
||||
# Do not link against shared libraries
|
||||
#--static
|
||||
|
|
21
builder
21
builder
|
@ -156,8 +156,8 @@ function build-tidy() { ## Builds the project using clang-tidy (It takes longer
|
|||
function build-release() { ## Builds the project in "Release" mode
|
||||
clean
|
||||
pushed_build
|
||||
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release "$ROOT_DIR"
|
||||
cmake --build .
|
||||
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release "${CMAKEARGS[@]}" "$ROOT_DIR"
|
||||
cmake --build . --config Release
|
||||
popd_build
|
||||
}
|
||||
|
||||
|
@ -180,18 +180,15 @@ function clean() { ## Cleans up the source dir and removes the build
|
|||
}
|
||||
|
||||
function run() { ## Runs `serenec` and passes all the given aruguments to it
|
||||
LD_PRELOAD=$(clang -print-file-name=libclang_rt.asan-x86_64.so) \
|
||||
"$BUILD_DIR"/serenec/serenec "$@"
|
||||
"$BUILD_DIR"/serenec/serenec "$@"
|
||||
}
|
||||
|
||||
function lldb-run() { ## Runs `serenec` under lldb
|
||||
LD_PRELOAD=$(clang -print-file-name=libclang_rt.asan-x86_64.so) \
|
||||
lldb -- "$BUILD_DIR"/serenec/serenec "$@"
|
||||
lldb -- "$BUILD_DIR"/serenec/serenec "$@"
|
||||
}
|
||||
|
||||
function repl() { ## Runs `serene-repl` and passes all the given aruguments to it
|
||||
LD_PRELOAD=$(clang -print-file-name=libclang_rt.asan-x86_64.so) \
|
||||
"$BUILD_DIR"/serene-repl/serene-repl "$@"
|
||||
"$BUILD_DIR"/serene-repl/serene-repl "$@"
|
||||
}
|
||||
|
||||
function memcheck-serene() { ## Runs `valgrind` to check `serenec` birany
|
||||
|
@ -209,13 +206,11 @@ function tests() { ## Runs all the test cases
|
|||
local test_file="$BUILD_DIR/$proj/tests/${proj}Tests"
|
||||
|
||||
if [[ -f "$test_file" ]]; then
|
||||
LD_PRELOAD=$(clang -print-file-name=libclang_rt.asan-x86_64.so) \
|
||||
eval "$test_file ${*:2}"
|
||||
eval "$test_file ${*:2}"
|
||||
fi
|
||||
done
|
||||
else
|
||||
LD_PRELOAD=$(clang -print-file-name=libclang_rt.asan-x86_64.so) \
|
||||
eval "$BUILD_DIR/$1/tests/$1Tests ${*:2}"
|
||||
eval "$BUILD_DIR/$1/tests/$1Tests ${*:2}"
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -303,8 +298,6 @@ function setup() { ## Setup the working directory and make it ready for developm
|
|||
else
|
||||
error "Python is required to setup pre-commit"
|
||||
fi
|
||||
# rm -rfv "$ME/.git/hooks/pre-commit"
|
||||
# ln -s "$ME/scripts/pre-commit" "$ME/.git/hooks/pre-commit"
|
||||
}
|
||||
|
||||
function setup-dev() { ## Setup the container like env to build/develop Serene (requires sudo access)
|
||||
|
|
|
@ -23,7 +23,7 @@ if(NOT APPLE)
|
|||
endif()
|
||||
|
||||
set(SOURCES core.cpp)
|
||||
add_library(core STATIC
|
||||
add_library(core OBJECT
|
||||
${SOURCES})
|
||||
|
||||
#add_custom_target(serene.core)
|
||||
|
@ -41,14 +41,12 @@ set_target_properties(core PROPERTIES
|
|||
LINK_WHAT_YOU_USE TRUE
|
||||
CXX_INCLUDE_WHAT_YOU_USE "${iwyu_path}"
|
||||
C_INCLUDE_WHAT_YOU_USE "${iwyu_path}"
|
||||
# LTO support
|
||||
# LTO support we need the actual object file
|
||||
# LTO will export them to llvm IR
|
||||
INTERPROCEDURAL_OPTIMIZATION FALSE)
|
||||
|
||||
target_compile_options(core PUBLIC -fsanitize=address -static-libsan --static)
|
||||
target_link_options(core PUBLIC -fsanitize=address -static-libsan --static)
|
||||
|
||||
get_target_property(MFLAGS core COMPILE_OPTIONS)
|
||||
message(STATUS "------ ${MFLAGS}")
|
||||
target_compile_options(core PRIVATE --static)
|
||||
target_link_options(core PRIVATE --static)
|
||||
|
||||
if(SERENE_ENABLE_TIDY)
|
||||
set_target_properties(core PROPERTIES CXX_CLANG_TIDY ${CLANG_TIDY_PATH})
|
||||
|
|
|
@ -47,35 +47,15 @@ set_target_properties(serene PROPERTIES
|
|||
INTERPROCEDURAL_OPTIMIZATION TRUE)
|
||||
|
||||
target_compile_options(serene
|
||||
PRIVATE
|
||||
$<$<CONFIG:DEBUG>:-static-libsan>)
|
||||
PRIVATE)
|
||||
|
||||
target_link_options(serene
|
||||
PRIVATE
|
||||
$<$<CONFIG:DEBUG>:-shared-libsan>)
|
||||
|
||||
PRIVATE)
|
||||
|
||||
if(SERENE_ENABLE_TIDY)
|
||||
set_target_properties(serene PROPERTIES CXX_CLANG_TIDY ${CLANG_TIDY_PATH})
|
||||
endif()
|
||||
|
||||
# Do we need to build serene as a shared lib? default is "yes"
|
||||
if(SERENE_SHARED_LIB)
|
||||
|
||||
# We need to use libsan as a shared lib on debug mode. The
|
||||
# target executable has to be built with `-fsanitize=address`
|
||||
# as well and it has to run with:
|
||||
# LD_PRELOAD=$(clang -print-file-name=libclang_rt.asan-x86_64.so)
|
||||
target_compile_options(serene PRIVATE
|
||||
$<$<CONFIG:DEBUG>:-shared-libsan>
|
||||
)
|
||||
target_link_options(
|
||||
serene PRIVATE
|
||||
$<$<CONFIG:DEBUG>:-shared-libsan>
|
||||
)
|
||||
endif()
|
||||
|
||||
|
||||
if (CPP_20_SUPPORT)
|
||||
target_compile_features(serene PUBLIC cxx_std_20)
|
||||
else()
|
||||
|
|
|
@ -42,6 +42,18 @@ target_link_libraries(serene-repl
|
|||
Serene::lib
|
||||
)
|
||||
|
||||
target_compile_options(serene-repl
|
||||
PRIVATE
|
||||
$<$<CONFIG:DEBUG>:-fsanitize=address>
|
||||
$<$<CONFIG:DEBUG>:-static-libsan>
|
||||
)
|
||||
|
||||
target_link_options(serene-repl
|
||||
PRIVATE
|
||||
$<$<CONFIG:DEBUG>:-fsanitize=address>
|
||||
$<$<CONFIG:DEBUG>:-static-libsan>
|
||||
)
|
||||
|
||||
target_include_directories(serene-repl PRIVATE ${PROJECT_BINARY_DIR})
|
||||
target_include_directories(serene-repl PRIVATE ${INCLUDE_DIR})
|
||||
|
||||
|
|
|
@ -27,11 +27,15 @@ set_target_properties(serenec PROPERTIES
|
|||
|
||||
target_compile_options(serenec
|
||||
PRIVATE
|
||||
$<$<CONFIG:DEBUG>:-static-libsan>)
|
||||
$<$<CONFIG:DEBUG>:-fsanitize=address>
|
||||
$<$<CONFIG:DEBUG>:-static-libsan>
|
||||
)
|
||||
|
||||
target_link_options(serenec
|
||||
PRIVATE
|
||||
$<$<CONFIG:DEBUG>:-shared-libsan>)
|
||||
$<$<CONFIG:DEBUG>:-fsanitize=address>
|
||||
$<$<CONFIG:DEBUG>:-static-libsan>
|
||||
)
|
||||
|
||||
add_dependencies(serenec Serene::core)
|
||||
|
||||
|
|
Loading…
Reference in New Issue