From 5274042761888d9c0833203d6f96345ab78c27b0 Mon Sep 17 00:00:00 2001 From: Niels Alexander Buegel Date: Wed, 26 Nov 2025 22:56:04 +0100 Subject: [PATCH 1/2] Enable address sanitizer --- .gitlab-ci.yml | 9 ++++++++- .gitlab/ci/build.gitlab-ci.yml | 4 ++++ CMakeLists.txt | 9 +++++++++ continuousintegration/build/build_rpm.sh | 12 ++++++++++++ continuousintegration/build_deploy.sh | 7 +++++++ continuousintegration/docker/el9/build.Dockerfile | 2 +- cta.spec.in | 3 ++- 7 files changed, 43 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b3da571145..90eb6ab983 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -77,6 +77,13 @@ variables: - "RelWithDebInfo" - "MinSizeRel" + ENABLE_ADDRESS_SANITIZER: + description: "Whether to compile with Address Sanitizer enabled" + value: "FALSE" + options: + - "TRUE" + - "FALSE" + # CTA Configuration SCHEDULER_TYPE: description: "Specifies what scheduler should be used to build CTA and run the tests" @@ -180,7 +187,7 @@ variables: # Images IMAGE_DEFAULT: gitlab-registry.cern.ch/cta/public_registry/container_registry/cta-ci-default:2025-11-25-13422989.el9 IMAGE_LINT: gitlab-registry.cern.ch/cta/public_registry/container_registry/cta-ci-lint:2025-11-28-13475409.el9 - IMAGE_BUILD: gitlab-registry.cern.ch/cta/public_registry/container_registry/cta-ci-build:2025-11-25-13422989.el9 + IMAGE_BUILD: gitlab-registry.cern.ch/cta/public_registry/container_registry/cta-ci-build:2025-11-26-13457956.el9 IMAGE_TEST: gitlab-registry.cern.ch/cta/public_registry/container_registry/cta-ci-test:2025-11-25-13422989.el9 IMAGE_RELEASE: gitlab-registry.cern.ch/cta/public_registry/container_registry/cta-ci-release:2025-11-25-13422989.el9 IMAGE_DANGER: gitlab-registry.cern.ch/cta/public_registry/container_registry/cta-ci-danger:2025-11-25-13422989.el9 diff --git a/.gitlab/ci/build.gitlab-ci.yml b/.gitlab/ci/build.gitlab-ci.yml index 7b4b18bab5..4ad1e7e179 100644 --- a/.gitlab/ci/build.gitlab-ci.yml +++ b/.gitlab/ci/build.gitlab-ci.yml @@ -99,6 +99,10 @@ build-cta-rpm: if [[ "$USE_INTERNAL_REPOS" == "TRUE" ]]; then BUILD_OPTIONS+=" --use-internal-repos" fi + - | + if [ "$ENABLE_ADDRESS_SANITIZER" == "TRUE" ]; then + BUILD_OPTIONS+=" --enable-address-sanitizer" + fi - ./continuousintegration/build/build_rpm.sh --build-dir build_rpm --build-generator "${BUILD_GENERATOR}" --create-build-dir diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e08b8dfe5..487cdecf84 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,6 +57,15 @@ if (NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "${PROJECT_DEFAULT_BUILD_TYPE}" CACHE STRING "" FORCE) endif() +if (ENABLE_ADDRESS_SANITIZER) + message(STATUS "Enabling Address Sanitizer") + add_compile_options(-fsanitize=address -fno-omit-frame-pointer) + add_link_options(-fsanitize=address -fno-omit-frame-pointer) + set(RPM_ADDRESS_SANITIZER_OPT "-DENABLE_ADDRESS_SANITIZER:Bool=TRUE" CACHE STRING "" FORCE) +else () + set(RPM_ADDRESS_SANITIZER_OPT "-DENABLE_ADDRESS_SANITIZER:Bool=FALSE" CACHE STRING "" FORCE) +endif() + # To enable logging for testing purposes set -DENABLE_STDOUT_LOGGING=1 if (ENABLE_STDOUT_LOGGING) add_definitions (-DSTDOUT_LOGGING) diff --git a/continuousintegration/build/build_rpm.sh b/continuousintegration/build/build_rpm.sh index f87351936c..a860b9798c 100755 --- a/continuousintegration/build/build_rpm.sh +++ b/continuousintegration/build/build_rpm.sh @@ -38,6 +38,7 @@ usage() { echo " --clean-build-dir: Empties the build directory, ensuring a fresh build from scratch." echo " --create-build-dir Creates the build directory if it does not exist." echo " --enable-ccache: Enables ccache." + echo " --enable-address-sanitizer: Compile with address sanitizer enabled." echo " --skip-cmake Skips the cmake step. Can be used if this script is executed multiple times in succession." echo " --skip-debug-packages Skips the building of the debug RPM packages." echo " --skip-unit-tests Skips the unit tests. Speeds up the build time by not running the unit tests." @@ -70,6 +71,7 @@ build_rpm() { local skip_debug_packages=false local oracle_support=true local use_internal_repos=false + local enable_address_sanitizer=false # Parse command line arguments while [[ "$#" -gt 0 ]]; do @@ -110,6 +112,7 @@ build_rpm() { ;; --clean-build-dir) clean_build_dir=true ;; --create-build-dir) create_build_dir=true ;; + --enable-address-sanitizer) enable_address_sanitizer=true ;; --enable-ccache) enable_ccache=true ;; --cta-version) if [[ $# -gt 1 ]]; then @@ -328,6 +331,15 @@ build_rpm() { cmake_options+=" -D ENABLE_CCACHE:STRING=0" fi + # Address Sanitizer + if [[ ${enable_address_sanitizer} = true ]]; then + echo "Enabling Address Sanitizer" + cmake_options+=" -D ENABLE_ADDRESS_SANITIZER:BOOL=TRUE" + else + # the else clause is necessary to prevent cmake from caching this variable + cmake_options+=" -D ENABLE_ADDRESS_SANITIZER:BOOL=FALSE" + fi + # Scheduler type if [[ ${scheduler_type} == "pgsched" ]]; then echo "Using specified scheduler database type $scheduler_type" diff --git a/continuousintegration/build_deploy.sh b/continuousintegration/build_deploy.sh index e183a894f3..5f4c52b126 100755 --- a/continuousintegration/build_deploy.sh +++ b/continuousintegration/build_deploy.sh @@ -40,6 +40,7 @@ usage() { echo " --cmake-build-type : Specifies the build type for cmake. Must be one of [Release, Debug, RelWithDebInfo, or MinSizeRel]." echo " --disable-oracle-support: Disables support for oracle." echo " --disable-ccache: Disables ccache for the building of the rpms." + echo " --address-sanitizer: Compile with address sanitizer enabled." echo " --force-install: Adds the --install-srpm flag to the build_rpm step, regardless of whether the container was reset or not." echo " --skip-build: Skips the build step." echo " --skip-deploy: Skips the deploy step." @@ -112,6 +113,7 @@ build_deploy() { local use_internal_repos=true local eos_enabled=true local dcache_enabled=false + local enable_address_sanitizer=false # Parse command line arguments @@ -141,6 +143,7 @@ build_deploy() { --use-public-repos) use_internal_repos=false ;; --local-telemetry) local_telemetry=true ;; --publish-telemetry) publish_telemetry=true ;; + --enable-address-sanitizer) enable_address_sanitizer=true ;; --eos-image-tag) if [[ $# -gt 1 ]]; then eos_image_tag="$2" @@ -365,6 +368,10 @@ build_deploy() { build_rpm_flags+=" --use-internal-repos" fi + if [[ ${enable_address_sanitizer} = true ]]; then + build_rpm_flags+=" --address-sanitizer" + fi + print_header "BUILDING RPMS" ${container_runtime} exec -it "${build_container_name}" \ ./shared/CTA/continuousintegration/build/build_rpm.sh \ diff --git a/continuousintegration/docker/el9/build.Dockerfile b/continuousintegration/docker/el9/build.Dockerfile index 13ab3669fb..5df7233fe1 100644 --- a/continuousintegration/docker/el9/build.Dockerfile +++ b/continuousintegration/docker/el9/build.Dockerfile @@ -17,5 +17,5 @@ FROM gitlab-registry.cern.ch/linuxsupport/alma9-base:latest RUN dnf install -y epel-release almalinux-release-devel git python3-dnf-plugin-versionlock -RUN dnf install -y gcc gcc-c++ cmake3 rpm-build dnf-utils make ninja-build ccache systemd-devel clang-tools-extra && \ +RUN dnf install -y gcc gcc-c++ cmake3 rpm-build dnf-utils make ninja-build ccache systemd-devel clang-tools-extra libasan && \ dnf clean all --enablerepo=\* diff --git a/cta.spec.in b/cta.spec.in index aeaf25154d..f4320e46ae 100644 --- a/cta.spec.in +++ b/cta.spec.in @@ -9,6 +9,7 @@ %define usingObjectstore @RPM_USINGOBJECTSTORE@ %define occiSupport @RPM_USING_ORACLE@ %define schedOpt @RPM_SCHEDOPT@ +%define asanOptions @RPM_ADDRESS_SANITIZER_OPT@ %define oracleOpt @RPM_ORACLE@ %define buildGenerator @CMAKE_GENERATOR@ @@ -87,7 +88,7 @@ The CTA project is the CERN Tape Archive system. mkdir -p build cd build # ccacheFlags will be empty if ccache is not enabled -CTA_VERSION=%{ctaVersion} cmake3 -G "%{buildGenerator}" .. %{ccacheFlags} -DCOMPILE_PACKAGING:STRING=0 -DVCS_VERSION=%{ctaRelease} %{schedOpt} %{oracleOpt} +CTA_VERSION=%{ctaVersion} cmake3 -G "%{buildGenerator}" .. %{ccacheFlags} -DCOMPILE_PACKAGING:STRING=0 -DVCS_VERSION=%{ctaRelease} %{schedOpt} %{oracleOpt} %{asanOptions} cmake --build . -j@JOBS_COUNT@ %install -- GitLab From 381732b516d982a9c07795a27abb415bd365dd98 Mon Sep 17 00:00:00 2001 From: Niels Alexander Buegel Date: Mon, 1 Dec 2025 13:45:47 +0100 Subject: [PATCH 2/2] Fixed help message in build_deploy --- continuousintegration/build_deploy.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/continuousintegration/build_deploy.sh b/continuousintegration/build_deploy.sh index 5f4c52b126..a7192b612e 100755 --- a/continuousintegration/build_deploy.sh +++ b/continuousintegration/build_deploy.sh @@ -40,7 +40,7 @@ usage() { echo " --cmake-build-type : Specifies the build type for cmake. Must be one of [Release, Debug, RelWithDebInfo, or MinSizeRel]." echo " --disable-oracle-support: Disables support for oracle." echo " --disable-ccache: Disables ccache for the building of the rpms." - echo " --address-sanitizer: Compile with address sanitizer enabled." + echo " --enable-address-sanitizer: Compile with address sanitizer enabled." echo " --force-install: Adds the --install-srpm flag to the build_rpm step, regardless of whether the container was reset or not." echo " --skip-build: Skips the build step." echo " --skip-deploy: Skips the deploy step." -- GitLab