@@ -2087,6 +2087,7 @@ def phase_linker_setup(options, state, newargs):
20872087 if settings .MAIN_MODULE == 1 :
20882088 settings .INCLUDE_FULL_LIBRARY = 1
20892089 settings .DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += ['$loadDylibs' ]
2090+ settings .REQUIRED_EXPORTS += ['malloc' ]
20902091
20912092 if settings .MAIN_MODULE == 1 or settings .SIDE_MODULE == 1 :
20922093 settings .LINKABLE = 1
@@ -2339,7 +2340,7 @@ def phase_linker_setup(options, state, newargs):
23392340 settings .FETCH_WORKER_FILE = unsuffixed_basename (target ) + '.fetch.js'
23402341
23412342 if settings .DEMANGLE_SUPPORT :
2342- settings .REQUIRED_EXPORTS += ['__cxa_demangle' ]
2343+ settings .REQUIRED_EXPORTS += ['__cxa_demangle' , 'free' ]
23432344 settings .DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += ['$demangle' , '$stackTrace' ]
23442345
23452346 if settings .FULL_ES3 :
@@ -2413,11 +2414,6 @@ def phase_linker_setup(options, state, newargs):
24132414 exit_with_error ('-sPROXY_TO_PTHREAD requires -pthread to work!' )
24142415 settings .JS_LIBRARIES .append ((0 , 'library_pthread_stub.js' ))
24152416
2416- # TODO: Move this into the library JS file once it becomes possible.
2417- # See https://github.com/emscripten-core/emscripten/pull/15982
2418- if settings .INCLUDE_FULL_LIBRARY and not settings .DISABLE_EXCEPTION_CATCHING :
2419- settings .EXPORTED_FUNCTIONS += ['___get_exception_message' , '_free' ]
2420-
24212417 if settings .MEMORY64 :
24222418 if settings .ASYNCIFY and settings .MEMORY64 == 1 :
24232419 exit_with_error ('MEMORY64=1 is not compatible with ASYNCIFY' )
@@ -2760,20 +2756,16 @@ def check_memory_setting(setting):
27602756 # need to be able to call these explicitly.
27612757 settings .REQUIRED_EXPORTS += ['__funcs_on_exit' ]
27622758
2763- # various settings require malloc/free support from JS
2764- if settings .RELOCATABLE or \
2765- settings .BUILD_AS_WORKER or \
2766- settings .USE_WEBGPU or \
2767- settings .OFFSCREENCANVAS_SUPPORT or \
2768- settings .LEGACY_GL_EMULATION or \
2759+ # Some settings require malloc/free to be exported explictly.
2760+ # In most cases, the inclustion of native symbols like malloc and free
2761+ # is taken care of by wasm-ld use its normal symbol resolution process.
2762+ # However, when JS symbols are exported explictly via
2763+ # DEFAULT_LIBRARY_FUNCS_TO_INCLUDE and they depend on native symbols
2764+ # we need to explictly require those exports.
2765+ if settings .BUILD_AS_WORKER or \
27692766 settings .ASYNCIFY or \
27702767 settings .WASMFS or \
2771- settings .DEMANGLE_SUPPORT or \
27722768 settings .FORCE_FILESYSTEM or \
2773- settings .STB_IMAGE or \
2774- settings .EMBIND or \
2775- settings .FETCH or \
2776- settings .PROXY_POSIX_SOCKETS or \
27772769 options .memory_profiler or \
27782770 sanitize :
27792771 settings .REQUIRED_EXPORTS += ['malloc' , 'free' ]
0 commit comments