https://github.com/anutosh491 created 
https://github.com/llvm/llvm-project/pull/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-if-defined` 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.

>From 9d1a14f3bdc241b200cb485569582886955b0338 Mon Sep 17 00:00:00 2001
From: anutosh491 <[email protected]>
Date: Wed, 7 Oct 2026 15:38:55 +0530
Subject: [PATCH] [CMake] Honor symbol export lists for Emscripten

---
 clang/tools/libclang/CMakeLists.txt |  2 +-
 llvm/cmake/modules/AddLLVM.cmake    | 15 +++++++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)

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..d08204ec962982 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -164,6 +164,21 @@ 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 "${Python3_EXECUTABLE}" "-c"
+      "import sys;print(''.join('-Wl,--export-if-defined=' + l.strip() + '\\n' 
for l in sys.stdin if l.strip()), end='')"
+      < ${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

Reply via email to