mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
Enable asan on debug macos aarch64 builds (#17058)
This commit is contained in:
3
Makefile
3
Makefile
@@ -1301,6 +1301,7 @@ jsc-build-mac-compile-lto:
|
|||||||
.PHONY: jsc-build-mac-compile-debug
|
.PHONY: jsc-build-mac-compile-debug
|
||||||
jsc-build-mac-compile-debug:
|
jsc-build-mac-compile-debug:
|
||||||
mkdir -p $(WEBKIT_DEBUG_DIR) $(WEBKIT_DIR);
|
mkdir -p $(WEBKIT_DEBUG_DIR) $(WEBKIT_DIR);
|
||||||
|
# to disable asan, remove -DENABLE_SANITIZERS=address and add -DENABLE_MALLOC_HEAP_BREAKDOWN=ON
|
||||||
cd $(WEBKIT_DEBUG_DIR) && \
|
cd $(WEBKIT_DEBUG_DIR) && \
|
||||||
ICU_INCLUDE_DIRS="$(HOMEBREW_PREFIX)opt/icu4c/include" \
|
ICU_INCLUDE_DIRS="$(HOMEBREW_PREFIX)opt/icu4c/include" \
|
||||||
cmake \
|
cmake \
|
||||||
@@ -1309,7 +1310,6 @@ jsc-build-mac-compile-debug:
|
|||||||
-DCMAKE_BUILD_TYPE=Debug \
|
-DCMAKE_BUILD_TYPE=Debug \
|
||||||
-DUSE_THIN_ARCHIVES=OFF \
|
-DUSE_THIN_ARCHIVES=OFF \
|
||||||
-DENABLE_FTL_JIT=ON \
|
-DENABLE_FTL_JIT=ON \
|
||||||
-DENABLE_MALLOC_HEAP_BREAKDOWN=ON \
|
|
||||||
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
|
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
|
||||||
-DUSE_BUN_JSC_ADDITIONS=ON \
|
-DUSE_BUN_JSC_ADDITIONS=ON \
|
||||||
-DUSE_BUN_EVENT_LOOP=ON \
|
-DUSE_BUN_EVENT_LOOP=ON \
|
||||||
@@ -1321,6 +1321,7 @@ jsc-build-mac-compile-debug:
|
|||||||
-DUSE_PTHREAD_JIT_PERMISSIONS_API=ON \
|
-DUSE_PTHREAD_JIT_PERMISSIONS_API=ON \
|
||||||
-DENABLE_REMOTE_INSPECTOR=ON \
|
-DENABLE_REMOTE_INSPECTOR=ON \
|
||||||
-DUSE_VISIBILITY_ATTRIBUTE=1 \
|
-DUSE_VISIBILITY_ATTRIBUTE=1 \
|
||||||
|
-DENABLE_SANITIZERS=address \
|
||||||
$(WEBKIT_DIR) \
|
$(WEBKIT_DIR) \
|
||||||
$(WEBKIT_DEBUG_DIR) && \
|
$(WEBKIT_DEBUG_DIR) && \
|
||||||
CFLAGS="$(CFLAGS) -ffat-lto-objects" CXXFLAGS="$(CXXFLAGS) -ffat-lto-objects" \
|
CFLAGS="$(CFLAGS) -ffat-lto-objects" CXXFLAGS="$(CXXFLAGS) -ffat-lto-objects" \
|
||||||
|
|||||||
11
build.zig
11
build.zig
@@ -46,6 +46,7 @@ const BunBuildOptions = struct {
|
|||||||
sha: []const u8,
|
sha: []const u8,
|
||||||
/// enable debug logs in release builds
|
/// enable debug logs in release builds
|
||||||
enable_logs: bool = false,
|
enable_logs: bool = false,
|
||||||
|
enable_asan: bool,
|
||||||
tracy_callstack_depth: u16,
|
tracy_callstack_depth: u16,
|
||||||
reported_nodejs_version: Version,
|
reported_nodejs_version: Version,
|
||||||
/// To make iterating on some '@embedFile's faster, we load them at runtime
|
/// To make iterating on some '@embedFile's faster, we load them at runtime
|
||||||
@@ -275,6 +276,7 @@ pub fn build(b: *Build) !void {
|
|||||||
|
|
||||||
.tracy_callstack_depth = b.option(u16, "tracy_callstack_depth", "") orelse 10,
|
.tracy_callstack_depth = b.option(u16, "tracy_callstack_depth", "") orelse 10,
|
||||||
.enable_logs = b.option(bool, "enable_logs", "Enable logs in release") orelse false,
|
.enable_logs = b.option(bool, "enable_logs", "Enable logs in release") orelse false,
|
||||||
|
.enable_asan = b.option(bool, "enable_asan", "Enable asan") orelse false,
|
||||||
};
|
};
|
||||||
|
|
||||||
// zig build obj
|
// zig build obj
|
||||||
@@ -393,6 +395,7 @@ pub fn addMultiCheck(
|
|||||||
.reported_nodejs_version = root_build_options.reported_nodejs_version,
|
.reported_nodejs_version = root_build_options.reported_nodejs_version,
|
||||||
.codegen_path = root_build_options.codegen_path,
|
.codegen_path = root_build_options.codegen_path,
|
||||||
.no_llvm = root_build_options.no_llvm,
|
.no_llvm = root_build_options.no_llvm,
|
||||||
|
.enable_asan = root_build_options.enable_asan,
|
||||||
};
|
};
|
||||||
|
|
||||||
var obj = addBunObject(b, &options);
|
var obj = addBunObject(b, &options);
|
||||||
@@ -440,6 +443,14 @@ pub fn addBunObject(b: *Build, opts: *BunBuildOptions) *Compile {
|
|||||||
.omit_frame_pointer = false,
|
.omit_frame_pointer = false,
|
||||||
.strip = false, // stripped at the end
|
.strip = false, // stripped at the end
|
||||||
});
|
});
|
||||||
|
if (opts.enable_asan) {
|
||||||
|
if (@hasField(Build.Module, "sanitize_address")) {
|
||||||
|
obj.root_module.sanitize_address = true;
|
||||||
|
} else {
|
||||||
|
const fail_step = b.addFail("asan is not supported on this platform");
|
||||||
|
obj.step.dependOn(&fail_step.step);
|
||||||
|
}
|
||||||
|
}
|
||||||
obj.bundle_compiler_rt = false;
|
obj.bundle_compiler_rt = false;
|
||||||
obj.root_module.omit_frame_pointer = false;
|
obj.root_module.omit_frame_pointer = false;
|
||||||
|
|
||||||
|
|||||||
@@ -44,6 +44,13 @@ if(WIN32)
|
|||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(ENABLE_ASAN)
|
||||||
|
register_compiler_flags(
|
||||||
|
DESCRIPTION "Enable AddressSanitizer"
|
||||||
|
-fsanitize=address
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
# --- Optimization level ---
|
# --- Optimization level ---
|
||||||
if(DEBUG)
|
if(DEBUG)
|
||||||
register_compiler_flags(
|
register_compiler_flags(
|
||||||
|
|||||||
@@ -86,6 +86,11 @@ optionx(ENABLE_LTO BOOL "If LTO (link-time optimization) should be used" DEFAULT
|
|||||||
if(LINUX)
|
if(LINUX)
|
||||||
optionx(ENABLE_VALGRIND BOOL "If Valgrind support should be enabled" DEFAULT OFF)
|
optionx(ENABLE_VALGRIND BOOL "If Valgrind support should be enabled" DEFAULT OFF)
|
||||||
endif()
|
endif()
|
||||||
|
if(DEBUG AND APPLE AND CMAKE_SYSTEM_PROCESSOR MATCHES "arm64|aarch64")
|
||||||
|
optionx(ENABLE_ASAN BOOL "If ASAN support should be enabled" DEFAULT ON)
|
||||||
|
else()
|
||||||
|
optionx(ENABLE_ASAN BOOL "If ASAN support should be enabled" DEFAULT OFF)
|
||||||
|
endif()
|
||||||
|
|
||||||
optionx(ENABLE_PRETTIER BOOL "If prettier should be ran" DEFAULT OFF)
|
optionx(ENABLE_PRETTIER BOOL "If prettier should be ran" DEFAULT OFF)
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,12 @@ else()
|
|||||||
message(FATAL_ERROR "Unsupported architecture: ${CMAKE_HOST_SYSTEM_PROCESSOR}")
|
message(FATAL_ERROR "Unsupported architecture: ${CMAKE_HOST_SYSTEM_PROCESSOR}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(ZIG_NAME zig-${ZIG_OS}-${ZIG_ARCH}-${ZIG_VERSION})
|
set(ZIG_ASAN "")
|
||||||
|
if(ENABLE_ASAN)
|
||||||
|
set(ZIG_ASAN "+asan")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(ZIG_NAME zig-${ZIG_OS}-${ZIG_ARCH}-${ZIG_VERSION}${ZIG_ASAN})
|
||||||
|
|
||||||
if(CMAKE_HOST_WIN32)
|
if(CMAKE_HOST_WIN32)
|
||||||
set(ZIG_EXE "zig.exe")
|
set(ZIG_EXE "zig.exe")
|
||||||
|
|||||||
@@ -567,6 +567,7 @@ register_command(
|
|||||||
-Dcanary=${CANARY_REVISION}
|
-Dcanary=${CANARY_REVISION}
|
||||||
-Dcodegen_path=${CODEGEN_PATH}
|
-Dcodegen_path=${CODEGEN_PATH}
|
||||||
-Dcodegen_embed=$<IF:$<BOOL:${CODEGEN_EMBED}>,true,false>
|
-Dcodegen_embed=$<IF:$<BOOL:${CODEGEN_EMBED}>,true,false>
|
||||||
|
-Denable_asan=$<IF:$<BOOL:${ENABLE_ASAN}>,true,false>
|
||||||
--prominent-compile-errors
|
--prominent-compile-errors
|
||||||
${ZIG_FLAGS_BUN}
|
${ZIG_FLAGS_BUN}
|
||||||
ARTIFACTS
|
ARTIFACTS
|
||||||
@@ -829,6 +830,15 @@ if(NOT WIN32)
|
|||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if (ENABLE_ASAN)
|
||||||
|
target_compile_options(${bun} PUBLIC
|
||||||
|
-fsanitize=address
|
||||||
|
)
|
||||||
|
target_link_libraries(${bun} PUBLIC
|
||||||
|
-fsanitize=address
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
target_compile_options(${bun} PUBLIC
|
target_compile_options(${bun} PUBLIC
|
||||||
-Werror=return-type
|
-Werror=return-type
|
||||||
-Werror=return-stack-address
|
-Werror=return-stack-address
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ register_repository(
|
|||||||
REPOSITORY
|
REPOSITORY
|
||||||
oven-sh/mimalloc
|
oven-sh/mimalloc
|
||||||
COMMIT
|
COMMIT
|
||||||
82b2c2277a4d570187c07b376557dc5bde81d848
|
1beadf9651a7bfdec6b5367c380ecc3fe1c40d1a
|
||||||
)
|
)
|
||||||
|
|
||||||
set(MIMALLOC_CMAKE_ARGS
|
set(MIMALLOC_CMAKE_ARGS
|
||||||
@@ -19,6 +19,10 @@ set(MIMALLOC_CMAKE_ARGS
|
|||||||
-DMI_SKIP_COLLECT_ON_EXIT=ON
|
-DMI_SKIP_COLLECT_ON_EXIT=ON
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(ENABLE_ASAN)
|
||||||
|
list(APPEND MIMALLOC_CMAKE_ARGS -DMI_TRACK_ASAN=ON)
|
||||||
|
endif()
|
||||||
|
|
||||||
if(DEBUG)
|
if(DEBUG)
|
||||||
list(APPEND MIMALLOC_CMAKE_ARGS -DMI_DEBUG_FULL=ON)
|
list(APPEND MIMALLOC_CMAKE_ARGS -DMI_DEBUG_FULL=ON)
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ option(WEBKIT_VERSION "The version of WebKit to use")
|
|||||||
option(WEBKIT_LOCAL "If a local version of WebKit should be used instead of downloading")
|
option(WEBKIT_LOCAL "If a local version of WebKit should be used instead of downloading")
|
||||||
|
|
||||||
if(NOT WEBKIT_VERSION)
|
if(NOT WEBKIT_VERSION)
|
||||||
set(WEBKIT_VERSION e32c6356625cfacebff0c61d182f759abf6f508a)
|
set(WEBKIT_VERSION 851aabf42b06ba583cc0485ff9088e3f84c22f3d)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
string(SUBSTRING ${WEBKIT_VERSION} 0 16 WEBKIT_VERSION_PREFIX)
|
string(SUBSTRING ${WEBKIT_VERSION} 0 16 WEBKIT_VERSION_PREFIX)
|
||||||
@@ -79,6 +79,10 @@ else()
|
|||||||
set(WEBKIT_SUFFIX "${WEBKIT_SUFFIX}")
|
set(WEBKIT_SUFFIX "${WEBKIT_SUFFIX}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(ENABLE_ASAN)
|
||||||
|
set(WEBKIT_SUFFIX "${WEBKIT_SUFFIX}-asan")
|
||||||
|
endif()
|
||||||
|
|
||||||
set(WEBKIT_NAME bun-webkit-${WEBKIT_OS}-${WEBKIT_ARCH}${WEBKIT_SUFFIX})
|
set(WEBKIT_NAME bun-webkit-${WEBKIT_OS}-${WEBKIT_ARCH}${WEBKIT_SUFFIX})
|
||||||
set(WEBKIT_FILENAME ${WEBKIT_NAME}.tar.gz)
|
set(WEBKIT_FILENAME ${WEBKIT_NAME}.tar.gz)
|
||||||
setx(WEBKIT_DOWNLOAD_URL https://github.com/oven-sh/WebKit/releases/download/autobuild-${WEBKIT_VERSION}/${WEBKIT_FILENAME})
|
setx(WEBKIT_DOWNLOAD_URL https://github.com/oven-sh/WebKit/releases/download/autobuild-${WEBKIT_VERSION}/${WEBKIT_FILENAME})
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ else()
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
optionx(ZIG_VERSION STRING "The zig version of the compiler to download" DEFAULT "0.14.0-dev.2987+183bb8b08")
|
optionx(ZIG_VERSION STRING "The zig version of the compiler to download" DEFAULT "0.14.0-dev.2987+183bb8b08")
|
||||||
optionx(ZIG_COMMIT STRING "The zig commit to use in oven-sh/zig" DEFAULT "568a19ea4b811a5580bbf869cdaf6071244b9bb2")
|
optionx(ZIG_COMMIT STRING "The zig commit to use in oven-sh/zig" DEFAULT "63f8ed52c011beafde83216efba766492491ef4b")
|
||||||
optionx(ZIG_TARGET STRING "The zig target to use" DEFAULT ${DEFAULT_ZIG_TARGET})
|
optionx(ZIG_TARGET STRING "The zig target to use" DEFAULT ${DEFAULT_ZIG_TARGET})
|
||||||
|
|
||||||
if(CMAKE_BUILD_TYPE STREQUAL "Release")
|
if(CMAKE_BUILD_TYPE STREQUAL "Release")
|
||||||
@@ -79,6 +79,7 @@ register_command(
|
|||||||
-DZIG_PATH=${ZIG_PATH}
|
-DZIG_PATH=${ZIG_PATH}
|
||||||
-DZIG_VERSION=${ZIG_VERSION}
|
-DZIG_VERSION=${ZIG_VERSION}
|
||||||
-DZIG_COMMIT=${ZIG_COMMIT}
|
-DZIG_COMMIT=${ZIG_COMMIT}
|
||||||
|
-DENABLE_ASAN=${ENABLE_ASAN}
|
||||||
-P ${CWD}/cmake/scripts/DownloadZig.cmake
|
-P ${CWD}/cmake/scripts/DownloadZig.cmake
|
||||||
SOURCES
|
SOURCES
|
||||||
${CWD}/cmake/scripts/DownloadZig.cmake
|
${CWD}/cmake/scripts/DownloadZig.cmake
|
||||||
|
|||||||
@@ -133,10 +133,12 @@
|
|||||||
|
|
||||||
#if OS(DARWIN)
|
#if OS(DARWIN)
|
||||||
#if BUN_DEBUG
|
#if BUN_DEBUG
|
||||||
|
#if !__has_feature(address_sanitizer)
|
||||||
#include <malloc/malloc.h>
|
#include <malloc/malloc.h>
|
||||||
#define IS_MALLOC_DEBUGGING_ENABLED 1
|
#define IS_MALLOC_DEBUGGING_ENABLED 1
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
static WTF::StringView StringView_slice(WTF::StringView sv, unsigned start, unsigned end)
|
static WTF::StringView StringView_slice(WTF::StringView sv, unsigned start, unsigned end)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -50,10 +50,12 @@
|
|||||||
|
|
||||||
#if OS(DARWIN)
|
#if OS(DARWIN)
|
||||||
#if BUN_DEBUG
|
#if BUN_DEBUG
|
||||||
|
#if !__has_feature(address_sanitizer)
|
||||||
#include <malloc/malloc.h>
|
#include <malloc/malloc.h>
|
||||||
#define IS_MALLOC_DEBUGGING_ENABLED 1
|
#define IS_MALLOC_DEBUGGING_ENABLED 1
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
using namespace JSC;
|
using namespace JSC;
|
||||||
using namespace WTF;
|
using namespace WTF;
|
||||||
|
|||||||
Reference in New Issue
Block a user