@@ -68,7 +68,7 @@ var LibraryDylink = {
68
68
} ,
69
69
70
70
$updateGOT__deps : [ '$GOT' , '$isInternalSym' ] ,
71
- $updateGOT : function ( exports ) {
71
+ $updateGOT : function ( exports , replace ) {
72
72
#if DYLINK_DEBUG
73
73
err ( "updateGOT: " + Object . keys ( exports ) . length ) ;
74
74
#endif
@@ -77,7 +77,6 @@ var LibraryDylink = {
77
77
continue ;
78
78
}
79
79
80
- var replace = false ;
81
80
var value = exports [ symName ] ;
82
81
#if ! WASM_BIGINT
83
82
if ( symName . startsWith ( 'orig$' ) ) {
@@ -117,7 +116,7 @@ var LibraryDylink = {
117
116
118
117
// Applies relocations to exported things.
119
118
$relocateExports__deps : [ '$updateGOT' ] ,
120
- $relocateExports : function ( exports , memoryBase ) {
119
+ $relocateExports : function ( exports , memoryBase , replace ) {
121
120
var relocated = { } ;
122
121
123
122
for ( var e in exports ) {
@@ -139,7 +138,7 @@ var LibraryDylink = {
139
138
}
140
139
relocated [ e ] = value ;
141
140
}
142
- updateGOT ( relocated ) ;
141
+ updateGOT ( relocated , replace ) ;
143
142
return relocated ;
144
143
} ,
145
144
@@ -302,7 +301,7 @@ var LibraryDylink = {
302
301
name = getString ( ) ;
303
302
}
304
303
305
- var customSection = { neededDynlibs : [ ] } ;
304
+ var customSection = { neededDynlibs : [ ] , tlsExports : { } } ;
306
305
if ( name == 'dylink' ) {
307
306
customSection . memorySize = getLEB ( ) ;
308
307
customSection . memoryAlign = getLEB ( ) ;
@@ -320,6 +319,8 @@ var LibraryDylink = {
320
319
assert ( name === 'dylink.0' ) ;
321
320
var WASM_DYLINK_MEM_INFO = 0x1 ;
322
321
var WASM_DYLINK_NEEDED = 0x2 ;
322
+ var WASM_DYLINK_EXPORT_INFO = 0x3 ;
323
+ var WASM_SYMBOL_TLS = 0x100 ;
323
324
while ( offset < end ) {
324
325
var subsectionType = getU8 ( ) ;
325
326
var subsectionSize = getLEB ( ) ;
@@ -334,6 +335,15 @@ var LibraryDylink = {
334
335
var name = getString ( ) ;
335
336
customSection . neededDynlibs . push ( name ) ;
336
337
}
338
+ } else if ( subsectionType === WASM_DYLINK_EXPORT_INFO ) {
339
+ var count = getLEB ( ) ;
340
+ while ( count -- ) {
341
+ var name = getString ( ) ;
342
+ var flags = getLEB ( ) ;
343
+ if ( flags & WASM_SYMBOL_TLS ) {
344
+ customSection . tlsExports [ name ] = 1 ;
345
+ }
346
+ }
337
347
} else {
338
348
#if ASSERTIONS
339
349
err ( 'unknown dylink.0 subsection: ' + subsectionType )
@@ -529,17 +539,7 @@ var LibraryDylink = {
529
539
#if USE_PTHREADS
530
540
// Only one thread (currently The main thread) should call
531
541
// __wasm_call_ctors, but all threads need to call emscripten_tls_init
532
- var initTLS = moduleExports [ 'emscripten_tls_init' ] ;
533
- #if ASSERTIONS
534
- assert ( initTLS ) ;
535
- #endif
536
- #if DYLINK_DEBUG
537
- out ( "adding to tlsInitFunctions: " + initTLS ) ;
538
- #endif
539
- PThread . tlsInitFunctions . push ( initTLS ) ;
540
- if ( runtimeInitialized ) {
541
- initTLS ( ) ;
542
- }
542
+ registerTlsInit ( moduleExports [ 'emscripten_tls_init' ] , instance. exports , metadata )
543
543
if ( ! ENVIRONMENT_IS_PTHREAD ) {
544
544
#endif
545
545
var init = moduleExports [ '__wasm_call_ctors' ] ;
0 commit comments