From 580fdc979f75c7790c3f8564455b1c65172afc55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Fri, 8 Mar 2024 12:58:13 +0100 Subject: [PATCH 1/6] build,ci: add ASAN build to CI --- .github/workflows/ci.yml | 17 +++++++++++++++++ CMakeLists.txt | 12 ++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d42c423b..fc7ea08d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -151,3 +151,20 @@ 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 BUILD_WITH_ASAN=ON + - name: Test it + env: + ASAN_OPTIONS: halt_on_error=1 + run: make test diff --git a/CMakeLists.txt b/CMakeLists.txt index 5ee07536..b73d0ed5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,6 +45,8 @@ 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) add_subdirectory(deps/quickjs EXCLUDE_FROM_ALL) @@ -144,8 +146,14 @@ 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) + target_compile_options(tjs PRIVATE -fsanitize=address -fno-sanitize-recover=all -fno-omit-frame-pointer) + target_link_options(tjs PRIVATE -fsanitize=address -fno-sanitize-recover=all -fno-omit-frame-pointer) +elseif(BUILD_WITH_MSAN) + target_compile_options(tjs PRIVATE -fsanitize=memory -fno-sanitize-recover=all -fno-omit-frame-pointer) + target_link_options(tjs PRIVATE -fsanitize=memory -fno-sanitize-recover=all -fno-omit-frame-pointer) +elseif(BUILD_WITH_UBSAN) + target_compile_options(tjs PRIVATE -fsanitize=undefined -fno-sanitize-recover=all -fno-omit-frame-pointer) + target_link_options(tjs PRIVATE -fsanitize=undefined -fno-sanitize-recover=all -fno-omit-frame-pointer) endif() add_executable(tjsc EXCLUDE_FROM_ALL From 11fec1ffbbbcf1b1a709924e87f40ac80e47649e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Fri, 8 Mar 2024 13:08:52 +0100 Subject: [PATCH 2/6] test --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fc7ea08d..cda32434 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -163,7 +163,7 @@ jobs: sudo apt update sudo apt install -y libcurl4-openssl-dev - name: Build it - run: make BUILD_WITH_ASAN=ON + run: make debug BUILD_WITH_ASAN=ON - name: Test it env: ASAN_OPTIONS: halt_on_error=1 From 30102500ca9282dfd9fff374245c231627bd0a52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Fri, 8 Mar 2024 13:14:46 +0100 Subject: [PATCH 3/6] msan,ubsan --- .github/workflows/ci.yml | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cda32434..ac17646e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -168,3 +168,39 @@ jobs: 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 From 45d152b3d2130b9357b3b471a3f61cefe12b3d35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Fri, 8 Mar 2024 13:30:17 +0100 Subject: [PATCH 4/6] test --- CMakeLists.txt | 46 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b73d0ed5..20a186cd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,6 +49,41 @@ 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 + ) +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 + ) +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 + ) +endif() + add_subdirectory(deps/quickjs EXCLUDE_FROM_ALL) option(libuv_buildtests "" OFF) @@ -145,17 +180,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 -fno-sanitize-recover=all -fno-omit-frame-pointer) - target_link_options(tjs PRIVATE -fsanitize=address -fno-sanitize-recover=all -fno-omit-frame-pointer) -elseif(BUILD_WITH_MSAN) - target_compile_options(tjs PRIVATE -fsanitize=memory -fno-sanitize-recover=all -fno-omit-frame-pointer) - target_link_options(tjs PRIVATE -fsanitize=memory -fno-sanitize-recover=all -fno-omit-frame-pointer) -elseif(BUILD_WITH_UBSAN) - target_compile_options(tjs PRIVATE -fsanitize=undefined -fno-sanitize-recover=all -fno-omit-frame-pointer) - target_link_options(tjs PRIVATE -fsanitize=undefined -fno-sanitize-recover=all -fno-omit-frame-pointer) -endif() - add_executable(tjsc EXCLUDE_FROM_ALL src/qjsc.c ) From 1e70fe57f9cfa73fdd7b0c90c2005b1567451a76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Fri, 8 Mar 2024 13:46:45 +0100 Subject: [PATCH 5/6] wip --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 20a186cd..3885d7f1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,6 +60,7 @@ if (BUILD_WITH_ASAN) -fno-sanitize-recover=all -fno-omit-frame-pointer ) + add_compile_definitions(__ASAN__=1) elseif(BUILD_WITH_MSAN) add_compile_options( -fsanitize=memory @@ -71,6 +72,7 @@ elseif(BUILD_WITH_MSAN) -fno-sanitize-recover=all -fno-omit-frame-pointer ) + add_compile_definitions(__MSAN__=1) elseif(BUILD_WITH_UBSAN) add_compile_options( -fsanitize=undefined @@ -82,6 +84,7 @@ elseif(BUILD_WITH_UBSAN) -fno-sanitize-recover=all -fno-omit-frame-pointer ) + add_compile_definitions(__UBSAN__=1) endif() add_subdirectory(deps/quickjs EXCLUDE_FROM_ALL) From 8532f97368918f183226e49cd55c5b61e34f1e0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Fri, 8 Mar 2024 13:53:55 +0100 Subject: [PATCH 6/6] test curl init --- src/curl-utils.c | 14 -------------- src/vm.c | 2 ++ 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/src/curl-utils.c b/src/curl-utils.c index 73790ee2..0041d3b7 100644 --- a/src/curl-utils.c +++ b/src/curl-utils.c @@ -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(); @@ -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); diff --git a/src/vm.c b/src/vm.c index 2a4cf267..e3994bb2 100644 --- a/src/vm.c +++ b/src/vm.c @@ -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)