authorgravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2023-11-06 17:09:42+01:00
committergravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2023-11-28 15:47:03+01:00
logf3626eb81662fb7519d09e14bed6e4d958c73e43
tree8861fdc224683e84ac02d3d0d1385d46142ccecd
parent2a322645331532e22def160677a345854f00b7e2
signaturelock-open Commit is signed but in an unrecognized format.

wasm-link: ensure TLS global when resolved

When a linked object contains references to the __tls_base symbol, we lazily create this symbol. However, we wouldn't create the corresponding Wasm global. This meant its address wasn't set correctly as well as fail to output it into the `Names` section.

1 files changed, 8 insertions(+), 0 deletions(-)

src/link/Wasm.zig+8
......@@ -1242,6 +1242,14 @@ fn resolveLazySymbols(wasm: *Wasm) !void {
12421242 if (wasm.undefs.fetchSwapRemove(name_offset)) |kv| {
12431243 const loc = try wasm.createSyntheticSymbolOffset(name_offset, .global);
12441244 try wasm.discarded.putNoClobber(wasm.base.allocator, kv.value, loc);
1245 _ = wasm.resolved_symbols.swapRemove(kv.value);
1246 const symbol = loc.getSymbol(wasm);
1247 symbol.setFlag(.WASM_SYM_VISIBILITY_HIDDEN);
1248 symbol.index = @intCast(wasm.imported_globals_count + wasm.wasm_globals.items.len);
1249 try wasm.wasm_globals.append(wasm.base.allocator, .{
1250 .global_type = .{ .valtype = .i32, .mutable = true },
1251 .init = .{ .i32_const = undefined },
1252 });
12451253 }
12461254 }
12471255 }