Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined symbol _emscripten_memcpy_js when linking rust code with -lc -Oz #22742

Open
hoodmane opened this issue Oct 15, 2024 · 4 comments · May be fixed by #22765
Open

Undefined symbol _emscripten_memcpy_js when linking rust code with -lc -Oz #22742

hoodmane opened this issue Oct 15, 2024 · 4 comments · May be fixed by #22765

Comments

@hoodmane
Copy link
Contributor

hoodmane commented Oct 15, 2024

You need rust and the emscripten target installed. rustup target add wasm32-unknown-emscripten installs the emscripten target if you use rustup.

echo "fn main(){}" > a.rs
rustc -Copt-level=z a.rs -o a.js --target=wasm32-unknown-emscripten

Fails with:

          error: undefined symbol: _emscripten_memcpy_js (referenced by root reference (e.g. compiled C/C++ code))
          warning: To disable errors for undefined symbols use `-sERROR_ON_UNDEFINED_SYMBOLS=0`
          warning: __emscripten_memcpy_js may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
          Error: Aborting compilation due to previous errors
          emcc: error: '/home/rchatham/Documents/programming/emsdk/node/18.20.3_64bit/bin/node /home/rchatham/Documents/programming/emsdk/upstream/emscripten/src/compiler.mjs /tmp/tmpogw1glcz.json' failed (returned 1)          

If we minimize the failing emcc link command, it looks like:

emcc -o a.js -Oz -lc \
a.a.<some-hash>-cgu.0.rcgu.o \
a.<some-hash>.rcgu.o \
.../lib/rustlib/wasm32-unknown-emscripten/lib/libstd-1d3ccab4f7990fa9.rlib \
.../lib/rustlib/wasm32-unknown-emscripten/lib/libpanic_abort-bb30bbb88530dc79.rlib \
.../lib/rustlib/wasm32-unknown-emscripten/lib/liballoc-6b694a8bc75de25c.rlib \
.../lib/rustlib/wasm32-unknown-emscripten/lib/libcore-99daaba8bfbbfe7e.rlib \

If I remove either -Oz or -lc then it succeeds. If I pass EMCC_DEBUG=1 and look at the contents of tmpogw1glcz.json it looks like:

Details

{
"ABORTING_MALLOC": true,
"ABORT_ON_WASM_EXCEPTIONS": false,
"AGGRESSIVE_VARIABLE_ELIMINATION": 0,
"ALIASING_FUNCTION_POINTERS": 0,
"ALLOW_BLOCKING_ON_MAIN_THREAD": true,
"ALLOW_MEMORY_GROWTH": false,
"ALLOW_TABLE_GROWTH": false,
"ALLOW_UNIMPLEMENTED_SYSCALLS": true,
"ALL_INCOMING_MODULE_JS_API": [
"ENVIRONMENT",
"GL_MAX_TEXTURE_IMAGE_UNITS",
"SDL_canPlayWithWebAudio",
"SDL_numSimultaneouslyQueuedBuffers",
"INITIAL_MEMORY",
"wasmMemory",
"arguments",
"buffer",
"canvas",
"doNotCaptureKeyboard",
"dynamicLibraries",
"elementPointerLock",
"extraStackTrace",
"forcedAspectRatio",
"instantiateWasm",
"keyboardListeningElement",
"freePreloadedMediaOnUse",
"loadSplitModule",
"locateFile",
"logReadFiles",
"mainScriptUrlOrBlob",
"mem",
"monitorRunDependencies",
"noExitRuntime",
"noInitialRun",
"onAbort",
"onCustomMessage",
"onExit",
"onFree",
"onFullScreen",
"onMalloc",
"onRealloc",
"onRuntimeInitialized",
"postMainLoop",
"postRun",
"preInit",
"preMainLoop",
"preRun",
"preinitializedWebGLContext",
"preloadPlugins",
"print",
"printErr",
"setStatus",
"statusMessage",
"stderr",
"stdin",
"stdout",
"thisProgram",
"wasm",
"wasmBinary",
"websocket",
"fetchSettings"
],
"ASAN_SHADOW_SIZE": -1,
"ASM_JS": 1,
"ASM_PRIMITIVE_VARS": [],
"ASSERTIONS": 0,
"ASYNCIFY": 0,
"ASYNCIFY_ADD": [],
"ASYNCIFY_ADVISE": false,
"ASYNCIFY_BLACKLIST": [],
"ASYNCIFY_DEBUG": 0,
"ASYNCIFY_EXPORTS": [],
"ASYNCIFY_IGNORE_INDIRECT": false,
"ASYNCIFY_IMPORTS": [],
"ASYNCIFY_IMPORTS_EXCEPT_JS_LIBS": [],
"ASYNCIFY_LAZY_LOAD_CODE": false,
"ASYNCIFY_ONLY": [],
"ASYNCIFY_PROPAGATE_ADD": true,
"ASYNCIFY_REMOVE": [],
"ASYNCIFY_STACK_SIZE": 4096,
"ASYNCIFY_WHITELIST": [],
"AUDIO_WORKLET": 0,
"AUDIO_WORKLET_FILE": "",
"AUTODEBUG": false,
"AUTOLOAD_DYLIBS": true,
"AUTO_ARCHIVE_INDEXES": 0,
"AUTO_JS_LIBRARIES": true,
"AUTO_NATIVE_LIBRARIES": true,
"BINARYEN": 1,
"BINARYEN_ASYNC_COMPILATION": true,
"BINARYEN_EXTRA_PASSES": "",
"BINARYEN_FEATURES": [
"--mvp-features",
"--enable-multivalue",
"--enable-mutable-globals",
"--enable-reference-types",
"--enable-sign-ext"
],
"BINARYEN_IGNORE_IMPLICIT_TRAPS": false,
"BINARYEN_MEM_MAX": 2147483648,
"BINARYEN_METHOD": "native-wasm",
"BINARYEN_PASSES": "",
"BINARYEN_SCRIPTS": "",
"BINARYEN_TRAP_MODE": -1,
"BOOTSTRAPPING_STRUCT_INFO": false,
"BUILD_AS_SHARED_LIB": 0,
"BUILD_AS_WORKER": false,
"BULK_MEMORY": false,
"CAN_ADDRESS_2GB": false,
"CASE_INSENSITIVE_FS": false,
"CHECK_NULL_WRITES": true,
"CLOSURE_WARNINGS": "quiet",
"DEAD_FUNCTIONS": [],
"DEBUG_LEVEL": 0,
"DECLARE_ASM_MODULE_EXPORTS": true,
"DEFAULT_LIBRARY_FUNCS_TO_INCLUDE": [
"$ExitStatus",
"$callRuntimeCallbacks",
"$getValue",
"$noExitRuntime",
"$setValue",
"$stackRestore",
"$stackSave",
"__cxa_find_matching_catch_2",
"__cxa_find_matching_catch_4",
"__resumeException",
"__syscall_getcwd",
"_abort_js",
"_emscripten_memcpy_js",
"emscripten_resize_heap",
"environ_get",
"environ_sizes_get",
"fd_write",
"llvm_eh_typeid_for",
"$exitJS",
"$handleException",
"$stringToUTF8OnStack",
"$getWasmTableEntry"
],
"DEFAULT_PTHREAD_STACK_SIZE": 0,
"DEFAULT_TO_CXX": true,
"DEMANGLE_SUPPORT": false,
"DETERMINISTIC": false,
"DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR": true,
"DISABLE_EXCEPTION_CATCHING": 1,
"DISABLE_EXCEPTION_THROWING": false,
"DOUBLE_MODE": 0,
"DYLINK_DEBUG": 0,
"DYNAMIC_EXECUTION": 1,
"DYNCALLS": false,
"ELIMINATE_DUPLICATE_FUNCTIONS": 0,
"ELIMINATE_DUPLICATE_FUNCTIONS_DUMP_EQUIVALENT_FUNCTIONS": 0,
"ELIMINATE_DUPLICATE_FUNCTIONS_PASSES": 5,
"EMBIND": false,
"EMBIND_AOT": false,
"EMBIND_STD_STRING_IS_UTF8": true,
"EMITTING_JS": 1,
"EMIT_EMSCRIPTEN_LICENSE": false,
"EMIT_EMSCRIPTEN_METADATA": 0,
"EMIT_NAME_SECTION": false,
"EMIT_PRODUCERS_SECTION": false,
"EMIT_SYMBOL_MAP": false,
"EMIT_TSD": false,
"EMSCRIPTEN_TRACING": false,
"EMSCRIPTEN_VERSION": "3.1.68",
"EMULATE_FUNCTION_POINTER_CASTS": false,
"ENVIRONMENT": "web,webview,worker,node",
"ENVIRONMENT_MAY_BE_NODE": true,
"ENVIRONMENT_MAY_BE_SHELL": false,
"ENVIRONMENT_MAY_BE_WEB": true,
"ENVIRONMENT_MAY_BE_WEBVIEW": true,
"ENVIRONMENT_MAY_BE_WORKER": true,
"ERROR_ON_MISSING_LIBRARIES": 1,
"ERROR_ON_UNDEFINED_SYMBOLS": true,
"ERROR_ON_WASM_CHANGES_AFTER_LINK": false,
"EVAL_CTORS": 0,
"EXCEPTION_CATCHING_ALLOWED": [],
"EXCEPTION_CATCHING_WHITELIST": [],
"EXCEPTION_DEBUG": false,
"EXCEPTION_STACK_TRACES": false,
"EXIT_RUNTIME": false,
"EXPECT_MAIN": true,
"EXPORTED_FUNCTIONS": [
"_memory",
"___indirect_function_table",
"_main"
],
"EXPORTED_RUNTIME_METHODS": [
"HEAPF32",
"HEAPF64",
"HEAP_DATA_VIEW",
"HEAP8",
"HEAPU8",
"HEAP16",
"HEAPU16",
"HEAP32",
"HEAPU32",
"HEAP64",
"HEAPU64"
],
"EXPORT_ALL": false,
"EXPORT_BINDINGS": 0,
"EXPORT_ES6": false,
"EXPORT_EXCEPTION_HANDLING_HELPERS": false,
"EXPORT_FUNCTION_TABLES": 0,
"EXPORT_IF_DEFINED": [
"__start_em_asm",
"__stop_em_asm",
"__start_em_lib_deps",
"__stop_em_lib_deps",
"__start_em_js",
"__stop_em_js",
"main",
"__main_argc_argv"
],
"EXPORT_KEEPALIVE": true,
"EXPORT_NAME": "Module",
"EXTRA_EXPORTED_RUNTIME_METHODS": [],
"FAST_UNROLLED_MEMCPY_AND_MEMSET": 0,
"FETCH": false,
"FETCH_DEBUG": false,
"FETCH_SUPPORT_INDEXEDDB": true,
"FILESYSTEM": true,
"FINALIZE_ASM_JS": 0,
"FORCE_ALIGNED_MEMORY": 0,
"FORCE_FILESYSTEM": false,
"FS_DEBUG": false,
"FULL_ES2": false,
"FULL_ES3": false,
"FUNCTION_POINTER_ALIGNMENT": 2,
"GENERATE_DWARF": false,
"GENERATE_SOURCE_MAP": false,
"GLOBAL_BASE": 1024,
"GL_ASSERTIONS": false,
"GL_DEBUG": false,
"GL_DISABLE_HALF_FLOAT_EXTENSION_IF_BROKEN": false,
"GL_EMULATE_GLES_VERSION_STRING_FORMAT": true,
"GL_ENABLE_GET_PROC_ADDRESS": true,
"GL_EXPLICIT_UNIFORM_BINDING": false,
"GL_EXPLICIT_UNIFORM_LOCATION": false,
"GL_EXTENSIONS_IN_PREFIXED_FORMAT": true,
"GL_FFP_ONLY": false,
"GL_MAX_TEMP_BUFFER_SIZE": 2097152,
"GL_POOL_TEMP_BUFFERS": true,
"GL_PREINITIALIZED_CONTEXT": false,
"GL_SUPPORT_AUTOMATIC_ENABLE_EXTENSIONS": true,
"GL_SUPPORT_EXPLICIT_SWAP_CONTROL": false,
"GL_SUPPORT_SIMPLE_ENABLE_EXTENSIONS": true,
"GL_TESTING": false,
"GL_TRACK_ERRORS": true,
"GL_UNSAFE_OPTS": true,
"GL_WORKAROUND_SAFARI_GETCONTEXT_BUG": true,
"HAS_MAIN": true,
"HAVE_EM_ASM": false,
"HEADLESS": false,
"HEAP_BASE": 0,
"HTML5_SUPPORT_DEFERRING_USER_SENSITIVE_REQUESTS": true,
"IGNORE_CLOSURE_COMPILER_ERRORS": false,
"IGNORE_MISSING_MAIN": true,
"IMPORTED_MEMORY": false,
"INCLUDE_FULL_LIBRARY": false,
"INCLUDE_WEBGL1_FALLBACK": true,
"INCOMING_MODULE_JS_API": [
"ENVIRONMENT",
"GL_MAX_TEXTURE_IMAGE_UNITS",
"SDL_canPlayWithWebAudio",
"SDL_numSimultaneouslyQueuedBuffers",
"INITIAL_MEMORY",
"wasmMemory",
"arguments",
"buffer",
"canvas",
"doNotCaptureKeyboard",
"dynamicLibraries",
"elementPointerLock",
"extraStackTrace",
"forcedAspectRatio",
"instantiateWasm",
"keyboardListeningElement",
"freePreloadedMediaOnUse",
"loadSplitModule",
"locateFile",
"logReadFiles",
"mainScriptUrlOrBlob",
"mem",
"monitorRunDependencies",
"noExitRuntime",
"noInitialRun",
"onAbort",
"onCustomMessage",
"onExit",
"onFree",
"onFullScreen",
"onMalloc",
"onRealloc",
"onRuntimeInitialized",
"postMainLoop",
"postRun",
"preInit",
"preMainLoop",
"preRun",
"preinitializedWebGLContext",
"preloadPlugins",
"print",
"printErr",
"setStatus",
"statusMessage",
"stderr",
"stdin",
"stdout",
"thisProgram",
"wasm",
"wasmBinary",
"websocket"
],
"INITIAL_HEAP": 16777216,
"INITIAL_MEMORY": -1,
"INITIAL_TABLE": -1,
"INLINING_LIMIT": false,
"INVOKE_RUN": true,
"JSPI": 0,
"JSPI_EXPORTS": [],
"JSPI_IMPORTS": [],
"JS_LIBRARIES": [
"library_pthread_stub.js"
],
"JS_MATH": false,
"LEGACY_GL_EMULATION": false,
"LEGACY_RUNTIME": false,
"LEGACY_SETTINGS": [
"BINARYEN",
"TOTAL_STACK",
"BINARYEN_ASYNC_COMPILATION",
"UNALIGNED_MEMORY",
"FORCE_ALIGNED_MEMORY",
"PGO",
"QUANTUM_SIZE",
"FUNCTION_POINTER_ALIGNMENT",
"RESERVED_FUNCTION_POINTERS",
"BUILD_AS_SHARED_LIB",
"SAFE_SPLIT_MEMORY",
"SPLIT_MEMORY",
"BINARYEN_METHOD",
"BINARYEN_TRAP_MODE",
"PRECISE_I64_MATH",
"MEMFS_APPEND_TO_TYPED_ARRAYS",
"ERROR_ON_MISSING_LIBRARIES",
"EMITTING_JS",
"SKIP_STACK_IN_SMALL",
"SAFE_STACK",
"MEMORY_GROWTH_STEP",
"ELIMINATE_DUPLICATE_FUNCTIONS",
"ELIMINATE_DUPLICATE_FUNCTIONS_DUMP_EQUIVALENT_FUNCTIONS",
"ELIMINATE_DUPLICATE_FUNCTIONS_PASSES",
"WASM_OBJECT_FILES",
"TOTAL_MEMORY",
"WASM_MEM_MAX",
"BINARYEN_MEM_MAX",
"BINARYEN_PASSES",
"SWAPPABLE_ASM_MODULE",
"ASM_JS",
"FINALIZE_ASM_JS",
"ASYNCIFY_WHITELIST",
"ASYNCIFY_BLACKLIST",
"EXCEPTION_CATCHING_WHITELIST",
"SEPARATE_ASM",
"SEPARATE_ASM_MODULE_NAME",
"FAST_UNROLLED_MEMCPY_AND_MEMSET",
"DOUBLE_MODE",
"PRECISE_F32",
"ALIASING_FUNCTION_POINTERS",
"AGGRESSIVE_VARIABLE_ELIMINATION",
"SIMPLIFY_IFS",
"DEAD_FUNCTIONS",
"WASM_BACKEND",
"EXPORT_BINDINGS",
"RUNNING_JS_OPTS",
"EXPORT_FUNCTION_TABLES",
"BINARYEN_SCRIPTS",
"WARN_UNALIGNED",
"ASM_PRIMITIVE_VARS",
"WORKAROUND_IOS_9_RIGHT_SHIFT_BUG",
"RUNTIME_FUNCS_TO_IMPORT",
"LIBRARY_DEPS_TO_AUTOEXPORT",
"EMIT_EMSCRIPTEN_METADATA",
"SHELL_FILE",
"LLD_REPORT_UNDEFINED",
"MEM_INIT_METHOD",
"USE_PTHREADS",
"USES_DYNAMIC_ALLOC",
"REVERSE_DEPS",
"RUNTIME_LOGGING",
"MIN_EDGE_VERSION",
"MIN_IE_VERSION",
"WORKAROUND_OLD_WEBGL_UNIFORM_UPLOAD_IGNORED_OFFSET_BUG",
"AUTO_ARCHIVE_INDEXES"
],
"LEGACY_VM_SUPPORT": false,
"LEGALIZE_JS_FFI": true,
"LIBRARY_DEBUG": false,
"LIBRARY_DEPS_TO_AUTOEXPORT": [],
"LINKABLE": false,
"LINK_AS_CXX": true,
"LLD_REPORT_UNDEFINED": 1,
"LOAD_SOURCE_MAP": false,
"LTO": 0,
"LZ4": false,
"MAIN_MODULE": 0,
"MAIN_READS_PARAMS": true,
"MALLOC": "dlmalloc",
"MAXIMUM_MEMORY": 2147483648,
"MAX_WEBGL_VERSION": 1,
"MAYBE_CLOSURE_COMPILER": false,
"MAYBE_WASM2JS": false,
"MEMFS_APPEND_TO_TYPED_ARRAYS": 1,
"MEMORY64": 0,
"MEMORYPROFILER": false,
"MEMORY_GROWTH_GEOMETRIC_CAP": 100663296,
"MEMORY_GROWTH_GEOMETRIC_STEP": 0.2,
"MEMORY_GROWTH_LINEAR_STEP": -1,
"MEMORY_GROWTH_STEP": -1,
"MEM_INIT_METHOD": 0,
"MINIFICATION_MAP": "",
"MINIFY_HTML": true,
"MINIFY_WASM_EXPORT_NAMES": true,
"MINIFY_WASM_IMPORTED_MODULES": 1,
"MINIFY_WASM_IMPORTS_AND_EXPORTS": 1,
"MINIFY_WHITESPACE": true,
"MINIMAL_RUNTIME": 0,
"MINIMAL_RUNTIME_STREAMING_WASM_COMPILATION": false,
"MINIMAL_RUNTIME_STREAMING_WASM_INSTANTIATION": false,
"MIN_CHROME_VERSION": 85,
"MIN_EDGE_VERSION": 2147483647,
"MIN_FIREFOX_VERSION": 79,
"MIN_IE_VERSION": 2147483647,
"MIN_NODE_VERSION": 160000,
"MIN_SAFARI_VERSION": 140100,
"MIN_WEBGL_VERSION": 1,
"MODULARIZE": false,
"NODEJS_CATCH_EXIT": false,
"NODEJS_CATCH_REJECTION": 0,
"NODERAWFS": false,
"NODE_CODE_CACHING": false,
"OFFSCREENCANVASES_TO_PTHREAD": "#canvas",
"OFFSCREENCANVAS_SUPPORT": false,
"OFFSCREEN_FRAMEBUFFER": false,
"OFFSCREEN_FRAMEBUFFER_FORBID_VAO_PATH": false,
"OPENAL_DEBUG": false,
"OPT_LEVEL": 2,
"PGO": 0,
"POLYFILL": true,
"POLYFILL_OLD_MATH_FUNCTIONS": 0,
"POST_JS_FILES": [],
"PRECISE_F32": 0,
"PRECISE_I64_MATH": 1,
"PRE_JS_FILES": [],
"PRINTF_LONG_DOUBLE": false,
"PROXY_POSIX_SOCKETS": false,
"PROXY_TO_PTHREAD": false,
"PROXY_TO_WORKER": false,
"PROXY_TO_WORKER_FILENAME": "",
"PTHREADS": false,
"PTHREADS_DEBUG": false,
"PTHREADS_PROFILING": false,
"PTHREAD_POOL_DELAY_LOAD": false,
"PTHREAD_POOL_SIZE": 0,
"PTHREAD_POOL_SIZE_STRICT": 1,
"PURE_WASI": false,
"QUANTUM_SIZE": 4,
"RELOCATABLE": false,
"REQUIRED_EXPORTS": [
"_emscripten_stack_alloc",
"__get_temp_ret",
"__set_temp_ret",
"__wasm_call_ctors",
"emscripten_stack_get_current",
"_emscripten_stack_restore"
],
"RESERVED_FUNCTION_POINTERS": false,
"RETAIN_COMPILER_SETTINGS": false,
"REVERSE_DEPS": "auto",
"RUNNING_JS_OPTS": 0,
"RUNTIME_DEBUG": false,
"RUNTIME_FUNCS_TO_IMPORT": [],
"RUNTIME_LINKED_LIBS": [],
"RUNTIME_LOGGING": false,
"SAFE_HEAP": 0,
"SAFE_HEAP_LOG": false,
"SAFE_SPLIT_MEMORY": 0,
"SAFE_STACK": 0,
"SDL2_IMAGE_FORMATS": [],
"SDL2_MIXER_FORMATS": [
"ogg"
],
"SEPARATE_ASM": 0,
"SEPARATE_ASM_MODULE_NAME": "",
"SEPARATE_DWARF": false,
"SEPARATE_DWARF_URL": "",
"SHARED_MEMORY": false,
"SHELL_FILE": "",
"SHRINK_LEVEL": 2,
"SIDE_MODULE": 0,
"SIDE_MODULE_EXPORTS": [],
"SIGNATURE_CONVERSIONS": [],
"SIMPLIFY_IFS": 1,
"SINGLE_FILE": false,
"SKIP_STACK_IN_SMALL": 0,
"SMALL_XHR_CHUNKS": false,
"SOCKET_DEBUG": false,
"SOCKET_WEBRTC": false,
"SOURCE_MAP_BASE": "",
"SPLIT_MEMORY": 0,
"SPLIT_MODULE": false,
"STACK_FIRST": false,
"STACK_HIGH": 0,
"STACK_LOW": 0,
"STACK_OVERFLOW_CHECK": 0,
"STACK_SIZE": 65536,
"STANDALONE_WASM": false,
"STB_IMAGE": false,
"STRICT": false,
"STRICT_JS": false,
"SUPPORTS_GLOBALTHIS": true,
"SUPPORTS_PROMISE_ANY": true,
"SUPPORT_BASE64_EMBEDDING": false,
"SUPPORT_BIG_ENDIAN": false,
"SUPPORT_ERRNO": true,
"SUPPORT_LONGJMP": "emscripten",
"SWAPPABLE_ASM_MODULE": 0,
"SYSCALLS_REQUIRE_FILESYSTEM": true,
"SYSCALL_DEBUG": false,
"TABLE_BASE": 1,
"TARGET_BASENAME": "a",
"TARGET_JS_NAME": "a.js",
"TEXTDECODER": 1,
"TOTAL_MEMORY": -1,
"TOTAL_STACK": 65536,
"TRACE_WEBGL_CALLS": false,
"TRANSPILE": false,
"TRUSTED_TYPES": false,
"UBSAN_RUNTIME": 0,
"UNALIGNED_MEMORY": 0,
"USER_EXPORTS": [],
"USES_DYNAMIC_ALLOC": 1,
"USE_ASAN": false,
"USE_BOOST_HEADERS": false,
"USE_BULLET": false,
"USE_BZIP2": false,
"USE_CLOSURE_COMPILER": false,
"USE_COCOS2D": 0,
"USE_ES6_IMPORT_META": true,
"USE_FREETYPE": false,
"USE_GIFLIB": false,
"USE_GLFW": 0,
"USE_HARFBUZZ": false,
"USE_ICU": false,
"USE_LIBJPEG": false,
"USE_LIBPNG": false,
"USE_LSAN": false,
"USE_MODPLUG": false,
"USE_MPG123": false,
"USE_OFFSET_CONVERTER": false,
"USE_OGG": false,
"USE_PTHREADS": 0,
"USE_READY_PROMISE": true,
"USE_REGAL": false,
"USE_RTTI": true,
"USE_SDL": 0,
"USE_SDL_GFX": 0,
"USE_SDL_IMAGE": 1,
"USE_SDL_MIXER": 1,
"USE_SDL_NET": 1,
"USE_SDL_TTF": 1,
"USE_SQLITE3": false,
"USE_VORBIS": false,
"USE_WEBGL2": false,
"USE_WEBGPU": false,
"USE_ZLIB": false,
"VERBOSE": false,
"WARN_DEPRECATED": true,
"WARN_ON_UNDEFINED_SYMBOLS": true,
"WARN_UNALIGNED": 0,
"WASI_MODULE_NAME": "wasi_snapshot_preview1",
"WASM": 1,
"WASM2JS": false,
"WASMFS": false,
"WASM_ASYNC_COMPILATION": true,
"WASM_BACKEND": -1,
"WASM_BIGINT": false,
"WASM_BINARY_FILE": "a.wasm",
"WASM_EXCEPTIONS": false,
"WASM_EXNREF": false,
"WASM_EXPORTS": [
"memory",
"__wasm_call_ctors",
"main",
"__indirect_function_table",
"malloc",
"htonl",
"htons",
"ntohs",
"_emscripten_tempret_set",
"_emscripten_stack_restore",
"_emscripten_stack_alloc",
"emscripten_stack_get_current",
"__cxa_can_catch"
],
"WASM_GLOBAL_EXPORTS": [],
"WASM_MEM_MAX": 2147483648,
"WASM_OBJECT_FILES": 0,
"WASM_WORKERS": 0,
"WASM_WORKER_FILE": "",
"WEAK_IMPORTS": [],
"WEBAUDIO_DEBUG": 0,
"WEBGL2_BACKWARDS_COMPATIBILITY_EMULATION": false,
"WEBGL_USE_GARBAGE_FREE_APIS": false,
"WEBSOCKET_DEBUG": false,
"WEBSOCKET_SUBPROTOCOL": "binary",
"WEBSOCKET_URL": "ws:#",
"WORKAROUND_IOS_9_RIGHT_SHIFT_BUG": 0,
"WORKAROUND_OLD_WEBGL_UNIFORM_UPLOAD_IGNORED_OFFSET_BUG": 0
}

If I delete _emscripten_memcpy_js from DEFAULT_LIBRARY_FUNCS_TO_INCLUDE then compiler.mjs succeeds.

Version of emscripten/emsdk:

emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.68 (ceee49d2ecdab36a3feb85a684f8e5a453dde910)
clang version 20.0.0git (https:/github.com/llvm/llvm-project 5cc64bf60bc04b9315de3c679eb753de4d554a8a)
Target: wasm32-unknown-emscripten
Thread model: posix
@sbc100
Copy link
Collaborator

sbc100 commented Oct 15, 2024

_emscripten_memcpy_js is just a normal JS library function. I lives here:

emscripten/src/library.js

Lines 409 to 439 in 1dfe990

// In -Oz builds, we replace memcpy() altogether with a non-unrolled wasm
// variant, so we should never emit _emscripten_memcpy_js() in the build.
// In STANDALONE_WASM we avoid the _emscripten_memcpy_js dependency so keep
// the wasm file standalone.
// In BULK_MEMORY mode we include native versions of these functions based
// on memory.fill and memory.copy.
// In MAIN_MODULE=1 or EMCC_FORCE_STDLIBS mode all of libc is force included
// so we cannot override parts of it, and therefore cannot use libc_optz.
#if (SHRINK_LEVEL < 2 || LINKABLE || process.env.EMCC_FORCE_STDLIBS) && !STANDALONE_WASM && !BULK_MEMORY
#if MIN_CHROME_VERSION < 45 || MIN_FIREFOX_VERSION < 34 || MIN_SAFARI_VERSION < 100101
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin lists browsers that support TypedArray.prototype.copyWithin, but it
// has outdated information for Safari, saying it would not support it.
// https://github.com/WebKit/webkit/commit/24a800eea4d82d6d595cdfec69d0f68e733b5c52#diff-c484911d8df319ba75fce0d8e7296333R1 suggests support was added on Aug 28, 2015.
// Manual testing suggests:
// Safari/601.1 Version/9.0 on iPhone 4s with iOS 9.3.6 (released September 30, 2015) does not support copyWithin.
// but the following systems do:
// AppleWebKit/602.2.14 Safari/602.1 Version/10.0 Mobile/14B100 iPhone OS 10_1_1 on iPhone 5s with iOS 10.1.1 (released October 31, 2016)
// AppleWebKit/603.3.8 Safari/602.1 Version/10.0 on iPhone 5 with iOS 10.3.4 (released July 22, 2019)
// AppleWebKit/605.1.15 iPhone OS 12_3_1 Version/12.1.1 Safari/604.1 on iPhone SE with iOS 12.3.1
// AppleWebKit/605.1.15 Safari/604.1 Version/13.0.4 iPhone OS 13_3 on iPhone 6s with iOS 13.3
// AppleWebKit/605.1.15 Version/13.0.3 Intel Mac OS X 10_15_1 on Safari 13.0.3 (15608.3.10.1.4) on macOS Catalina 10.15.1
// Hence the support status of .copyWithin() for Safari version range [10.0.0, 10.1.0] is unknown.
_emscripten_memcpy_js: `= Uint8Array.prototype.copyWithin
? (dest, src, num) => HEAPU8.copyWithin(dest, src, src + num)
: (dest, src, num) => HEAPU8.set(HEAPU8.subarray(src, src+num), dest)`,
#else
_emscripten_memcpy_js: (dest, src, num) => HEAPU8.copyWithin(dest, src, src + num),
#endif
#endif

Does your version of library JS also contains this symbol?

@hoodmane
Copy link
Contributor Author

hoodmane commented Oct 16, 2024

Yeah library.js has _emscripten_memcpy_js. I am using stock emscripten 3.1.68 installed with emsdk. The following is a full reproduction:

git clone https://github.com/emscripten-core/emsdk.git
./emsdk/emsdk install 3.1.68
./emsdk/emsdk activate 3.1.68
source ./emsdk/emsdk_env.sh
# install rustup
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source $HOME/.cargo/env
rustup target add wasm32-unknown-emscripten
echo "fn main(){}" > a.rs
rustc -Copt-level=z a.rs -o a.js --target=wasm32-unknown-emscripten

@hoodmane
Copy link
Contributor Author

I've attached the output from --reproduce=repro.tar
repro.tar.gz

@hoodmane
Copy link
Contributor Author

This also happens with -lc -sWASM_BIGINT.

hoodmane added a commit to hoodmane/emscripten that referenced this issue Oct 18, 2024
There have been a lot of bugs when the caller passes `-lc` over the years. For
example it crashes if we do:
```
emcc -lc -sDISABLE_EXCEPTION_CATCHING=0 -sMIN_SAFARI_VERSION=150000
```

Rust likes to pass `-lc`. Let's drop it and stop causing trouble for Rust.

Resolves emscripten-core#22758, emscripten-core#22742 and would have resolved emscripten-core#16680 if it hadn't disappeared
first.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants