@@ -354,25 +354,33 @@ fn make_env_module<'a>(
354354 exports. export ( CABI_REALLOC , ExportKind :: Func , index) ;
355355 }
356356
357+ let mut add_global_export = |name : & str , value, mutable| {
358+ let index = globals. len ( ) ;
359+ globals. global (
360+ wasm_encoder:: GlobalType {
361+ val_type : ValType :: I32 ,
362+ mutable,
363+ shared : false ,
364+ } ,
365+ & const_u32 ( value) ,
366+ ) ;
367+ exports. export ( name, ExportKind :: Global , index) ;
368+ } ;
369+
357370 let dl_openables = DlOpenables :: new ( table_offset, memory_offset, metadata) ;
358371
372+ if metadata. iter ( ) . any ( |m| m. needs_libdl_libraries ) {
373+ add_global_export (
374+ metadata:: LIBDL_LIBRARIES ,
375+ dl_openables. libraries_address ,
376+ true ,
377+ ) ;
378+ }
379+
359380 table_offset += dl_openables. function_count ;
360381 memory_offset += u32:: try_from ( dl_openables. buffer . len ( ) ) . unwrap ( ) ;
361382
362383 let memory_size = {
363- let mut add_global_export = |name : & str , value, mutable| {
364- let index = globals. len ( ) ;
365- globals. global (
366- wasm_encoder:: GlobalType {
367- val_type : ValType :: I32 ,
368- mutable,
369- shared : false ,
370- } ,
371- & const_u32 ( value) ,
372- ) ;
373- exports. export ( name, ExportKind :: Global , index) ;
374- } ;
375-
376384 if metadata. iter ( ) . any ( |m| m. needs_stack_pointer ) {
377385 add_global_export ( metadata:: STACK_POINTER , stack_size_bytes, true ) ;
378386 }
@@ -566,7 +574,6 @@ fn make_init_module(
566574 types. ty ( ) . function ( [ ] , [ ] ) ;
567575 let thunk_ty = 0 ;
568576 types. ty ( ) . function ( [ ValType :: I32 ] , [ ] ) ;
569- let one_i32_param_ty = 1 ;
570577 let mut type_offset = 2 ;
571578
572579 for metadata in metadata {
@@ -736,18 +743,6 @@ fn make_init_module(
736743 ) ) ) ;
737744 }
738745
739- if metadata. has_set_libraries {
740- ctor_calls. push ( Ins :: I32Const (
741- i32:: try_from ( dl_openables. libraries_address ) . unwrap ( ) ,
742- ) ) ;
743- ctor_calls. push ( Ins :: Call ( add_function_import (
744- & mut imports,
745- metadata. name ,
746- metadata:: SET_LIBRARIES ,
747- one_i32_param_ty,
748- ) ) ) ;
749- }
750-
751746 for import in & metadata. memory_address_imports {
752747 let ( exporter, _) = find_offset_exporter ( import, exporters) ?;
753748
@@ -1756,6 +1751,7 @@ impl Linker {
17561751 metadata:: HEAP_END ,
17571752 metadata:: STACK_HIGH ,
17581753 metadata:: STACK_LOW ,
1754+ metadata:: LIBDL_LIBRARIES ,
17591755 ]
17601756 . into_iter ( )
17611757 . map ( |name| Item {
0 commit comments