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:DEBUG>:-fno-omit-frame-pointer>
|
||||||
$<$<CONFIG:RELEASE>:-fomit-frame-pointer>
|
$<$<CONFIG:RELEASE>:-fomit-frame-pointer>
|
||||||
$<$<CONFIG:DEBUG>:-fsanitize=address>
|
|
||||||
|
|
||||||
$<$<CONFIG:RELEASE>:-O3>
|
$<$<CONFIG:RELEASE>:-O3>
|
||||||
$<$<CONFIG:RELEASE>:-fmerge-all-constants>
|
$<$<CONFIG:RELEASE>:-fmerge-all-constants>
|
||||||
|
@ -120,8 +119,6 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
|
||||||
# We enforce the lld linker
|
# We enforce the lld linker
|
||||||
-fuse-ld=lld
|
-fuse-ld=lld
|
||||||
-Wl,-gc-sections
|
-Wl,-gc-sections
|
||||||
$<$<CONFIG:RELEASE>:-fsanitize-address-globals-dead-stripping>
|
|
||||||
$<$<CONFIG:DEBUG>:-fsanitize=address>
|
|
||||||
$<$<CONFIG:RELEASE>:-s>
|
$<$<CONFIG:RELEASE>:-s>
|
||||||
# Do not link against shared libraries
|
# Do not link against shared libraries
|
||||||
#--static
|
#--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
|
function build-release() { ## Builds the project in "Release" mode
|
||||||
clean
|
clean
|
||||||
pushed_build
|
pushed_build
|
||||||
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release "$ROOT_DIR"
|
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release "${CMAKEARGS[@]}" "$ROOT_DIR"
|
||||||
cmake --build .
|
cmake --build . --config Release
|
||||||
popd_build
|
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
|
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
|
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
|
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
|
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"
|
local test_file="$BUILD_DIR/$proj/tests/${proj}Tests"
|
||||||
|
|
||||||
if [[ -f "$test_file" ]]; then
|
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
|
fi
|
||||||
done
|
done
|
||||||
else
|
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
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -303,8 +298,6 @@ function setup() { ## Setup the working directory and make it ready for developm
|
||||||
else
|
else
|
||||||
error "Python is required to setup pre-commit"
|
error "Python is required to setup pre-commit"
|
||||||
fi
|
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)
|
function setup-dev() { ## Setup the container like env to build/develop Serene (requires sudo access)
|
||||||
|
|
|
@ -23,7 +23,7 @@ if(NOT APPLE)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(SOURCES core.cpp)
|
set(SOURCES core.cpp)
|
||||||
add_library(core STATIC
|
add_library(core OBJECT
|
||||||
${SOURCES})
|
${SOURCES})
|
||||||
|
|
||||||
#add_custom_target(serene.core)
|
#add_custom_target(serene.core)
|
||||||
|
@ -41,14 +41,12 @@ set_target_properties(core PROPERTIES
|
||||||
LINK_WHAT_YOU_USE TRUE
|
LINK_WHAT_YOU_USE TRUE
|
||||||
CXX_INCLUDE_WHAT_YOU_USE "${iwyu_path}"
|
CXX_INCLUDE_WHAT_YOU_USE "${iwyu_path}"
|
||||||
C_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)
|
INTERPROCEDURAL_OPTIMIZATION FALSE)
|
||||||
|
|
||||||
target_compile_options(core PUBLIC -fsanitize=address -static-libsan --static)
|
target_compile_options(core PRIVATE --static)
|
||||||
target_link_options(core PUBLIC -fsanitize=address -static-libsan --static)
|
target_link_options(core PRIVATE --static)
|
||||||
|
|
||||||
get_target_property(MFLAGS core COMPILE_OPTIONS)
|
|
||||||
message(STATUS "------ ${MFLAGS}")
|
|
||||||
|
|
||||||
if(SERENE_ENABLE_TIDY)
|
if(SERENE_ENABLE_TIDY)
|
||||||
set_target_properties(core PROPERTIES CXX_CLANG_TIDY ${CLANG_TIDY_PATH})
|
set_target_properties(core PROPERTIES CXX_CLANG_TIDY ${CLANG_TIDY_PATH})
|
||||||
|
|
|
@ -47,35 +47,15 @@ set_target_properties(serene PROPERTIES
|
||||||
INTERPROCEDURAL_OPTIMIZATION TRUE)
|
INTERPROCEDURAL_OPTIMIZATION TRUE)
|
||||||
|
|
||||||
target_compile_options(serene
|
target_compile_options(serene
|
||||||
PRIVATE
|
PRIVATE)
|
||||||
$<$<CONFIG:DEBUG>:-static-libsan>)
|
|
||||||
|
|
||||||
target_link_options(serene
|
target_link_options(serene
|
||||||
PRIVATE
|
PRIVATE)
|
||||||
$<$<CONFIG:DEBUG>:-shared-libsan>)
|
|
||||||
|
|
||||||
|
|
||||||
if(SERENE_ENABLE_TIDY)
|
if(SERENE_ENABLE_TIDY)
|
||||||
set_target_properties(serene PROPERTIES CXX_CLANG_TIDY ${CLANG_TIDY_PATH})
|
set_target_properties(serene PROPERTIES CXX_CLANG_TIDY ${CLANG_TIDY_PATH})
|
||||||
endif()
|
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)
|
if (CPP_20_SUPPORT)
|
||||||
target_compile_features(serene PUBLIC cxx_std_20)
|
target_compile_features(serene PUBLIC cxx_std_20)
|
||||||
else()
|
else()
|
||||||
|
|
|
@ -42,6 +42,18 @@ target_link_libraries(serene-repl
|
||||||
Serene::lib
|
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 ${PROJECT_BINARY_DIR})
|
||||||
target_include_directories(serene-repl PRIVATE ${INCLUDE_DIR})
|
target_include_directories(serene-repl PRIVATE ${INCLUDE_DIR})
|
||||||
|
|
||||||
|
|
|
@ -27,11 +27,15 @@ set_target_properties(serenec PROPERTIES
|
||||||
|
|
||||||
target_compile_options(serenec
|
target_compile_options(serenec
|
||||||
PRIVATE
|
PRIVATE
|
||||||
$<$<CONFIG:DEBUG>:-static-libsan>)
|
$<$<CONFIG:DEBUG>:-fsanitize=address>
|
||||||
|
$<$<CONFIG:DEBUG>:-static-libsan>
|
||||||
|
)
|
||||||
|
|
||||||
target_link_options(serenec
|
target_link_options(serenec
|
||||||
PRIVATE
|
PRIVATE
|
||||||
$<$<CONFIG:DEBUG>:-shared-libsan>)
|
$<$<CONFIG:DEBUG>:-fsanitize=address>
|
||||||
|
$<$<CONFIG:DEBUG>:-static-libsan>
|
||||||
|
)
|
||||||
|
|
||||||
add_dependencies(serenec Serene::core)
|
add_dependencies(serenec Serene::core)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue