Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build,ci: add ASAN build to CI #463

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,56 @@ jobs:
run: make VERBOSE=1
- name: Test it
run: make test
linux-asan:
name: ASAN
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Dependencies
run: |
sudo apt update
sudo apt install -y libcurl4-openssl-dev
- name: Build it
run: make debug BUILD_WITH_ASAN=ON
- name: Test it
env:
ASAN_OPTIONS: halt_on_error=1
run: make test
linux-msan:
name: MSAN
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Dependencies
run: |
sudo apt update
sudo apt install -y libcurl4-openssl-dev
- name: Build it
env:
CC: clang
run: make debug BUILD_WITH_MSAN=ON
- name: Test it
env:
MSAN_OPTIONS: halt_on_error=1
run: make test
linux-ubsan:
name: UBSAN
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Dependencies
run: |
sudo apt update
sudo apt install -y libcurl4-openssl-dev
- name: Build it
run: make debug BUILD_WITH_UBSAN=ON
- name: Test it
env:
UBSAN_OPTIONS: halt_on_error=1
run: make test
45 changes: 40 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,48 @@ macro(cpr_option OPTION_NAME OPTION_TEXT OPTION_DEFAULT)
endmacro()

cpr_option(BUILD_WITH_ASAN "If ON, build with the address sanitizer enabled" OFF)
cpr_option(BUILD_WITH_MSAN "If ON, build with the memory sanitizer enabled" OFF)
cpr_option(BUILD_WITH_UBSAN "If ON, build with the undefined behavior sanitizer enabled" OFF)
cpr_option(USE_EXTERNAL_FFI "Specify to use external ffi dependency" OFF)

if (BUILD_WITH_ASAN)
add_compile_options(
-fsanitize=address
-fno-sanitize-recover=all
-fno-omit-frame-pointer
)
add_link_options(
-fsanitize=address
-fno-sanitize-recover=all
-fno-omit-frame-pointer
)
add_compile_definitions(__ASAN__=1)
elseif(BUILD_WITH_MSAN)
add_compile_options(
-fsanitize=memory
-fno-sanitize-recover=all
-fno-omit-frame-pointer
)
add_link_options(
-fsanitize=memory
-fno-sanitize-recover=all
-fno-omit-frame-pointer
)
add_compile_definitions(__MSAN__=1)
elseif(BUILD_WITH_UBSAN)
add_compile_options(
-fsanitize=undefined
-fno-sanitize-recover=all
-fno-omit-frame-pointer
)
add_link_options(
-fsanitize=undefined
-fno-sanitize-recover=all
-fno-omit-frame-pointer
)
add_compile_definitions(__UBSAN__=1)
endif()

add_subdirectory(deps/quickjs EXCLUDE_FROM_ALL)

option(libuv_buildtests "" OFF)
Expand Down Expand Up @@ -143,11 +183,6 @@ target_compile_definitions(tjs PRIVATE TJS__PLATFORM="${TJS_PLATFORM}")
target_include_directories(tjs PRIVATE ${CURL_INCLUDE_DIRS})
target_link_libraries(tjs qjs uv_a m3 sqlite3 m pthread ${CURL_LIBRARIES})

if (BUILD_WITH_ASAN)
target_compile_options(tjs PRIVATE -fsanitize=address)
target_link_options(tjs PRIVATE -fsanitize=address)
endif()

add_executable(tjsc EXCLUDE_FROM_ALL
src/qjsc.c
)
Expand Down
14 changes: 0 additions & 14 deletions src/curl-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,7 @@
"txiki.js/" STRINGIFY(TJS_VERSION_MAJOR) "." STRINGIFY(TJS_VERSION_MINOR) "." STRINGIFY(TJS_VERSION_PATCH) \
TJS_VERSION_SUFFIX

static uv_once_t curl__init_once = UV_ONCE_INIT;

static void tjs__curl_init_once(void) {
curl_global_init(CURL_GLOBAL_ALL);
}

static void tjs__curl_init(void) {
uv_once(&curl__init_once, tjs__curl_init_once);
}

CURL *tjs__curl_easy_init(CURL *curl_h) {
tjs__curl_init();

if (curl_h == NULL)
curl_h = curl_easy_init();

Expand Down Expand Up @@ -261,8 +249,6 @@ CURLM *tjs__get_curlm(JSContext *ctx) {
CHECK_NOT_NULL(qrt);

if (!qrt->curl_ctx.curlm_h) {
tjs__curl_init();

CURLM *curlm_h = curl_multi_init();
curl_multi_setopt(curlm_h, CURLMOPT_SOCKETFUNCTION, curl__handle_socket);
curl_multi_setopt(curlm_h, CURLMOPT_SOCKETDATA, qrt);
Expand Down
2 changes: 2 additions & 0 deletions src/vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@ void TJS_FreeRuntime(TJSRuntime *qrt) {
}

void TJS_SetupArgs(int argc, char **argv) {
curl_global_init(CURL_GLOBAL_ALL);

tjs__argc = argc;
tjs__argv = uv_setup_args(argc, argv);
if (!tjs__argv)
Expand Down
Loading