Author: Anutosh Bhat Date: 2026-10-07T19:48:22Z New Revision: 70f06c967d7aa78b9c4784174104d0ee506d537c
URL: https://github.com/llvm/llvm-project/commit/70f06c967d7aa78b9c4784174104d0ee506d537c DIFF: https://github.com/llvm/llvm-project/commit/70f06c967d7aa78b9c4784174104d0ee506d537c.diff LOG: [CMake] Honor symbol export lists for Emscripten (#229715) I ran into this while building LLVM 23.1.2 with Emscripten 6.x for emscripten-forge, for both wasm32 and wasm64. Check here : https://github.com/emscripten-forge/recipes/pull/7258 The build completes, but the wasm64 package test fails with: ```text Error: libRemarks.so is not built for architecture wasm64 ``` Looking at the library, it only exports `LLVMRemarkVersion` besides the module constructor. The remaining Remarks APIs are missing because their definitions live in static dependency archives and are never pulled into the shared library. The resulting tiny module is reported as wasm32 even in the wasm64 build. The missing APIs affect wasm32 too; its architecture check just happens to pass. #221647 removes the unsupported ELF version-script flags, but we still need an Emscripten equivalent for those export lists. This patch adds that handling to `add_llvm_symbol_exports`, using `--export` for the listed symbols. It also makes libclang use its existing generic export list on Emscripten. I tested this with Emscripten 6.0.8 on both architectures: rebuilt Remarks, verified all 25 C API exports, and linked and ran a shared-library consumer that parses a YAML remark. I also checked export-list generation for LTO and libclang. Added: Modified: clang/tools/libclang/CMakeLists.txt llvm/cmake/modules/AddLLVM.cmake Removed: ################################################################################ diff --git a/clang/tools/libclang/CMakeLists.txt b/clang/tools/libclang/CMakeLists.txt index 38f577499dd22e..0f78e2913b4ef9 100644 --- a/clang/tools/libclang/CMakeLists.txt +++ b/clang/tools/libclang/CMakeLists.txt @@ -95,7 +95,7 @@ if(MSVC) set(LLVM_EXPORTED_SYMBOL_FILE) endif() -if (UNIX AND NOT APPLE AND NOT "${CMAKE_SYSTEM_NAME}" MATCHES "AIX" AND NOT CYGWIN) +if (UNIX AND NOT APPLE AND NOT "${CMAKE_SYSTEM_NAME}" MATCHES "AIX|Emscripten" AND NOT CYGWIN) set(LLVM_EXPORTED_SYMBOL_FILE) set(USE_VERSION_SCRIPT ${LLVM_HAVE_LINK_VERSION_SCRIPT}) endif() diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake index 3169756c0f28af..8f71a9f9b7086d 100644 --- a/llvm/cmake/modules/AddLLVM.cmake +++ b/llvm/cmake/modules/AddLLVM.cmake @@ -164,6 +164,19 @@ function(add_llvm_symbol_exports target_name export_file) set(native_export_file "${export_file}") set_property(TARGET ${target_name} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,-bE:${export_file}") + elseif(CMAKE_SYSTEM_NAME STREQUAL "Emscripten") + # wasm-ld uses explicit exports, not ELF version scripts. These also + # pull the exported API definitions out of static dependency archives. + set(native_export_file "${target_name}.exports") + add_custom_command(OUTPUT ${native_export_file} + COMMAND sed -e "s/^/-Wl,--export=/" < ${export_file} > ${native_export_file} + DEPENDS ${export_file} + VERBATIM + COMMENT "Creating export file for ${target_name}") + # Forward each response-file entry through the Emscripten driver. + set_property(TARGET ${target_name} APPEND PROPERTY + LINK_OPTIONS "-Wl,--no-export-dynamic" + "@${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}") elseif(LLVM_HAVE_LINK_VERSION_SCRIPT) # Gold and BFD ld require a version script rather than a plain list. set(native_export_file "${target_name}.exports") _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
