@@ -2087,6 +2087,7 @@ def phase_linker_setup(options, state, newargs):
2087
2087
if settings .MAIN_MODULE == 1 :
2088
2088
settings .INCLUDE_FULL_LIBRARY = 1
2089
2089
settings .DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += ['$loadDylibs' ]
2090
+ settings .REQUIRED_EXPORTS += ['malloc' ]
2090
2091
2091
2092
if settings .MAIN_MODULE == 1 or settings .SIDE_MODULE == 1 :
2092
2093
settings .LINKABLE = 1
@@ -2339,7 +2340,7 @@ def phase_linker_setup(options, state, newargs):
2339
2340
settings .FETCH_WORKER_FILE = unsuffixed_basename (target ) + '.fetch.js'
2340
2341
2341
2342
if settings .DEMANGLE_SUPPORT :
2342
- settings .REQUIRED_EXPORTS += ['__cxa_demangle' ]
2343
+ settings .REQUIRED_EXPORTS += ['__cxa_demangle' , 'free' ]
2343
2344
settings .DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += ['$demangle' , '$stackTrace' ]
2344
2345
2345
2346
if settings .FULL_ES3 :
@@ -2413,11 +2414,6 @@ def phase_linker_setup(options, state, newargs):
2413
2414
exit_with_error ('-sPROXY_TO_PTHREAD requires -pthread to work!' )
2414
2415
settings .JS_LIBRARIES .append ((0 , 'library_pthread_stub.js' ))
2415
2416
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
-
2421
2417
if settings .MEMORY64 :
2422
2418
if settings .ASYNCIFY and settings .MEMORY64 == 1 :
2423
2419
exit_with_error ('MEMORY64=1 is not compatible with ASYNCIFY' )
@@ -2760,20 +2756,16 @@ def check_memory_setting(setting):
2760
2756
# need to be able to call these explicitly.
2761
2757
settings .REQUIRED_EXPORTS += ['__funcs_on_exit' ]
2762
2758
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 \
2769
2766
settings .ASYNCIFY or \
2770
2767
settings .WASMFS or \
2771
- settings .DEMANGLE_SUPPORT or \
2772
2768
settings .FORCE_FILESYSTEM or \
2773
- settings .STB_IMAGE or \
2774
- settings .EMBIND or \
2775
- settings .FETCH or \
2776
- settings .PROXY_POSIX_SOCKETS or \
2777
2769
options .memory_profiler or \
2778
2770
sanitize :
2779
2771
settings .REQUIRED_EXPORTS += ['malloc' , 'free' ]
0 commit comments