4747: ${LD:= " ${CXX} " }
4848: ${LDFLAGS:= " ${CXXFLAGS} " } # to make sure we link with sanitizer runtime
4949
50+ FUZZER_ARGS=" "
51+ if [[ " $FUZZING_ENGINE " == libfuzzer ]]; then
52+ FUZZER_ARGS=" -DENABLE_LIBFUZZER_STATIC_LINKAGE=ON"
53+ fi
54+
5055cmake_args=(
5156 # Specific to Tarantool
52- -DENABLE_BACKTRACE=OFF
57+ # Tarantool executable binary is needed for running Lua tests,
58+ # it should not have any dependencies.
59+ -DBUILD_STATIC=ON
60+ -DENABLE_BACKTRACE=ON
5361 -DENABLE_FUZZER=ON
5462 -DOSS_FUZZ=ON
5563 -DLUA_USE_APICHECK=ON
5664 -DLUA_USE_ASSERT=ON
5765 -DLUAJIT_USE_SYSMALLOC=ON
5866 -DLUAJIT_ENABLE_GC64=ON
5967 $SANITIZERS_ARGS
68+ $FUZZER_ARGS
6069
6170 -DCMAKE_BUILD_TYPE=Debug
6271
@@ -76,7 +85,7 @@ cmake_args=(
7685
7786 # Dependencies
7887 -DENABLE_BUNDLED_ICU=ON
79- -DENABLE_BUNDLED_LIBUNWIND=OFF
88+ -DENABLE_BUNDLED_LIBUNWIND=ON
8089 -DENABLE_BUNDLED_ZSTD=OFF
8190)
8291
@@ -90,7 +99,7 @@ cmake --build build --target fuzzers --parallel --verbose
9099
91100# Archive and copy to $OUT seed corpus if the build succeeded.
92101# Postfix `_fuzzer` is used in Tarantool, postfix `_test` is
93- # used in Lua C API tests [1].
102+ # used in additional tests [1].
94103#
95104# 1. https://github.com/ligurio/lunapark
96105cp test/static/* .dict test/static/* .options $OUT /
105114 zip --quiet -j $OUT /" $name " _seed_corpus.zip $corpus_dir /*
106115 fi
107116done
117+
118+ # Finish execution if libFuzzer is not used, because luzer
119+ # is libFuzzer-based.
120+ # UndefinedBehaviorSanitizer is not supported,
121+ # see https://github.com/tarantool/tarantool/issues/12216.
122+ if [[ " $FUZZING_ENGINE " != libfuzzer ]] ||
123+ [[ " $SANITIZER " == " undefined" ]]; then
124+ exit
125+ fi
126+
127+ # Tarantool binary is required for running luzer-based tests.
128+ # Beware, tarantool binary is linked with libFuzzer statically
129+ # when CMake options ENABLE_LIBFUZZER_STATIC_LINKAGE and
130+ # ENABLE_FUZZER are passed, the linkage can fail
131+ # when other fuzzing engine is used due to symbols conflict,
132+ # see FUZZING_ENGINE environment variable.
133+ cmake --build build --target tarantool --parallel --verbose
134+
135+ LUA_RUNTIME_NAME=tarantool
136+ TARANTOOL_PATH=build/src/$LUA_RUNTIME_NAME
137+ LUA_MODULES_DIR=lua_modules
138+
139+ apt install -y luarocks liblua5.1-0 liblua5.1-0-dev liblua5.1-0-dbg lua5.1
140+
141+ # Required by luzer installed using luarocks.
142+ export OSS_FUZZ=1
143+ luarocks install --lua-version 5.1 --server=https://luarocks.org/dev --tree=$LUA_MODULES_DIR luzer
144+ unset OSS_FUZZ
145+
146+ cp build/test/fuzz/lua-tests/src/tests/lapi/lib.lua " $OUT "
147+ LUZER_TEST_DIR=" build/luzer_tests"
148+ # Copying luzer-based tests to a $LUZER_TEST_DIR.
149+ cmake --build build --parallel --verbose --target copy_tests
150+ # Generating test wrappers for luzer-based tests.
151+ for test_file in $( find $LUZER_TEST_DIR -name " *.lua" -type f) ;
152+ do
153+ " $SRC /compile_lua_fuzzer" " $LUA_RUNTIME_NAME " $( basename " $test_file " )
154+ cp " $test_file " " $OUT /"
155+ done
156+
157+ cp $TARANTOOL_PATH " $OUT /$LUA_RUNTIME_NAME "
158+ cp -R $LUA_MODULES_DIR " $OUT /"
0 commit comments