Skip to content

Commit fce97c0

Browse files
committed
feat(ci): Add ASAN and UBSAN build and CI job
1 parent 2302437 commit fce97c0

File tree

5 files changed

+149
-6
lines changed

5 files changed

+149
-6
lines changed

.github/workflows/linux-build-base.yml

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,3 +270,111 @@ jobs:
270270
with:
271271
path: ${{ env.CCACHE_DIR }}
272272
key: ccache-fedora-debug-default-gcc
273+
274+
asan-ubsan-adapters:
275+
name: Linux debug with adapters - testing asan and ubsan
276+
# prevent errors when forks ff their main branch
277+
if: ${{ github.repository == 'facebookincubator/velox' }}
278+
runs-on: ubuntu-latest
279+
container:
280+
image: ghcr.io/facebookincubator/velox-dev:adapters
281+
volumes:
282+
- /usr:/host_usr
283+
- /opt:/host_opt
284+
defaults:
285+
run:
286+
shell: bash
287+
env:
288+
CCACHE_DIR: ${{ github.workspace }}/ccache
289+
VELOX_DEPENDENCY_SOURCE: SYSTEM
290+
faiss_SOURCE: BUNDLED
291+
concurrency:
292+
group: ${{ github.workflow }}-asan-ubsan-adapters-${{ github.event.pull_request.number }}
293+
cancel-in-progress: true
294+
steps:
295+
- name: Free Disk Space
296+
run: |
297+
# Re-used from free-disk-space github action.
298+
getAvailableSpace() { echo $(df -a $1 | awk 'NR > 1 {avail+=$4} END {print avail}'); }
299+
# Show before
300+
echo "Original available disk space: " $(getAvailableSpace)
301+
# Remove DotNet.
302+
rm -rf /host_usr/share/dotnet || true
303+
# Remove android
304+
rm -rf /host_usr/local/lib/android || true
305+
# Remove CodeQL
306+
rm -rf /host_opt/hostedtoolcache/CodeQL || true
307+
# Show after
308+
echo "New available disk space: " $(getAvailableSpace)
309+
310+
- uses: actions/checkout@v5
311+
with:
312+
fetch-depth: 2
313+
persist-credentials: false
314+
315+
- name: Fix git permissions
316+
# Usually actions/checkout does this but as we run in a container
317+
# it doesn't work
318+
run: git config --global --add safe.directory ${GITHUB_WORKSPACE}
319+
320+
- uses: apache/infrastructure-actions/stash/restore@3354c1565d4b0e335b78a76aedd82153a9e144d4
321+
with:
322+
path: ${{ env.CCACHE_DIR }}
323+
key: ccache-asan-ubsan-adapters
324+
325+
- name: Zero Ccache Statistics
326+
run: |
327+
ccache -sz
328+
329+
- name: Make Debug Build
330+
env:
331+
MAKEFLAGS: NUM_THREADS=4 MAX_HIGH_MEM_JOBS=3 MAX_LINK_JOBS=3
332+
CUDA_VERSION: '12.8'
333+
CUDA_ARCHITECTURES: 70
334+
CUDA_COMPILER: /usr/local/cuda-${CUDA_VERSION}/bin/nvcc
335+
# Set compiler to GCC 12 for CUDA
336+
CUDA_FLAGS: -ccbin /opt/rh/gcc-toolset-12/root/usr/bin
337+
run: |
338+
EXTRA_CMAKE_FLAGS=(
339+
"-DVELOX_ENABLE_ASAN_UBSAN_SANITIZERS=ON"
340+
"-DVELOX_ENABLE_BENCHMARKS=ON"
341+
"-DVELOX_ENABLE_EXAMPLES=ON"
342+
"-DVELOX_ENABLE_ARROW=ON"
343+
"-DVELOX_ENABLE_GEO=ON"
344+
"-DVELOX_ENABLE_PARQUET=ON"
345+
"-DVELOX_ENABLE_HDFS=ON"
346+
"-DVELOX_ENABLE_S3=ON"
347+
"-DVELOX_ENABLE_GCS=ON"
348+
"-DVELOX_ENABLE_ABFS=ON"
349+
"-DVELOX_ENABLE_WAVE=ON"
350+
"-DVELOX_MONO_LIBRARY=ON"
351+
"-DVELOX_BUILD_SHARED=ON"
352+
"-DVELOX_ENABLE_REMOTE_FUNCTIONS=ON"
353+
)
354+
clang++ --version
355+
dnf install -y compiler-rt
356+
CC=clang CXX=clang++ make debug EXTRA_CMAKE_FLAGS="${EXTRA_CMAKE_FLAGS[*]}"
357+
358+
- name: Ccache after
359+
run: ccache -s
360+
361+
- uses: apache/infrastructure-actions/stash/save@3354c1565d4b0e335b78a76aedd82153a9e144d4
362+
with:
363+
path: ${{ env.CCACHE_DIR }}
364+
key: ccache-asan-ubsan-adapters
365+
366+
- name: Run Tests
367+
env:
368+
LIBHDFS3_CONF: ${{ github.workspace }}/scripts/ci/hdfs-client.xml
369+
working-directory: _build/debug
370+
run: |
371+
# Can be removed after images are rebuild
372+
if [ -f "/opt/miniforge/etc/profile.d/conda.sh" ]; then
373+
source "/opt/miniforge/etc/profile.d/conda.sh"
374+
conda activate adapters
375+
fi
376+
# Needed for HADOOP 3.3.6 minicluster. Can remove after updating to 3.4.2.
377+
wget https://repo1.maven.org/maven2/org/mockito/mockito-core/2.23.4/mockito-core-2.23.4.jar -O /usr/local/hadoop/share/hadoop/mapreduce/mockito-core-2.23.4.jar
378+
379+
export CLASSPATH=`/usr/local/hadoop/bin/hdfs classpath --glob`
380+
ctest -j 4 --label-exclude cuda_driver --output-on-failure --no-tests=error

CMakeLists.txt

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,13 @@ option(VELOX_ENABLE_FAISS "Build faiss vector search support" OFF)
179179
# is broken if you use ninja.
180180
option(VELOX_FORCE_COLORED_OUTPUT "Always produce ANSI-colored output (GNU/Clang only)." OFF)
181181

182+
# Enable the address and undefined behavior sanitizers. They can run together.
183+
option(
184+
VELOX_ENABLE_ASAN_UBSAN_SANITIZERS
185+
"Builds velox with Clang ASAN and UBSAN sanitizer flags"
186+
OFF
187+
)
188+
182189
if(${VELOX_BUILD_MINIMAL} OR ${VELOX_BUILD_MINIMAL_WITH_DWIO})
183190
# Enable and disable components for velox base build
184191
set(VELOX_BUILD_TESTING OFF)
@@ -508,10 +515,7 @@ endif()
508515

509516
# Set after the test of the CUDA compiler. Otherwise, the test fails with
510517
# -latomic not found because it is added right after the compiler exe.
511-
if(
512-
"${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang"
513-
AND "${CMAKE_CXX_COMPILER_VERSION}" VERSION_GREATER_EQUAL 15
514-
)
518+
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND "${CMAKE_CXX_COMPILER_VERSION}" VERSION_EQUAL 15)
515519
set(CMAKE_EXE_LINKER_FLAGS "-latomic")
516520
endif()
517521

@@ -729,7 +733,23 @@ if("${TREAT_WARNINGS_AS_ERRORS}")
729733
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
730734
endif()
731735

736+
# Enable the ASAN and UBSAN sanitzers for Clang 20 and above.
737+
# Also only eligible with the type debug build.
738+
if(
739+
VELOX_ENABLE_ASAN_UBSAN_SANITIZERS
740+
AND CMAKE_BUILD_TYPE STREQUAL "Debug"
741+
AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang"
742+
AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 20
743+
)
744+
set(
745+
CMAKE_CXX_FLAGS
746+
"${CMAKE_CXX_FLAGS} -O1 -fsanitize=address -fsanitize=undefined -fno-omit-frame-pointer"
747+
)
748+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address -fsanitize=undefined")
749+
endif()
750+
732751
message("FINAL CMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}")
752+
message("FINAL CMAKE_EXE_LINKER_FLAGS=${CMAKE_EXE_LINKER_FLAGS}")
733753

734754
if(VELOX_ENABLE_ARROW)
735755
velox_set_source(Arrow)

scripts/setup-centos9.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ function install_build_prerequisites {
5656
dnf config-manager --set-enabled crb
5757
dnf update -y
5858
fi
59-
dnf_install autoconf automake ccache clang gcc-toolset-12 gcc-toolset-14 git libtool \
59+
dnf_install autoconf automake ccache clang compiler-rt \
60+
gcc-toolset-12 gcc-toolset-14 git libtool \
6061
llvm ninja-build python3-pip python3-devel wget which
6162

6263
install_uv

velox/common/base/Macros.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@
2828
_Pragma("GCC diagnostic pop");
2929
#endif
3030

31+
#if defined(__clang__) && defined(__has_warning) && \
32+
__has_warning("-Wmissing-designated-field-initializers")
33+
#define VELOX_SUPPRESS_MISSING_DESIGNATED_FIELD_INITIALIZERS_WARNING \
34+
_Pragma("clang diagnostic push"); \
35+
_Pragma( \
36+
"clang diagnostic ignored \"-Wmissing-designated-field-initializers\"")
37+
#define VELOX_UNSUPPRESS_MISSING_DESIGNATED_FIELD_INITIALIZERS_WARNING \
38+
_Pragma("clang diagnostic pop");
39+
#else
40+
#define VELOX_SUPPRESS_MISSING_DESIGNATED_FIELD_INITIALIZERS_WARNING
41+
#define VELOX_UNSUPPRESS_MISSING_DESIGNATED_FIELD_INITIALIZERS_WARNING
42+
#endif
43+
3144
#define VELOX_CONCAT(x, y) x##y
3245
// Need this extra layer to expand __COUNTER__.
3346
#define VELOX_VARNAME_IMPL(x, y) VELOX_CONCAT(x, y)

velox/functions/prestosql/DateTimeFunctions.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1963,10 +1963,11 @@ struct ParseDurationFunction {
19631963
FOLLY_ALWAYS_INLINE void call(
19641964
out_type<IntervalDayTime>& result,
19651965
const arg_type<Varchar>& amountUnit) {
1966+
VELOX_SUPPRESS_MISSING_DESIGNATED_FIELD_INITIALIZERS_WARNING
19661967
static const LazyRE2 kDurationRegex{
19671968
.pattern_ = R"(^\s*(\d+(?:\.\d+)?)\s*([a-zA-Z]+)\s*$)",
1968-
.options_ = {},
19691969
};
1970+
VELOX_UNSUPPRESS_MISSING_DESIGNATED_FIELD_INITIALIZERS_WARNING
19701971
// TODO: Remove re2::StringPiece != std::string_view hacks.
19711972
// It's needed because for some systems in CI,
19721973
// re2 and abseil libraries are old.

0 commit comments

Comments
 (0)