From c71d2df9ba4db90a2269f7f6bdc0e8db69773861 Mon Sep 17 00:00:00 2001 From: Derek Schuff Date: Thu, 15 Jan 2026 22:03:49 +0000 Subject: [PATCH 1/2] Link mimalloc with --as-needed on Linux The mimalloc CMake code unconditionally adds libatomic to its link dependencies, but it's not actually needed on the modern systems that we're building for. Adding the --as-needed flag causes the linker to only link against the following libraries if they provide symbols that are actually needed. For static linking, we wrap mimalloc's injected dependencies in -Wl,--as-needed since they surface all the way up to the final link line for each tool (I don't think it would hurt to just link all the tools with --as-needed but this seemed cleaner). For dynamic linking, it's sufficient to just make the libmimalloc.so link with --as-needed. --- CMakeLists.txt | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6b4cf08524d..1b2c617cbdc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -478,9 +478,9 @@ else() add_link_flag("-Bsymbolic") endif() endif() -target_link_libraries(binaryen Threads::Threads) +target_link_libraries(binaryen PUBLIC Threads::Threads) if(BUILD_LLVM_DWARF) - target_link_libraries(binaryen llvm_dwarf) + target_link_libraries(binaryen PRIVATE llvm_dwarf) endif() if(BUILD_MIMALLOC) @@ -489,9 +489,12 @@ if(BUILD_MIMALLOC) endif() message(STATUS "Building with mimalloc allocator.") if(BUILD_STATIC_LIB) - target_link_libraries(binaryen mimalloc-static) + target_link_libraries(binaryen PRIVATE "-Wl,--push-state,--as-needed") + target_link_libraries(binaryen PRIVATE mimalloc-static) + target_link_libraries(binaryen PRIVATE "-Wl,--pop-state") else() - target_link_libraries(binaryen mimalloc) + target_link_options(mimalloc PRIVATE "-Wl,--as-needed") + target_link_libraries(binaryen PRIVATE mimalloc) endif() endif() From 5b75f78f5a3e5bf643012b51608f5ce2c171863a Mon Sep 17 00:00:00 2001 From: Derek Schuff Date: Fri, 16 Jan 2026 17:22:30 +0000 Subject: [PATCH 2/2] setup rpath for libbinaryen --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b2c617cbdc..1f1d97ae046 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -479,6 +479,7 @@ else() endif() endif() target_link_libraries(binaryen PUBLIC Threads::Threads) +binaryen_setup_rpath(binaryen) if(BUILD_LLVM_DWARF) target_link_libraries(binaryen PRIVATE llvm_dwarf) endif()