| ... | @@ -443,6 +443,30 @@ pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Option | ... | @@ -443,6 +443,30 @@ pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Option |
| 443 | // at the end during `initializeCallCtorsFunction`. | 443 | // at the end during `initializeCallCtorsFunction`. |
| 444 | } | 444 | } |
| 445 | | 445 | |
| | 446 | // shared-memory symbols for TLS support |
| | 447 | if (wasm_bin.base.options.shared_memory) { |
| | 448 | { |
| | 449 | const loc = try wasm_bin.createSyntheticSymbol("__tls_base", .global); |
| | 450 | const symbol = loc.getSymbol(wasm_bin); |
| | 451 | symbol.setFlag(.WASM_SYM_VISIBILITY_HIDDEN); |
| | 452 | } |
| | 453 | { |
| | 454 | const loc = try wasm_bin.createSyntheticSymbol("__tls_size", .global); |
| | 455 | const symbol = loc.getSymbol(wasm_bin); |
| | 456 | symbol.setFlag(.WASM_SYM_VISIBILITY_HIDDEN); |
| | 457 | } |
| | 458 | { |
| | 459 | const loc = try wasm_bin.createSyntheticSymbol("__tls_align", .global); |
| | 460 | const symbol = loc.getSymbol(wasm_bin); |
| | 461 | symbol.setFlag(.WASM_SYM_VISIBILITY_HIDDEN); |
| | 462 | } |
| | 463 | { |
| | 464 | const loc = try wasm_bin.createSyntheticSymbol("__wasm_tls_init", .function); |
| | 465 | const symbol = loc.getSymbol(wasm_bin); |
| | 466 | symbol.setFlag(.WASM_SYM_VISIBILITY_HIDDEN); |
| | 467 | } |
| | 468 | } |
| | 469 | |
| 446 | // if (!options.strip and options.module != null) { | 470 | // if (!options.strip and options.module != null) { |
| 447 | // wasm_bin.dwarf = Dwarf.init(allocator, &wasm_bin.base, options.target); | 471 | // wasm_bin.dwarf = Dwarf.init(allocator, &wasm_bin.base, options.target); |
| 448 | // try wasm_bin.initDebugSections(); | 472 | // try wasm_bin.initDebugSections(); |
| ... | @@ -2286,12 +2310,28 @@ fn setupMemory(wasm: *Wasm) !void { | ... | @@ -2286,12 +2310,28 @@ fn setupMemory(wasm: *Wasm) !void { |
| 2286 | | 2310 | |
| 2287 | // set TLS-related symbols | 2311 | // set TLS-related symbols |
| 2288 | if (mem.eql(u8, entry.key_ptr.*, ".tdata")) { | 2312 | if (mem.eql(u8, entry.key_ptr.*, ".tdata")) { |
| 2289 | if (wasm.findGlobalSymbol("__tls_base")) |loc| { | 2313 | if (wasm.findGlobalSymbol("__tls_size")) |loc| { |
| | 2314 | const sym = loc.getSymbol(wasm); |
| | 2315 | sym.index = @intCast(u32, wasm.wasm_globals.items.len) + wasm.imported_globals_count; |
| | 2316 | try wasm.wasm_globals.append(wasm.base.allocator, .{ |
| | 2317 | .global_type = .{ .valtype = .i32, .mutable = false }, |
| | 2318 | .init = .{ .i32_const = @intCast(i32, segment.size) }, |
| | 2319 | }); |
| | 2320 | } |
| | 2321 | if (wasm.findGlobalSymbol("__tls_align")) |loc| { |
| 2290 | const sym = loc.getSymbol(wasm); | 2322 | const sym = loc.getSymbol(wasm); |
| 2291 | sym.index = @intCast(u32, wasm.wasm_globals.items.len) + wasm.imported_globals_count; | 2323 | sym.index = @intCast(u32, wasm.wasm_globals.items.len) + wasm.imported_globals_count; |
| 2292 | try wasm.wasm_globals.append(wasm.base.allocator, .{ | 2324 | try wasm.wasm_globals.append(wasm.base.allocator, .{ |
| 2293 | .global_type = .{ .valtype = .i32, .mutable = false }, | 2325 | .global_type = .{ .valtype = .i32, .mutable = false }, |
| 2294 | .init = .{ .i32_const = @intCast(i32, memory_ptr) }, | 2326 | .init = .{ .i32_const = @intCast(i32, segment.alignment) }, |
| | 2327 | }); |
| | 2328 | } |
| | 2329 | if (wasm.findGlobalSymbol("__tls_base")) |loc| { |
| | 2330 | const sym = loc.getSymbol(wasm); |
| | 2331 | sym.index = @intCast(u32, wasm.wasm_globals.items.len) + wasm.imported_globals_count; |
| | 2332 | try wasm.wasm_globals.append(wasm.base.allocator, .{ |
| | 2333 | .global_type = .{ .valtype = .i32, .mutable = wasm.base.options.shared_memory }, |
| | 2334 | .init = .{ .i32_const = if (wasm.base.options.shared_memory) @as(u32, 0) else @intCast(i32, memory_ptr) }, |
| 2295 | }); | 2335 | }); |
| 2296 | } | 2336 | } |
| 2297 | } | 2337 | } |