authorgravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2023-03-10 06:20:10+01:00
committergravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2023-03-10 06:20:10+01:00
log0ee9a52507fe30983f7933cb19a5bfde3b40a60c
treee4ab6f9b2ce0804e291ab347c1bdd28b1cc54857
parent87738cad8607a31537a5c16826ab315990bc73c6
signaturelock-open Commit is signed but in an unrecognized format.

wasm-linker: remove synthetic segments & atoms


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

src/link/Wasm.zig-29
......@@ -887,32 +887,12 @@ fn resolveLazySymbols(wasm: *Wasm) !void {
887887 const loc = try wasm.createSyntheticSymbol("__heap_base", .data);
888888 try wasm.discarded.putNoClobber(wasm.base.allocator, kv.value, loc);
889889 _ = wasm.resolved_symbols.swapRemove(loc); // we don't want to emit this symbol, only use it for relocations.
890
891 // TODO: Can we use `createAtom` here while also re-using the symbol
892 // from `createSyntheticSymbol`.
893 const atom_index = @intCast(Atom.Index, wasm.managed_atoms.items.len);
894 const atom = try wasm.managed_atoms.addOne(wasm.base.allocator);
895 atom.* = Atom.empty;
896 atom.sym_index = loc.index;
897 atom.alignment = 1;
898
899 try wasm.parseAtom(atom_index, .{ .data = .synthetic });
900 try wasm.symbol_atom.putNoClobber(wasm.base.allocator, loc, atom_index);
901890 }
902891
903892 if (wasm.undefs.fetchSwapRemove("__heap_end")) |kv| {
904893 const loc = try wasm.createSyntheticSymbol("__heap_end", .data);
905894 try wasm.discarded.putNoClobber(wasm.base.allocator, kv.value, loc);
906895 _ = wasm.resolved_symbols.swapRemove(loc);
907
908 const atom_index = @intCast(Atom.Index, wasm.managed_atoms.items.len);
909 const atom = try wasm.managed_atoms.addOne(wasm.base.allocator);
910 atom.* = Atom.empty;
911 atom.sym_index = loc.index;
912 atom.alignment = 1;
913
914 try wasm.parseAtom(atom_index, .{ .data = .synthetic });
915 try wasm.symbol_atom.putNoClobber(wasm.base.allocator, loc, atom_index);
916896 }
917897}
918898
......@@ -1614,7 +1594,6 @@ const Kind = union(enum) {
16141594 read_only,
16151595 uninitialized,
16161596 initialized,
1617 synthetic,
16181597 },
16191598 function: void,
16201599
......@@ -1625,7 +1604,6 @@ const Kind = union(enum) {
16251604 .read_only => return ".rodata.",
16261605 .uninitialized => return ".bss.",
16271606 .initialized => return ".data.",
1628 .synthetic => return ".synthetic",
16291607 }
16301608 }
16311609};
......@@ -1833,7 +1811,6 @@ fn sortDataSegments(wasm: *Wasm) !void {
18331811 if (mem.startsWith(u8, name, ".rodata")) return 0;
18341812 if (mem.startsWith(u8, name, ".data")) return 1;
18351813 if (mem.startsWith(u8, name, ".text")) return 2;
1836 if (mem.startsWith(u8, name, ".synthetic")) return 100; // always at end
18371814 return 3;
18381815 }
18391816 };
......@@ -2245,10 +2222,6 @@ fn setupMemory(wasm: *Wasm) !void {
22452222 var offset: u32 = @intCast(u32, memory_ptr);
22462223 var data_seg_it = wasm.data_segments.iterator();
22472224 while (data_seg_it.next()) |entry| {
2248 if (mem.eql(u8, entry.key_ptr.*, ".synthetic")) {
2249 // do not update synthetic segments as they are not part of the output
2250 continue;
2251 }
22522225 const segment = &wasm.segments.items[entry.value_ptr.*];
22532226 memory_ptr = std.mem.alignForwardGeneric(u64, memory_ptr, segment.alignment);
22542227 memory_ptr += segment.size;
......@@ -3447,8 +3420,6 @@ fn emitNameSection(wasm: *Wasm, binary_bytes: *std.ArrayList(u8), arena: std.mem
34473420 // bss section is not emitted when this condition holds true, so we also
34483421 // do not output a name for it.
34493422 if (!wasm.base.options.import_memory and std.mem.eql(u8, key, ".bss")) continue;
3450 // Synthetic segments are not emitted
3451 if (std.mem.eql(u8, key, ".synthetic")) continue;
34523423 segments.appendAssumeCapacity(.{ .index = data_segment_index, .name = key });
34533424 data_segment_index += 1;
34543425 }