@@ -49,14 +49,21 @@ endif()
49
49
50
50
option (BUILD_STATIC_LIB "Build as a static library" OFF )
51
51
if (MSVC )
52
- # We don't have dllexport declarations set up for windows yet.
52
+ # We don't have dllexport declarations set up for Windows yet.
53
53
set (BUILD_STATIC_LIB ON )
54
54
endif ()
55
55
56
- # Turn this off to install only tools and not static/dynamic libs
56
+ # Advised to turn on when statically linking against musl libc (e.g., in the
57
+ # Alpine Linux build we use for producing official Linux binaries), because
58
+ # musl libc's allocator has very bad performance on heavily multi-threaded
59
+ # workloads / high core count machines.
60
+ # See https://github.com/WebAssembly/binaryen/issues/5561.
61
+ option (MIMALLOC_STATIC "Build with statically linked mimalloc allocator" OFF )
62
+
63
+ # Turn this off to install only tools and not static/dynamic libs.
57
64
option (INSTALL_LIBS "Install libraries" ON )
58
65
59
- # Turn this on to build only the subset of tools needed for emscripten
66
+ # Turn this on to build only the subset of tools needed for Emscripten.
60
67
option (BUILD_EMSCRIPTEN_TOOLS_ONLY "Build only tools needed by emscripten" OFF )
61
68
62
69
# Turn this on to build binaryen.js as ES5, with additional compatibility configuration for js_of_ocaml.
@@ -345,11 +352,11 @@ if(EMSCRIPTEN)
345
352
# in opt builds, LTO helps so much (>20%) it's worth slow compile times
346
353
add_nondebug_compile_flag ("-flto" )
347
354
endif ()
348
- if (EMSCRIPTEN_ENABLE_WASM64 )
349
- add_compile_flag ("-sMEMORY64 -Wno-experimental" )
350
- add_link_flag ("-sMEMORY64" )
351
- endif ()
355
+ if (EMSCRIPTEN_ENABLE_WASM64 )
356
+ add_compile_flag ("-sMEMORY64 -Wno-experimental" )
357
+ add_link_flag ("-sMEMORY64" )
352
358
endif ()
359
+ endif ()
353
360
354
361
# clang doesn't print colored diagnostics when invoked from Ninja
355
362
if (UNIX AND CMAKE_GENERATOR STREQUAL "Ninja" )
@@ -455,6 +462,14 @@ if(BUILD_LLVM_DWARF)
455
462
target_link_libraries (binaryen llvm_dwarf )
456
463
endif ()
457
464
465
+ if (MIMALLOC_STATIC )
466
+ if (NOT (LINUX AND BUILD_STATIC_LIB ) OR EMSCRIPTEN )
467
+ message (FATAL_ERROR "Statically linking mimalloc is only supported when building as a native, statically linked library on Linux." )
468
+ endif ()
469
+ message (STATUS "Building with statically linked mimalloc allocator." )
470
+ target_link_libraries (binaryen mimalloc-static )
471
+ endif ()
472
+
458
473
add_subdirectory (src/ir )
459
474
add_subdirectory (src/asmjs )
460
475
add_subdirectory (src/cfg )
0 commit comments