@@ -164,22 +164,23 @@ var LibraryDylink = {
164164 } ,
165165
166166 $GOT : { } ,
167- $currentModuleWeakSymbols : '=new Set({{{ JSON.stringify(Array.from(WEAK_IMPORTS)) }}})' ,
168167
169- // Create globals to each imported symbol. These are all initialized to zero
170- // and get assigned later in `updateGOT`
168+ // Proxy handler used for GOT.mem and GOT.func imports. Each of these
169+ // imports is fullfilled dynamically via the `get` method of this proxy
170+ // handler. We abuse the `target` of the Proxy in order to pass the set of
171+ // weak imports to the handler.
171172 $GOTHandler__internal : true ,
172- $GOTHandler__deps : [ '$GOT' , '$currentModuleWeakSymbols' ] ,
173+ $GOTHandler__deps : [ '$GOT' ] ,
173174 $GOTHandler : {
174- get ( obj , symName ) {
175+ get ( weakImports , symName ) {
175176 var rtn = GOT [ symName ] ;
176177 if ( ! rtn ) {
177178#if DYLINK_DEBUG == 2
178179 dbg ( `new GOT entry: ${ symName } ` ) ;
179180#endif
180181 rtn = GOT [ symName ] = new WebAssembly . Global ( { 'value' : '{{{ POINTER_WASM_TYPE }}}' , 'mutable' : true } , { { { UNDEFINED_ADDR } } } ) ;
181182 }
182- if ( ! currentModuleWeakSymbols . has ( symName ) ) {
183+ if ( ! weakImports . has ( symName ) ) {
183184 // Any non-weak reference to a symbol marks it as `required`, which
184185 // enabled `reportUndefinedSymbols` to report undefined symbol errors
185186 // correctly.
@@ -660,7 +661,6 @@ var LibraryDylink = {
660661 '$loadDynamicLibrary' , '$getMemory' , '$updateGOT' ,
661662 '$relocateExports' , '$resolveGlobalSymbol' , '$GOTHandler' ,
662663 '$getDylinkMetadata' , '$alignMemory' ,
663- '$currentModuleWeakSymbols' ,
664664 '$updateTableMap' ,
665665 '$wasmTable' ,
666666 '$addOnPostCtor' ,
@@ -799,10 +799,10 @@ var LibraryDylink = {
799799 }
800800 } ;
801801 var proxy = new Proxy ( { } , proxyHandler ) ;
802- currentModuleWeakSymbols = metadata . weakImports ;
802+ var GOTProxy = new Proxy ( metadata . weakImports , GOTHandler ) ;
803803 var info = {
804- 'GOT.mem' : new Proxy ( { } , GOTHandler ) ,
805- 'GOT.func' : new Proxy ( { } , GOTHandler ) ,
804+ 'GOT.mem' : GOTProxy ,
805+ 'GOT.func' : GOTProxy ,
806806 'env' : proxy ,
807807 '{{{ WASI_MODULE_NAME }}}' : proxy ,
808808 } ;
0 commit comments