mirror of
https://github.com/ziglang/zig.git
synced 2026-02-13 21:08:36 +00:00
link.File.Wasm: remove the "files" abstraction
Removes the `files` field from the Wasm linker, storing the ZigObject as its own field instead using a tagged union. This removes a layer of indirection when accessing the ZigObject, and untangles logic so that we can introduce a "pre-link" phase that prepares the linker state to handle only incremental updates to the ZigObject and then minimize logic inside flush(). Furthermore, don't make array elements store their own indexes, that's always a waste. Flattens some of the file system hierarchy and unifies variable names for easier refactoring. Introduces type safety for optional object indexes.
This commit is contained in:
parent
17a87d7341
commit
ba2d006634
@ -648,12 +648,9 @@ set(ZIG_STAGE2_SOURCES
|
||||
src/link/StringTable.zig
|
||||
src/link/Wasm.zig
|
||||
src/link/Wasm/Archive.zig
|
||||
src/link/Wasm/Atom.zig
|
||||
src/link/Wasm/Object.zig
|
||||
src/link/Wasm/Symbol.zig
|
||||
src/link/Wasm/ZigObject.zig
|
||||
src/link/Wasm/file.zig
|
||||
src/link/Wasm/types.zig
|
||||
src/link/aarch64.zig
|
||||
src/link/riscv.zig
|
||||
src/link/table_section.zig
|
||||
|
||||
@ -1291,7 +1291,7 @@ fn genFunc(func: *CodeGen) InnerError!void {
|
||||
var prologue = std.ArrayList(Mir.Inst).init(func.gpa);
|
||||
defer prologue.deinit();
|
||||
|
||||
const sp = @intFromEnum(func.bin_file.zigObjectPtr().?.stack_pointer_sym);
|
||||
const sp = @intFromEnum(func.bin_file.zig_object.?.stack_pointer_sym);
|
||||
// load stack pointer
|
||||
try prologue.append(.{ .tag = .global_get, .data = .{ .label = sp } });
|
||||
// store stack pointer so we can restore it when we return from the function
|
||||
@ -1511,7 +1511,7 @@ fn restoreStackPointer(func: *CodeGen) !void {
|
||||
try func.emitWValue(func.initial_stack_value);
|
||||
|
||||
// save its value in the global stack pointer
|
||||
try func.addLabel(.global_set, @intFromEnum(func.bin_file.zigObjectPtr().?.stack_pointer_sym));
|
||||
try func.addLabel(.global_set, @intFromEnum(func.bin_file.zig_object.?.stack_pointer_sym));
|
||||
}
|
||||
|
||||
/// From a given type, will create space on the virtual stack to store the value of such type.
|
||||
@ -2262,7 +2262,7 @@ fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif
|
||||
}
|
||||
|
||||
if (callee) |direct| {
|
||||
const atom_index = func.bin_file.zigObjectPtr().?.navs.get(direct).?.atom;
|
||||
const atom_index = func.bin_file.zig_object.?.navs.get(direct).?.atom;
|
||||
try func.addLabel(.call, @intFromEnum(func.bin_file.getAtom(atom_index).sym_index));
|
||||
} else {
|
||||
// in this case we call a function pointer
|
||||
@ -2274,7 +2274,7 @@ fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif
|
||||
var fn_type = try genFunctype(func.gpa, fn_info.cc, fn_info.param_types.get(ip), Type.fromInterned(fn_info.return_type), pt, func.target.*);
|
||||
defer fn_type.deinit(func.gpa);
|
||||
|
||||
const fn_type_index = try func.bin_file.zigObjectPtr().?.putOrGetFuncType(func.gpa, fn_type);
|
||||
const fn_type_index = try func.bin_file.zig_object.?.putOrGetFuncType(func.gpa, fn_type);
|
||||
try func.addLabel(.call_indirect, fn_type_index);
|
||||
}
|
||||
|
||||
@ -7178,7 +7178,7 @@ fn callIntrinsic(
|
||||
const zcu = pt.zcu;
|
||||
var func_type = try genFunctype(func.gpa, .{ .wasm_watc = .{} }, param_types, return_type, pt, func.target.*);
|
||||
defer func_type.deinit(func.gpa);
|
||||
const func_type_index = try func.bin_file.zigObjectPtr().?.putOrGetFuncType(func.gpa, func_type);
|
||||
const func_type_index = try func.bin_file.zig_object.?.putOrGetFuncType(func.gpa, func_type);
|
||||
try func.bin_file.addOrUpdateImport(name, symbol_index, null, func_type_index);
|
||||
|
||||
const want_sret_param = firstParamSRet(.{ .wasm_watc = .{} }, return_type, pt, func.target.*);
|
||||
|
||||
@ -310,7 +310,7 @@ fn emitGlobal(emit: *Emit, tag: Mir.Inst.Tag, inst: Mir.Inst.Index) !void {
|
||||
const global_offset = emit.offset();
|
||||
try emit.code.appendSlice(&buf);
|
||||
|
||||
const atom_index = emit.bin_file.zigObjectPtr().?.navs.get(emit.owner_nav).?.atom;
|
||||
const atom_index = emit.bin_file.zig_object.?.navs.get(emit.owner_nav).?.atom;
|
||||
const atom = emit.bin_file.getAtomPtr(atom_index);
|
||||
try atom.relocs.append(gpa, .{
|
||||
.index = label,
|
||||
@ -370,7 +370,7 @@ fn emitCall(emit: *Emit, inst: Mir.Inst.Index) !void {
|
||||
try emit.code.appendSlice(&buf);
|
||||
|
||||
if (label != 0) {
|
||||
const atom_index = emit.bin_file.zigObjectPtr().?.navs.get(emit.owner_nav).?.atom;
|
||||
const atom_index = emit.bin_file.zig_object.?.navs.get(emit.owner_nav).?.atom;
|
||||
const atom = emit.bin_file.getAtomPtr(atom_index);
|
||||
try atom.relocs.append(gpa, .{
|
||||
.offset = call_offset,
|
||||
@ -390,7 +390,7 @@ fn emitCallIndirect(emit: *Emit, inst: Mir.Inst.Index) !void {
|
||||
leb128.writeUnsignedFixed(5, &buf, type_index);
|
||||
try emit.code.appendSlice(&buf);
|
||||
if (type_index != 0) {
|
||||
const atom_index = emit.bin_file.zigObjectPtr().?.navs.get(emit.owner_nav).?.atom;
|
||||
const atom_index = emit.bin_file.zig_object.?.navs.get(emit.owner_nav).?.atom;
|
||||
const atom = emit.bin_file.getAtomPtr(atom_index);
|
||||
try atom.relocs.append(emit.bin_file.base.comp.gpa, .{
|
||||
.offset = call_offset,
|
||||
@ -412,7 +412,7 @@ fn emitFunctionIndex(emit: *Emit, inst: Mir.Inst.Index) !void {
|
||||
try emit.code.appendSlice(&buf);
|
||||
|
||||
if (symbol_index != 0) {
|
||||
const atom_index = emit.bin_file.zigObjectPtr().?.navs.get(emit.owner_nav).?.atom;
|
||||
const atom_index = emit.bin_file.zig_object.?.navs.get(emit.owner_nav).?.atom;
|
||||
const atom = emit.bin_file.getAtomPtr(atom_index);
|
||||
try atom.relocs.append(gpa, .{
|
||||
.offset = index_offset,
|
||||
@ -443,7 +443,7 @@ fn emitMemAddress(emit: *Emit, inst: Mir.Inst.Index) !void {
|
||||
}
|
||||
|
||||
if (mem.pointer != 0) {
|
||||
const atom_index = emit.bin_file.zigObjectPtr().?.navs.get(emit.owner_nav).?.atom;
|
||||
const atom_index = emit.bin_file.zig_object.?.navs.get(emit.owner_nav).?.atom;
|
||||
const atom = emit.bin_file.getAtomPtr(atom_index);
|
||||
try atom.relocs.append(gpa, .{
|
||||
.offset = mem_offset,
|
||||
|
||||
1289
src/link/Wasm.zig
1289
src/link/Wasm.zig
File diff suppressed because it is too large
Load Diff
@ -1,204 +0,0 @@
|
||||
/// Represents the index of the file this atom was generated from.
|
||||
/// This is 'null' when the atom was generated by a synthetic linker symbol.
|
||||
file: FileIndex,
|
||||
/// symbol index of the symbol representing this atom
|
||||
sym_index: Symbol.Index,
|
||||
/// Size of the atom, used to calculate section sizes in the final binary
|
||||
size: u32 = 0,
|
||||
/// List of relocations belonging to this atom
|
||||
relocs: std.ArrayListUnmanaged(types.Relocation) = .empty,
|
||||
/// Contains the binary data of an atom, which can be non-relocated
|
||||
code: std.ArrayListUnmanaged(u8) = .empty,
|
||||
/// For code this is 1, for data this is set to the highest value of all segments
|
||||
alignment: Wasm.Alignment = .@"1",
|
||||
/// Offset into the section where the atom lives, this already accounts
|
||||
/// for alignment.
|
||||
offset: u32 = 0,
|
||||
/// The original offset within the object file. This value is subtracted from
|
||||
/// relocation offsets to determine where in the `data` to rewrite the value
|
||||
original_offset: u32 = 0,
|
||||
/// Previous atom in relation to this atom.
|
||||
/// is null when this atom is the first in its order
|
||||
prev: Atom.Index = .null,
|
||||
/// Contains atoms local to a decl, all managed by this `Atom`.
|
||||
/// When the parent atom is being freed, it will also do so for all local atoms.
|
||||
locals: std.ArrayListUnmanaged(Atom.Index) = .empty,
|
||||
|
||||
/// Represents the index of an Atom where `null` is considered
|
||||
/// an invalid atom.
|
||||
pub const Index = enum(u32) {
|
||||
null = std.math.maxInt(u32),
|
||||
_,
|
||||
};
|
||||
|
||||
/// Frees all resources owned by this `Atom`.
|
||||
pub fn deinit(atom: *Atom, gpa: std.mem.Allocator) void {
|
||||
atom.relocs.deinit(gpa);
|
||||
atom.code.deinit(gpa);
|
||||
atom.locals.deinit(gpa);
|
||||
atom.* = undefined;
|
||||
}
|
||||
|
||||
/// Sets the length of relocations and code to '0',
|
||||
/// effectively resetting them and allowing them to be re-populated.
|
||||
pub fn clear(atom: *Atom) void {
|
||||
atom.relocs.clearRetainingCapacity();
|
||||
atom.code.clearRetainingCapacity();
|
||||
}
|
||||
|
||||
pub fn format(atom: Atom, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void {
|
||||
_ = fmt;
|
||||
_ = options;
|
||||
try writer.print("Atom{{ .sym_index = {d}, .alignment = {d}, .size = {d}, .offset = 0x{x:0>8} }}", .{
|
||||
@intFromEnum(atom.sym_index),
|
||||
atom.alignment,
|
||||
atom.size,
|
||||
atom.offset,
|
||||
});
|
||||
}
|
||||
|
||||
/// Returns the location of the symbol that represents this `Atom`
|
||||
pub fn symbolLoc(atom: Atom) Wasm.SymbolLoc {
|
||||
return .{ .file = atom.file, .index = atom.sym_index };
|
||||
}
|
||||
|
||||
/// Resolves the relocations within the atom, writing the new value
|
||||
/// at the calculated offset.
|
||||
pub fn resolveRelocs(atom: *Atom, wasm_bin: *const Wasm) void {
|
||||
if (atom.relocs.items.len == 0) return;
|
||||
const symbol_name = atom.symbolLoc().getName(wasm_bin);
|
||||
log.debug("Resolving relocs in atom '{s}' count({d})", .{
|
||||
symbol_name,
|
||||
atom.relocs.items.len,
|
||||
});
|
||||
|
||||
for (atom.relocs.items) |reloc| {
|
||||
const value = atom.relocationValue(reloc, wasm_bin);
|
||||
log.debug("Relocating '{s}' referenced in '{s}' offset=0x{x:0>8} value={d}", .{
|
||||
(Wasm.SymbolLoc{ .file = atom.file, .index = @enumFromInt(reloc.index) }).getName(wasm_bin),
|
||||
symbol_name,
|
||||
reloc.offset,
|
||||
value,
|
||||
});
|
||||
|
||||
switch (reloc.relocation_type) {
|
||||
.R_WASM_TABLE_INDEX_I32,
|
||||
.R_WASM_FUNCTION_OFFSET_I32,
|
||||
.R_WASM_GLOBAL_INDEX_I32,
|
||||
.R_WASM_MEMORY_ADDR_I32,
|
||||
.R_WASM_SECTION_OFFSET_I32,
|
||||
=> std.mem.writeInt(u32, atom.code.items[reloc.offset - atom.original_offset ..][0..4], @as(u32, @truncate(value)), .little),
|
||||
.R_WASM_TABLE_INDEX_I64,
|
||||
.R_WASM_MEMORY_ADDR_I64,
|
||||
=> std.mem.writeInt(u64, atom.code.items[reloc.offset - atom.original_offset ..][0..8], value, .little),
|
||||
.R_WASM_GLOBAL_INDEX_LEB,
|
||||
.R_WASM_EVENT_INDEX_LEB,
|
||||
.R_WASM_FUNCTION_INDEX_LEB,
|
||||
.R_WASM_MEMORY_ADDR_LEB,
|
||||
.R_WASM_MEMORY_ADDR_SLEB,
|
||||
.R_WASM_TABLE_INDEX_SLEB,
|
||||
.R_WASM_TABLE_NUMBER_LEB,
|
||||
.R_WASM_TYPE_INDEX_LEB,
|
||||
.R_WASM_MEMORY_ADDR_TLS_SLEB,
|
||||
=> leb.writeUnsignedFixed(5, atom.code.items[reloc.offset - atom.original_offset ..][0..5], @as(u32, @truncate(value))),
|
||||
.R_WASM_MEMORY_ADDR_LEB64,
|
||||
.R_WASM_MEMORY_ADDR_SLEB64,
|
||||
.R_WASM_TABLE_INDEX_SLEB64,
|
||||
.R_WASM_MEMORY_ADDR_TLS_SLEB64,
|
||||
=> leb.writeUnsignedFixed(10, atom.code.items[reloc.offset - atom.original_offset ..][0..10], value),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// From a given `relocation` will return the new value to be written.
|
||||
/// All values will be represented as a `u64` as all values can fit within it.
|
||||
/// The final value must be casted to the correct size.
|
||||
fn relocationValue(atom: Atom, relocation: types.Relocation, wasm_bin: *const Wasm) u64 {
|
||||
const target_loc = (Wasm.SymbolLoc{ .file = atom.file, .index = @enumFromInt(relocation.index) }).finalLoc(wasm_bin);
|
||||
const symbol = target_loc.getSymbol(wasm_bin);
|
||||
if (relocation.relocation_type != .R_WASM_TYPE_INDEX_LEB and
|
||||
symbol.tag != .section and
|
||||
symbol.isDead())
|
||||
{
|
||||
const val = atom.thombstone(wasm_bin) orelse relocation.addend;
|
||||
return @bitCast(val);
|
||||
}
|
||||
switch (relocation.relocation_type) {
|
||||
.R_WASM_FUNCTION_INDEX_LEB => return symbol.index,
|
||||
.R_WASM_TABLE_NUMBER_LEB => return symbol.index,
|
||||
.R_WASM_TABLE_INDEX_I32,
|
||||
.R_WASM_TABLE_INDEX_I64,
|
||||
.R_WASM_TABLE_INDEX_SLEB,
|
||||
.R_WASM_TABLE_INDEX_SLEB64,
|
||||
=> return wasm_bin.function_table.get(.{ .file = atom.file, .index = @enumFromInt(relocation.index) }) orelse 0,
|
||||
.R_WASM_TYPE_INDEX_LEB => {
|
||||
const obj_file = wasm_bin.file(atom.file) orelse return relocation.index;
|
||||
const original_type = obj_file.funcTypes()[relocation.index];
|
||||
return wasm_bin.getTypeIndex(original_type).?;
|
||||
},
|
||||
.R_WASM_GLOBAL_INDEX_I32,
|
||||
.R_WASM_GLOBAL_INDEX_LEB,
|
||||
=> return symbol.index,
|
||||
.R_WASM_MEMORY_ADDR_I32,
|
||||
.R_WASM_MEMORY_ADDR_I64,
|
||||
.R_WASM_MEMORY_ADDR_LEB,
|
||||
.R_WASM_MEMORY_ADDR_LEB64,
|
||||
.R_WASM_MEMORY_ADDR_SLEB,
|
||||
.R_WASM_MEMORY_ADDR_SLEB64,
|
||||
=> {
|
||||
std.debug.assert(symbol.tag == .data);
|
||||
if (symbol.isUndefined()) {
|
||||
return 0;
|
||||
}
|
||||
const va: i33 = @intCast(symbol.virtual_address);
|
||||
return @intCast(va + relocation.addend);
|
||||
},
|
||||
.R_WASM_EVENT_INDEX_LEB => return symbol.index,
|
||||
.R_WASM_SECTION_OFFSET_I32 => {
|
||||
const target_atom_index = wasm_bin.symbol_atom.get(target_loc).?;
|
||||
const target_atom = wasm_bin.getAtom(target_atom_index);
|
||||
const rel_value: i33 = @intCast(target_atom.offset);
|
||||
return @intCast(rel_value + relocation.addend);
|
||||
},
|
||||
.R_WASM_FUNCTION_OFFSET_I32 => {
|
||||
if (symbol.isUndefined()) {
|
||||
const val = atom.thombstone(wasm_bin) orelse relocation.addend;
|
||||
return @bitCast(val);
|
||||
}
|
||||
const target_atom_index = wasm_bin.symbol_atom.get(target_loc).?;
|
||||
const target_atom = wasm_bin.getAtom(target_atom_index);
|
||||
const rel_value: i33 = @intCast(target_atom.offset);
|
||||
return @intCast(rel_value + relocation.addend);
|
||||
},
|
||||
.R_WASM_MEMORY_ADDR_TLS_SLEB,
|
||||
.R_WASM_MEMORY_ADDR_TLS_SLEB64,
|
||||
=> {
|
||||
const va: i33 = @intCast(symbol.virtual_address);
|
||||
return @intCast(va + relocation.addend);
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// For a given `Atom` returns whether it has a thombstone value or not.
|
||||
/// This defines whether we want a specific value when a section is dead.
|
||||
fn thombstone(atom: Atom, wasm: *const Wasm) ?i64 {
|
||||
const atom_name = atom.symbolLoc().getName(wasm);
|
||||
if (std.mem.eql(u8, atom_name, ".debug_ranges") or std.mem.eql(u8, atom_name, ".debug_loc")) {
|
||||
return -2;
|
||||
} else if (std.mem.startsWith(u8, atom_name, ".debug_")) {
|
||||
return -1;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
const leb = std.leb;
|
||||
const log = std.log.scoped(.link);
|
||||
const mem = std.mem;
|
||||
const std = @import("std");
|
||||
const types = @import("types.zig");
|
||||
|
||||
const Allocator = mem.Allocator;
|
||||
const Atom = @This();
|
||||
const FileIndex = @import("file.zig").File.Index;
|
||||
const Symbol = @import("Symbol.zig");
|
||||
const Wasm = @import("../Wasm.zig");
|
||||
@ -3,22 +3,18 @@
|
||||
//! the data on correctness. The result can then be used by the linker.
|
||||
const Object = @This();
|
||||
|
||||
const Atom = @import("Atom.zig");
|
||||
const types = @import("types.zig");
|
||||
const std = @import("std");
|
||||
const Wasm = @import("../Wasm.zig");
|
||||
const Atom = Wasm.Atom;
|
||||
const Alignment = Wasm.Alignment;
|
||||
const Symbol = @import("Symbol.zig");
|
||||
const Alignment = types.Alignment;
|
||||
const File = @import("file.zig").File;
|
||||
|
||||
const std = @import("std");
|
||||
const Allocator = std.mem.Allocator;
|
||||
const leb = std.leb;
|
||||
const meta = std.meta;
|
||||
|
||||
const log = std.log.scoped(.object);
|
||||
|
||||
/// Index into the list of relocatable object files within the linker driver.
|
||||
index: File.Index = .null,
|
||||
/// Wasm spec version used for this `Object`
|
||||
version: u32 = 0,
|
||||
/// The file descriptor that represents the wasm object file.
|
||||
@ -28,7 +24,7 @@ path: []const u8,
|
||||
/// Parsed type section
|
||||
func_types: []const std.wasm.Type = &.{},
|
||||
/// A list of all imports for this module
|
||||
imports: []const types.Import = &.{},
|
||||
imports: []const Wasm.Import = &.{},
|
||||
/// Parsed function section
|
||||
functions: []const std.wasm.Func = &.{},
|
||||
/// Parsed table section
|
||||
@ -38,7 +34,7 @@ memories: []const std.wasm.Memory = &.{},
|
||||
/// Parsed global section
|
||||
globals: []const std.wasm.Global = &.{},
|
||||
/// Parsed export section
|
||||
exports: []const types.Export = &.{},
|
||||
exports: []const Wasm.Export = &.{},
|
||||
/// Parsed element section
|
||||
elements: []const std.wasm.Element = &.{},
|
||||
/// Represents the function ID that must be called on startup.
|
||||
@ -48,18 +44,18 @@ start: ?u32 = null,
|
||||
/// A slice of features that tell the linker what features are mandatory,
|
||||
/// used (or therefore missing) and must generate an error when another
|
||||
/// object uses features that are not supported by the other.
|
||||
features: []const types.Feature = &.{},
|
||||
features: []const Wasm.Feature = &.{},
|
||||
/// A table that maps the relocations we must perform where the key represents
|
||||
/// the section that the list of relocations applies to.
|
||||
relocations: std.AutoArrayHashMapUnmanaged(u32, []types.Relocation) = .empty,
|
||||
relocations: std.AutoArrayHashMapUnmanaged(u32, []Wasm.Relocation) = .empty,
|
||||
/// Table of symbols belonging to this Object file
|
||||
symtable: []Symbol = &.{},
|
||||
/// Extra metadata about the linking section, such as alignment of segments and their name
|
||||
segment_info: []const types.Segment = &.{},
|
||||
segment_info: []const Wasm.NamedSegment = &.{},
|
||||
/// A sequence of function initializers that must be called on startup
|
||||
init_funcs: []const types.InitFunc = &.{},
|
||||
init_funcs: []const Wasm.InitFunc = &.{},
|
||||
/// Comdat information
|
||||
comdat_info: []const types.Comdat = &.{},
|
||||
comdat_info: []const Wasm.Comdat = &.{},
|
||||
/// Represents non-synthetic sections that can essentially be mem-cpy'd into place
|
||||
/// after performing relocations.
|
||||
relocatable_data: std.AutoHashMapUnmanaged(RelocatableData.Tag, []RelocatableData) = .empty,
|
||||
@ -75,7 +71,7 @@ imported_globals_count: u32 = 0,
|
||||
imported_tables_count: u32 = 0,
|
||||
|
||||
/// Represents a single item within a section (depending on its `type`)
|
||||
const RelocatableData = struct {
|
||||
pub const RelocatableData = struct {
|
||||
/// The type of the relocatable data
|
||||
type: Tag,
|
||||
/// Pointer to the data of the segment, where its length is written to `size`
|
||||
@ -209,7 +205,7 @@ pub fn deinit(object: *Object, gpa: Allocator) void {
|
||||
|
||||
/// Finds the import within the list of imports from a given kind and index of that kind.
|
||||
/// Asserts the import exists
|
||||
pub fn findImport(object: *const Object, sym: Symbol) types.Import {
|
||||
pub fn findImport(object: *const Object, sym: Symbol) Wasm.Import {
|
||||
var i: u32 = 0;
|
||||
return for (object.imports) |import| {
|
||||
if (std.meta.activeTag(import.kind) == sym.tag.externalType()) {
|
||||
@ -261,7 +257,7 @@ fn checkLegacyIndirectFunctionTable(object: *Object, wasm_file: *const Wasm) !?S
|
||||
return error.MissingTableSymbols;
|
||||
}
|
||||
|
||||
const table_import: types.Import = for (object.imports) |imp| {
|
||||
const table_import: Wasm.Import = for (object.imports) |imp| {
|
||||
if (imp.kind == .table) {
|
||||
break imp;
|
||||
}
|
||||
@ -592,13 +588,13 @@ fn Parser(comptime ReaderType: type) type {
|
||||
const diags = &parser.wasm_file.base.comp.link_diags;
|
||||
const reader = parser.reader.reader();
|
||||
for (try readVec(&parser.object.features, reader, gpa)) |*feature| {
|
||||
const prefix = try readEnum(types.Feature.Prefix, reader);
|
||||
const prefix = try readEnum(Wasm.Feature.Prefix, reader);
|
||||
const name_len = try leb.readUleb128(u32, reader);
|
||||
const name = try gpa.alloc(u8, name_len);
|
||||
defer gpa.free(name);
|
||||
try reader.readNoEof(name);
|
||||
|
||||
const tag = types.known_features.get(name) orelse {
|
||||
const tag = Wasm.known_features.get(name) orelse {
|
||||
var err = try diags.addErrorWithNotes(1);
|
||||
try err.addMsg("Object file contains unknown feature: {s}", .{name});
|
||||
try err.addNote("defined in '{s}'", .{parser.object.path});
|
||||
@ -618,7 +614,7 @@ fn Parser(comptime ReaderType: type) type {
|
||||
const reader = parser.reader.reader();
|
||||
const section = try leb.readUleb128(u32, reader);
|
||||
const count = try leb.readUleb128(u32, reader);
|
||||
const relocations = try gpa.alloc(types.Relocation, count);
|
||||
const relocations = try gpa.alloc(Wasm.Relocation, count);
|
||||
errdefer gpa.free(relocations);
|
||||
|
||||
log.debug("Found {d} relocations for section ({d})", .{
|
||||
@ -628,7 +624,7 @@ fn Parser(comptime ReaderType: type) type {
|
||||
|
||||
for (relocations) |*relocation| {
|
||||
const rel_type = try reader.readByte();
|
||||
const rel_type_enum = std.meta.intToEnum(types.Relocation.RelocationType, rel_type) catch return error.MalformedSection;
|
||||
const rel_type_enum = std.meta.intToEnum(Wasm.Relocation.RelocationType, rel_type) catch return error.MalformedSection;
|
||||
relocation.* = .{
|
||||
.relocation_type = rel_type_enum,
|
||||
.offset = try leb.readUleb128(u32, reader),
|
||||
@ -671,7 +667,7 @@ fn Parser(comptime ReaderType: type) type {
|
||||
/// such as access to the `import` section to find the name of a symbol.
|
||||
fn parseSubsection(parser: *ObjectParser, gpa: Allocator, reader: anytype) !void {
|
||||
const sub_type = try leb.readUleb128(u8, reader);
|
||||
log.debug("Found subsection: {s}", .{@tagName(@as(types.SubsectionType, @enumFromInt(sub_type)))});
|
||||
log.debug("Found subsection: {s}", .{@tagName(@as(Wasm.SubsectionType, @enumFromInt(sub_type)))});
|
||||
const payload_len = try leb.readUleb128(u32, reader);
|
||||
if (payload_len == 0) return;
|
||||
|
||||
@ -681,9 +677,9 @@ fn Parser(comptime ReaderType: type) type {
|
||||
// every subsection contains a 'count' field
|
||||
const count = try leb.readUleb128(u32, limited_reader);
|
||||
|
||||
switch (@as(types.SubsectionType, @enumFromInt(sub_type))) {
|
||||
switch (@as(Wasm.SubsectionType, @enumFromInt(sub_type))) {
|
||||
.WASM_SEGMENT_INFO => {
|
||||
const segments = try gpa.alloc(types.Segment, count);
|
||||
const segments = try gpa.alloc(Wasm.NamedSegment, count);
|
||||
errdefer gpa.free(segments);
|
||||
for (segments) |*segment| {
|
||||
const name_len = try leb.readUleb128(u32, reader);
|
||||
@ -704,13 +700,13 @@ fn Parser(comptime ReaderType: type) type {
|
||||
// support legacy object files that specified being TLS by the name instead of the TLS flag.
|
||||
if (!segment.isTLS() and (std.mem.startsWith(u8, segment.name, ".tdata") or std.mem.startsWith(u8, segment.name, ".tbss"))) {
|
||||
// set the flag so we can simply check for the flag in the rest of the linker.
|
||||
segment.flags |= @intFromEnum(types.Segment.Flags.WASM_SEG_FLAG_TLS);
|
||||
segment.flags |= @intFromEnum(Wasm.NamedSegment.Flags.WASM_SEG_FLAG_TLS);
|
||||
}
|
||||
}
|
||||
parser.object.segment_info = segments;
|
||||
},
|
||||
.WASM_INIT_FUNCS => {
|
||||
const funcs = try gpa.alloc(types.InitFunc, count);
|
||||
const funcs = try gpa.alloc(Wasm.InitFunc, count);
|
||||
errdefer gpa.free(funcs);
|
||||
for (funcs) |*func| {
|
||||
func.* = .{
|
||||
@ -722,7 +718,7 @@ fn Parser(comptime ReaderType: type) type {
|
||||
parser.object.init_funcs = funcs;
|
||||
},
|
||||
.WASM_COMDAT_INFO => {
|
||||
const comdats = try gpa.alloc(types.Comdat, count);
|
||||
const comdats = try gpa.alloc(Wasm.Comdat, count);
|
||||
errdefer gpa.free(comdats);
|
||||
for (comdats) |*comdat| {
|
||||
const name_len = try leb.readUleb128(u32, reader);
|
||||
@ -736,11 +732,11 @@ fn Parser(comptime ReaderType: type) type {
|
||||
}
|
||||
|
||||
const symbol_count = try leb.readUleb128(u32, reader);
|
||||
const symbols = try gpa.alloc(types.ComdatSym, symbol_count);
|
||||
const symbols = try gpa.alloc(Wasm.ComdatSym, symbol_count);
|
||||
errdefer gpa.free(symbols);
|
||||
for (symbols) |*symbol| {
|
||||
symbol.* = .{
|
||||
.kind = @as(types.ComdatSym.Type, @enumFromInt(try leb.readUleb128(u8, reader))),
|
||||
.kind = @as(Wasm.ComdatSym.Type, @enumFromInt(try leb.readUleb128(u8, reader))),
|
||||
.index = try leb.readUleb128(u32, reader),
|
||||
};
|
||||
}
|
||||
@ -921,93 +917,3 @@ fn assertEnd(reader: anytype) !void {
|
||||
if (len != 0) return error.MalformedSection;
|
||||
if (reader.context.bytes_left != 0) return error.MalformedSection;
|
||||
}
|
||||
|
||||
/// Parses an object file into atoms, for code and data sections
|
||||
pub fn parseSymbolIntoAtom(object: *Object, wasm: *Wasm, symbol_index: Symbol.Index) !Atom.Index {
|
||||
const comp = wasm.base.comp;
|
||||
const gpa = comp.gpa;
|
||||
const symbol = &object.symtable[@intFromEnum(symbol_index)];
|
||||
const relocatable_data: RelocatableData = switch (symbol.tag) {
|
||||
.function => object.relocatable_data.get(.code).?[symbol.index - object.imported_functions_count],
|
||||
.data => object.relocatable_data.get(.data).?[symbol.index],
|
||||
.section => blk: {
|
||||
const data = object.relocatable_data.get(.custom).?;
|
||||
for (data) |dat| {
|
||||
if (dat.section_index == symbol.index) {
|
||||
break :blk dat;
|
||||
}
|
||||
}
|
||||
unreachable;
|
||||
},
|
||||
else => unreachable,
|
||||
};
|
||||
const final_index = try wasm.getMatchingSegment(object.index, symbol_index);
|
||||
const atom_index = try wasm.createAtom(symbol_index, object.index);
|
||||
try wasm.appendAtomAtIndex(final_index, atom_index);
|
||||
|
||||
const atom = wasm.getAtomPtr(atom_index);
|
||||
atom.size = relocatable_data.size;
|
||||
atom.alignment = relocatable_data.getAlignment(object);
|
||||
atom.code = std.ArrayListUnmanaged(u8).fromOwnedSlice(relocatable_data.data[0..relocatable_data.size]);
|
||||
atom.original_offset = relocatable_data.offset;
|
||||
|
||||
const segment: *Wasm.Segment = &wasm.segments.items[final_index];
|
||||
if (relocatable_data.type == .data) { //code section and custom sections are 1-byte aligned
|
||||
segment.alignment = segment.alignment.max(atom.alignment);
|
||||
}
|
||||
|
||||
if (object.relocations.get(relocatable_data.section_index)) |relocations| {
|
||||
const start = searchRelocStart(relocations, relocatable_data.offset);
|
||||
const len = searchRelocEnd(relocations[start..], relocatable_data.offset + atom.size);
|
||||
atom.relocs = std.ArrayListUnmanaged(types.Relocation).fromOwnedSlice(relocations[start..][0..len]);
|
||||
for (atom.relocs.items) |reloc| {
|
||||
switch (reloc.relocation_type) {
|
||||
.R_WASM_TABLE_INDEX_I32,
|
||||
.R_WASM_TABLE_INDEX_I64,
|
||||
.R_WASM_TABLE_INDEX_SLEB,
|
||||
.R_WASM_TABLE_INDEX_SLEB64,
|
||||
=> {
|
||||
try wasm.function_table.put(gpa, .{
|
||||
.file = object.index,
|
||||
.index = @enumFromInt(reloc.index),
|
||||
}, 0);
|
||||
},
|
||||
.R_WASM_GLOBAL_INDEX_I32,
|
||||
.R_WASM_GLOBAL_INDEX_LEB,
|
||||
=> {
|
||||
const sym = object.symtable[reloc.index];
|
||||
if (sym.tag != .global) {
|
||||
try wasm.got_symbols.append(gpa, .{ .file = object.index, .index = @enumFromInt(reloc.index) });
|
||||
}
|
||||
},
|
||||
else => {},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return atom_index;
|
||||
}
|
||||
|
||||
fn searchRelocStart(relocs: []const types.Relocation, address: u32) usize {
|
||||
var min: usize = 0;
|
||||
var max: usize = relocs.len;
|
||||
while (min < max) {
|
||||
const index = (min + max) / 2;
|
||||
const curr = relocs[index];
|
||||
if (curr.offset < address) {
|
||||
min = index + 1;
|
||||
} else {
|
||||
max = index;
|
||||
}
|
||||
}
|
||||
return min;
|
||||
}
|
||||
|
||||
fn searchRelocEnd(relocs: []const types.Relocation, address: u32) usize {
|
||||
for (relocs, 0..relocs.len) |reloc, index| {
|
||||
if (reloc.offset > address) {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
return relocs.len;
|
||||
}
|
||||
|
||||
@ -206,5 +206,4 @@ pub fn format(symbol: Symbol, comptime fmt: []const u8, options: std.fmt.FormatO
|
||||
}
|
||||
|
||||
const std = @import("std");
|
||||
const types = @import("types.zig");
|
||||
const Symbol = @This();
|
||||
|
||||
@ -4,8 +4,6 @@
|
||||
//! Think about this as fake in-memory Object file for the Zig module.
|
||||
|
||||
path: []const u8,
|
||||
/// Index within the list of relocatable objects of the linker driver.
|
||||
index: File.Index,
|
||||
/// Map of all `Nav` that are currently alive.
|
||||
/// Each index maps to the corresponding `NavInfo`.
|
||||
navs: std.AutoHashMapUnmanaged(InternPool.Nav.Index, NavInfo) = .empty,
|
||||
@ -16,8 +14,8 @@ func_types: std.ArrayListUnmanaged(std.wasm.Type) = .empty,
|
||||
functions: std.ArrayListUnmanaged(std.wasm.Func) = .empty,
|
||||
/// List of indexes pointing to an entry within the `functions` list which has been removed.
|
||||
functions_free_list: std.ArrayListUnmanaged(u32) = .empty,
|
||||
/// Map of symbol locations, represented by its `types.Import`.
|
||||
imports: std.AutoHashMapUnmanaged(Symbol.Index, types.Import) = .empty,
|
||||
/// Map of symbol locations, represented by its `Wasm.Import`.
|
||||
imports: std.AutoHashMapUnmanaged(Symbol.Index, Wasm.Import) = .empty,
|
||||
/// List of WebAssembly globals.
|
||||
globals: std.ArrayListUnmanaged(std.wasm.Global) = .empty,
|
||||
/// Mapping between an `Atom` and its type index representing the Wasm
|
||||
@ -30,7 +28,7 @@ global_syms: std.AutoHashMapUnmanaged(u32, Symbol.Index) = .empty,
|
||||
/// List of symbol indexes which are free to be used.
|
||||
symbols_free_list: std.ArrayListUnmanaged(Symbol.Index) = .empty,
|
||||
/// Extra metadata about the linking section, such as alignment of segments and their name.
|
||||
segment_info: std.ArrayListUnmanaged(types.Segment) = .empty,
|
||||
segment_info: std.ArrayListUnmanaged(Wasm.NamedSegment) = .empty,
|
||||
/// List of indexes which contain a free slot in the `segment_info` list.
|
||||
segment_free_list: std.ArrayListUnmanaged(u32) = .empty,
|
||||
/// File encapsulated string table, used to deduplicate strings within the generated file.
|
||||
@ -117,39 +115,39 @@ const NavInfo = struct {
|
||||
};
|
||||
|
||||
/// Initializes the `ZigObject` with initial symbols.
|
||||
pub fn init(zig_object: *ZigObject, wasm_file: *Wasm) !void {
|
||||
pub fn init(zig_object: *ZigObject, wasm: *Wasm) !void {
|
||||
// Initialize an undefined global with the name __stack_pointer. Codegen will use
|
||||
// this to generate relocations when moving the stack pointer. This symbol will be
|
||||
// resolved automatically by the final linking stage.
|
||||
try zig_object.createStackPointer(wasm_file);
|
||||
try zig_object.createStackPointer(wasm);
|
||||
|
||||
// TODO: Initialize debug information when we reimplement Dwarf support.
|
||||
}
|
||||
|
||||
fn createStackPointer(zig_object: *ZigObject, wasm_file: *Wasm) !void {
|
||||
const gpa = wasm_file.base.comp.gpa;
|
||||
fn createStackPointer(zig_object: *ZigObject, wasm: *Wasm) !void {
|
||||
const gpa = wasm.base.comp.gpa;
|
||||
const sym_index = try zig_object.getGlobalSymbol(gpa, "__stack_pointer");
|
||||
const sym = zig_object.symbol(sym_index);
|
||||
sym.index = zig_object.imported_globals_count;
|
||||
sym.tag = .global;
|
||||
const is_wasm32 = wasm_file.base.comp.root_mod.resolved_target.result.cpu.arch == .wasm32;
|
||||
const is_wasm32 = wasm.base.comp.root_mod.resolved_target.result.cpu.arch == .wasm32;
|
||||
try zig_object.imports.putNoClobber(gpa, sym_index, .{
|
||||
.name = sym.name,
|
||||
.module_name = try zig_object.string_table.insert(gpa, wasm_file.host_name),
|
||||
.module_name = try zig_object.string_table.insert(gpa, wasm.host_name),
|
||||
.kind = .{ .global = .{ .valtype = if (is_wasm32) .i32 else .i64, .mutable = true } },
|
||||
});
|
||||
zig_object.imported_globals_count += 1;
|
||||
zig_object.stack_pointer_sym = sym_index;
|
||||
}
|
||||
|
||||
fn symbol(zig_object: *const ZigObject, index: Symbol.Index) *Symbol {
|
||||
pub fn symbol(zig_object: *const ZigObject, index: Symbol.Index) *Symbol {
|
||||
return &zig_object.symbols.items[@intFromEnum(index)];
|
||||
}
|
||||
|
||||
/// Frees and invalidates all memory of the incrementally compiled Zig module.
|
||||
/// It is illegal behavior to access the `ZigObject` after calling `deinit`.
|
||||
pub fn deinit(zig_object: *ZigObject, wasm_file: *Wasm) void {
|
||||
const gpa = wasm_file.base.comp.gpa;
|
||||
pub fn deinit(zig_object: *ZigObject, wasm: *Wasm) void {
|
||||
const gpa = wasm.base.comp.gpa;
|
||||
for (zig_object.segment_info.items) |segment_info| {
|
||||
gpa.free(segment_info.name);
|
||||
}
|
||||
@ -157,9 +155,9 @@ pub fn deinit(zig_object: *ZigObject, wasm_file: *Wasm) void {
|
||||
{
|
||||
var it = zig_object.navs.valueIterator();
|
||||
while (it.next()) |nav_info| {
|
||||
const atom = wasm_file.getAtomPtr(nav_info.atom);
|
||||
const atom = wasm.getAtomPtr(nav_info.atom);
|
||||
for (atom.locals.items) |local_index| {
|
||||
const local_atom = wasm_file.getAtomPtr(local_index);
|
||||
const local_atom = wasm.getAtomPtr(local_index);
|
||||
local_atom.deinit(gpa);
|
||||
}
|
||||
atom.deinit(gpa);
|
||||
@ -168,24 +166,24 @@ pub fn deinit(zig_object: *ZigObject, wasm_file: *Wasm) void {
|
||||
}
|
||||
{
|
||||
for (zig_object.uavs.values()) |atom_index| {
|
||||
const atom = wasm_file.getAtomPtr(atom_index);
|
||||
const atom = wasm.getAtomPtr(atom_index);
|
||||
for (atom.locals.items) |local_index| {
|
||||
const local_atom = wasm_file.getAtomPtr(local_index);
|
||||
const local_atom = wasm.getAtomPtr(local_index);
|
||||
local_atom.deinit(gpa);
|
||||
}
|
||||
atom.deinit(gpa);
|
||||
}
|
||||
}
|
||||
if (zig_object.findGlobalSymbol("__zig_errors_len")) |sym_index| {
|
||||
const atom_index = wasm_file.symbol_atom.get(.{ .file = zig_object.index, .index = sym_index }).?;
|
||||
wasm_file.getAtomPtr(atom_index).deinit(gpa);
|
||||
const atom_index = wasm.symbol_atom.get(.{ .file = .zig_object, .index = sym_index }).?;
|
||||
wasm.getAtomPtr(atom_index).deinit(gpa);
|
||||
}
|
||||
if (wasm_file.symbol_atom.get(.{ .file = zig_object.index, .index = zig_object.error_table_symbol })) |atom_index| {
|
||||
const atom = wasm_file.getAtomPtr(atom_index);
|
||||
if (wasm.symbol_atom.get(.{ .file = .zig_object, .index = zig_object.error_table_symbol })) |atom_index| {
|
||||
const atom = wasm.getAtomPtr(atom_index);
|
||||
atom.deinit(gpa);
|
||||
}
|
||||
for (zig_object.synthetic_functions.items) |atom_index| {
|
||||
const atom = wasm_file.getAtomPtr(atom_index);
|
||||
const atom = wasm.getAtomPtr(atom_index);
|
||||
atom.deinit(gpa);
|
||||
}
|
||||
zig_object.synthetic_functions.deinit(gpa);
|
||||
@ -193,7 +191,7 @@ pub fn deinit(zig_object: *ZigObject, wasm_file: *Wasm) void {
|
||||
ty.deinit(gpa);
|
||||
}
|
||||
if (zig_object.error_names_atom != .null) {
|
||||
const atom = wasm_file.getAtomPtr(zig_object.error_names_atom);
|
||||
const atom = wasm.getAtomPtr(zig_object.error_names_atom);
|
||||
atom.deinit(gpa);
|
||||
}
|
||||
zig_object.global_syms.deinit(gpa);
|
||||
@ -240,7 +238,7 @@ pub fn allocateSymbol(zig_object: *ZigObject, gpa: std.mem.Allocator) !Symbol.In
|
||||
// the file on flush().
|
||||
pub fn updateNav(
|
||||
zig_object: *ZigObject,
|
||||
wasm_file: *Wasm,
|
||||
wasm: *Wasm,
|
||||
pt: Zcu.PerThread,
|
||||
nav_index: InternPool.Nav.Index,
|
||||
) !void {
|
||||
@ -260,19 +258,19 @@ pub fn updateNav(
|
||||
};
|
||||
|
||||
if (nav_init.typeOf(zcu).hasRuntimeBits(zcu)) {
|
||||
const gpa = wasm_file.base.comp.gpa;
|
||||
const atom_index = try zig_object.getOrCreateAtomForNav(wasm_file, pt, nav_index);
|
||||
const atom = wasm_file.getAtomPtr(atom_index);
|
||||
const gpa = wasm.base.comp.gpa;
|
||||
const atom_index = try zig_object.getOrCreateAtomForNav(wasm, pt, nav_index);
|
||||
const atom = wasm.getAtomPtr(atom_index);
|
||||
atom.clear();
|
||||
|
||||
if (is_extern)
|
||||
return zig_object.addOrUpdateImport(wasm_file, nav.name.toSlice(ip), atom.sym_index, lib_name.toSlice(ip), null);
|
||||
return zig_object.addOrUpdateImport(wasm, nav.name.toSlice(ip), atom.sym_index, lib_name.toSlice(ip), null);
|
||||
|
||||
var code_writer = std.ArrayList(u8).init(gpa);
|
||||
defer code_writer.deinit();
|
||||
|
||||
const res = try codegen.generateSymbol(
|
||||
&wasm_file.base,
|
||||
&wasm.base,
|
||||
pt,
|
||||
zcu.navSrcLoc(nav_index),
|
||||
nav_init,
|
||||
@ -288,13 +286,13 @@ pub fn updateNav(
|
||||
},
|
||||
};
|
||||
|
||||
try zig_object.finishUpdateNav(wasm_file, pt, nav_index, code);
|
||||
try zig_object.finishUpdateNav(wasm, pt, nav_index, code);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn updateFunc(
|
||||
zig_object: *ZigObject,
|
||||
wasm_file: *Wasm,
|
||||
wasm: *Wasm,
|
||||
pt: Zcu.PerThread,
|
||||
func_index: InternPool.Index,
|
||||
air: Air,
|
||||
@ -303,14 +301,14 @@ pub fn updateFunc(
|
||||
const zcu = pt.zcu;
|
||||
const gpa = zcu.gpa;
|
||||
const func = pt.zcu.funcInfo(func_index);
|
||||
const atom_index = try zig_object.getOrCreateAtomForNav(wasm_file, pt, func.owner_nav);
|
||||
const atom = wasm_file.getAtomPtr(atom_index);
|
||||
const atom_index = try zig_object.getOrCreateAtomForNav(wasm, pt, func.owner_nav);
|
||||
const atom = wasm.getAtomPtr(atom_index);
|
||||
atom.clear();
|
||||
|
||||
var code_writer = std.ArrayList(u8).init(gpa);
|
||||
defer code_writer.deinit();
|
||||
const result = try codegen.generateFunction(
|
||||
&wasm_file.base,
|
||||
&wasm.base,
|
||||
pt,
|
||||
zcu.navSrcLoc(func.owner_nav),
|
||||
func_index,
|
||||
@ -328,12 +326,12 @@ pub fn updateFunc(
|
||||
},
|
||||
};
|
||||
|
||||
return zig_object.finishUpdateNav(wasm_file, pt, func.owner_nav, code);
|
||||
return zig_object.finishUpdateNav(wasm, pt, func.owner_nav, code);
|
||||
}
|
||||
|
||||
fn finishUpdateNav(
|
||||
zig_object: *ZigObject,
|
||||
wasm_file: *Wasm,
|
||||
wasm: *Wasm,
|
||||
pt: Zcu.PerThread,
|
||||
nav_index: InternPool.Nav.Index,
|
||||
code: []const u8,
|
||||
@ -345,7 +343,7 @@ fn finishUpdateNav(
|
||||
const nav_val = zcu.navValue(nav_index);
|
||||
const nav_info = zig_object.navs.get(nav_index).?;
|
||||
const atom_index = nav_info.atom;
|
||||
const atom = wasm_file.getAtomPtr(atom_index);
|
||||
const atom = wasm.getAtomPtr(atom_index);
|
||||
const sym = zig_object.symbol(atom.sym_index);
|
||||
sym.name = try zig_object.string_table.insert(gpa, nav.fqn.toSlice(ip));
|
||||
try atom.code.appendSlice(gpa, code);
|
||||
@ -376,7 +374,7 @@ fn finishUpdateNav(
|
||||
}
|
||||
break :name ".bss.";
|
||||
};
|
||||
if ((wasm_file.base.isObject() or wasm_file.base.comp.config.import_memory) and
|
||||
if ((wasm.base.isObject() or wasm.base.comp.config.import_memory) and
|
||||
std.mem.startsWith(u8, segment_name, ".bss"))
|
||||
{
|
||||
@memset(atom.code.items, 0);
|
||||
@ -422,7 +420,7 @@ fn createDataSegment(
|
||||
/// The newly created Atom is empty with default fields as specified by `Atom.empty`.
|
||||
pub fn getOrCreateAtomForNav(
|
||||
zig_object: *ZigObject,
|
||||
wasm_file: *Wasm,
|
||||
wasm: *Wasm,
|
||||
pt: Zcu.PerThread,
|
||||
nav_index: InternPool.Nav.Index,
|
||||
) !Atom.Index {
|
||||
@ -431,7 +429,7 @@ pub fn getOrCreateAtomForNav(
|
||||
const gop = try zig_object.navs.getOrPut(gpa, nav_index);
|
||||
if (!gop.found_existing) {
|
||||
const sym_index = try zig_object.allocateSymbol(gpa);
|
||||
gop.value_ptr.* = .{ .atom = try wasm_file.createAtom(sym_index, zig_object.index) };
|
||||
gop.value_ptr.* = .{ .atom = try wasm.createAtom(sym_index, .zig_object) };
|
||||
const nav = ip.getNav(nav_index);
|
||||
const sym = zig_object.symbol(sym_index);
|
||||
sym.name = try zig_object.string_table.insert(gpa, nav.fqn.toSlice(ip));
|
||||
@ -441,13 +439,13 @@ pub fn getOrCreateAtomForNav(
|
||||
|
||||
pub fn lowerUav(
|
||||
zig_object: *ZigObject,
|
||||
wasm_file: *Wasm,
|
||||
wasm: *Wasm,
|
||||
pt: Zcu.PerThread,
|
||||
uav: InternPool.Index,
|
||||
explicit_alignment: InternPool.Alignment,
|
||||
src_loc: Zcu.LazySrcLoc,
|
||||
) !codegen.GenResult {
|
||||
const gpa = wasm_file.base.comp.gpa;
|
||||
const gpa = wasm.base.comp.gpa;
|
||||
const gop = try zig_object.uavs.getOrPut(gpa, uav);
|
||||
if (!gop.found_existing) {
|
||||
var name_buf: [32]u8 = undefined;
|
||||
@ -455,13 +453,13 @@ pub fn lowerUav(
|
||||
@intFromEnum(uav),
|
||||
}) catch unreachable;
|
||||
|
||||
switch (try zig_object.lowerConst(wasm_file, pt, name, Value.fromInterned(uav), src_loc)) {
|
||||
switch (try zig_object.lowerConst(wasm, pt, name, Value.fromInterned(uav), src_loc)) {
|
||||
.ok => |atom_index| zig_object.uavs.values()[gop.index] = atom_index,
|
||||
.fail => |em| return .{ .fail = em },
|
||||
}
|
||||
}
|
||||
|
||||
const atom = wasm_file.getAtomPtr(zig_object.uavs.values()[gop.index]);
|
||||
const atom = wasm.getAtomPtr(zig_object.uavs.values()[gop.index]);
|
||||
atom.alignment = switch (atom.alignment) {
|
||||
.none => explicit_alignment,
|
||||
else => switch (explicit_alignment) {
|
||||
@ -479,25 +477,25 @@ const LowerConstResult = union(enum) {
|
||||
|
||||
fn lowerConst(
|
||||
zig_object: *ZigObject,
|
||||
wasm_file: *Wasm,
|
||||
wasm: *Wasm,
|
||||
pt: Zcu.PerThread,
|
||||
name: []const u8,
|
||||
val: Value,
|
||||
src_loc: Zcu.LazySrcLoc,
|
||||
) !LowerConstResult {
|
||||
const gpa = wasm_file.base.comp.gpa;
|
||||
const zcu = wasm_file.base.comp.zcu.?;
|
||||
const gpa = wasm.base.comp.gpa;
|
||||
const zcu = wasm.base.comp.zcu.?;
|
||||
|
||||
const ty = val.typeOf(zcu);
|
||||
|
||||
// Create and initialize a new local symbol and atom
|
||||
const sym_index = try zig_object.allocateSymbol(gpa);
|
||||
const atom_index = try wasm_file.createAtom(sym_index, zig_object.index);
|
||||
const atom_index = try wasm.createAtom(sym_index, .zig_object);
|
||||
var value_bytes = std.ArrayList(u8).init(gpa);
|
||||
defer value_bytes.deinit();
|
||||
|
||||
const code = code: {
|
||||
const atom = wasm_file.getAtomPtr(atom_index);
|
||||
const atom = wasm.getAtomPtr(atom_index);
|
||||
atom.alignment = ty.abiAlignment(zcu);
|
||||
const segment_name = try std.mem.concat(gpa, u8, &.{ ".rodata.", name });
|
||||
errdefer gpa.free(segment_name);
|
||||
@ -514,7 +512,7 @@ fn lowerConst(
|
||||
};
|
||||
|
||||
const result = try codegen.generateSymbol(
|
||||
&wasm_file.base,
|
||||
&wasm.base,
|
||||
pt,
|
||||
src_loc,
|
||||
val,
|
||||
@ -529,7 +527,7 @@ fn lowerConst(
|
||||
};
|
||||
};
|
||||
|
||||
const atom = wasm_file.getAtomPtr(atom_index);
|
||||
const atom = wasm.getAtomPtr(atom_index);
|
||||
atom.size = @intCast(code.len);
|
||||
try atom.code.appendSlice(gpa, code);
|
||||
return .{ .ok = atom_index };
|
||||
@ -538,7 +536,7 @@ fn lowerConst(
|
||||
/// Returns the symbol index of the error name table.
|
||||
///
|
||||
/// When the symbol does not yet exist, it will create a new one instead.
|
||||
pub fn getErrorTableSymbol(zig_object: *ZigObject, wasm_file: *Wasm, pt: Zcu.PerThread) !Symbol.Index {
|
||||
pub fn getErrorTableSymbol(zig_object: *ZigObject, wasm: *Wasm, pt: Zcu.PerThread) !Symbol.Index {
|
||||
if (zig_object.error_table_symbol != .null) {
|
||||
return zig_object.error_table_symbol;
|
||||
}
|
||||
@ -546,10 +544,10 @@ pub fn getErrorTableSymbol(zig_object: *ZigObject, wasm_file: *Wasm, pt: Zcu.Per
|
||||
// no error was referenced yet, so create a new symbol and atom for it
|
||||
// and then return said symbol's index. The final table will be populated
|
||||
// during `flush` when we know all possible error names.
|
||||
const gpa = wasm_file.base.comp.gpa;
|
||||
const gpa = wasm.base.comp.gpa;
|
||||
const sym_index = try zig_object.allocateSymbol(gpa);
|
||||
const atom_index = try wasm_file.createAtom(sym_index, zig_object.index);
|
||||
const atom = wasm_file.getAtomPtr(atom_index);
|
||||
const atom_index = try wasm.createAtom(sym_index, .zig_object);
|
||||
const atom = wasm.getAtomPtr(atom_index);
|
||||
const slice_ty = Type.slice_const_u8_sentinel_0;
|
||||
atom.alignment = slice_ty.abiAlignment(pt.zcu);
|
||||
|
||||
@ -573,17 +571,17 @@ pub fn getErrorTableSymbol(zig_object: *ZigObject, wasm_file: *Wasm, pt: Zcu.Per
|
||||
///
|
||||
/// This creates a table that consists of pointers and length to each error name.
|
||||
/// The table is what is being pointed to within the runtime bodies that are generated.
|
||||
fn populateErrorNameTable(zig_object: *ZigObject, wasm_file: *Wasm, tid: Zcu.PerThread.Id) !void {
|
||||
fn populateErrorNameTable(zig_object: *ZigObject, wasm: *Wasm, tid: Zcu.PerThread.Id) !void {
|
||||
if (zig_object.error_table_symbol == .null) return;
|
||||
const gpa = wasm_file.base.comp.gpa;
|
||||
const atom_index = wasm_file.symbol_atom.get(.{ .file = zig_object.index, .index = zig_object.error_table_symbol }).?;
|
||||
const gpa = wasm.base.comp.gpa;
|
||||
const atom_index = wasm.symbol_atom.get(.{ .file = .zig_object, .index = zig_object.error_table_symbol }).?;
|
||||
|
||||
// Rather than creating a symbol for each individual error name,
|
||||
// we create a symbol for the entire region of error names. We then calculate
|
||||
// the pointers into the list using addends which are appended to the relocation.
|
||||
const names_sym_index = try zig_object.allocateSymbol(gpa);
|
||||
const names_atom_index = try wasm_file.createAtom(names_sym_index, zig_object.index);
|
||||
const names_atom = wasm_file.getAtomPtr(names_atom_index);
|
||||
const names_atom_index = try wasm.createAtom(names_sym_index, .zig_object);
|
||||
const names_atom = wasm.getAtomPtr(names_atom_index);
|
||||
names_atom.alignment = .@"1";
|
||||
const sym_name = try zig_object.string_table.insert(gpa, "__zig_err_names");
|
||||
const segment_name = try gpa.dupe(u8, ".rodata.__zig_err_names");
|
||||
@ -600,9 +598,9 @@ fn populateErrorNameTable(zig_object: *ZigObject, wasm_file: *Wasm, tid: Zcu.Per
|
||||
|
||||
// Addend for each relocation to the table
|
||||
var addend: u32 = 0;
|
||||
const pt: Zcu.PerThread = .{ .zcu = wasm_file.base.comp.zcu.?, .tid = tid };
|
||||
const pt: Zcu.PerThread = .{ .zcu = wasm.base.comp.zcu.?, .tid = tid };
|
||||
const slice_ty = Type.slice_const_u8_sentinel_0;
|
||||
const atom = wasm_file.getAtomPtr(atom_index);
|
||||
const atom = wasm.getAtomPtr(atom_index);
|
||||
{
|
||||
// TODO: remove this unreachable entry
|
||||
try atom.code.appendNTimes(gpa, 0, 4);
|
||||
@ -646,7 +644,7 @@ fn populateErrorNameTable(zig_object: *ZigObject, wasm_file: *Wasm, tid: Zcu.Per
|
||||
/// In all other cases, a data-symbol will be created instead.
|
||||
pub fn addOrUpdateImport(
|
||||
zig_object: *ZigObject,
|
||||
wasm_file: *Wasm,
|
||||
wasm: *Wasm,
|
||||
/// Name of the import
|
||||
name: []const u8,
|
||||
/// Symbol index that is external
|
||||
@ -658,7 +656,7 @@ pub fn addOrUpdateImport(
|
||||
/// is asserted instead.
|
||||
type_index: ?u32,
|
||||
) !void {
|
||||
const gpa = wasm_file.base.comp.gpa;
|
||||
const gpa = wasm.base.comp.gpa;
|
||||
std.debug.assert(symbol_index != .null);
|
||||
// For the import name, we use the decl's name, rather than the fully qualified name
|
||||
// Also mangle the name when the lib name is set and not equal to "C" so imports with the same
|
||||
@ -682,7 +680,7 @@ pub fn addOrUpdateImport(
|
||||
|
||||
if (type_index) |ty_index| {
|
||||
const gop = try zig_object.imports.getOrPut(gpa, symbol_index);
|
||||
const module_name = if (lib_name) |l_name| l_name else wasm_file.host_name;
|
||||
const module_name = if (lib_name) |l_name| l_name else wasm.host_name;
|
||||
if (!gop.found_existing) {
|
||||
zig_object.imported_functions_count += 1;
|
||||
}
|
||||
@ -733,7 +731,7 @@ pub fn getGlobalSymbol(zig_object: *ZigObject, gpa: std.mem.Allocator, name: []c
|
||||
/// Returns the given pointer address
|
||||
pub fn getNavVAddr(
|
||||
zig_object: *ZigObject,
|
||||
wasm_file: *Wasm,
|
||||
wasm: *Wasm,
|
||||
pt: Zcu.PerThread,
|
||||
nav_index: InternPool.Nav.Index,
|
||||
reloc_info: link.File.RelocInfo,
|
||||
@ -744,12 +742,12 @@ pub fn getNavVAddr(
|
||||
const nav = ip.getNav(nav_index);
|
||||
const target = &zcu.navFileScope(nav_index).mod.resolved_target.result;
|
||||
|
||||
const target_atom_index = try zig_object.getOrCreateAtomForNav(wasm_file, pt, nav_index);
|
||||
const target_atom = wasm_file.getAtom(target_atom_index);
|
||||
const target_atom_index = try zig_object.getOrCreateAtomForNav(wasm, pt, nav_index);
|
||||
const target_atom = wasm.getAtom(target_atom_index);
|
||||
const target_symbol_index = @intFromEnum(target_atom.sym_index);
|
||||
switch (ip.indexToKey(nav.status.resolved.val)) {
|
||||
.@"extern" => |@"extern"| try zig_object.addOrUpdateImport(
|
||||
wasm_file,
|
||||
wasm,
|
||||
nav.name.toSlice(ip),
|
||||
target_atom.sym_index,
|
||||
@"extern".lib_name.toSlice(ip),
|
||||
@ -759,11 +757,11 @@ pub fn getNavVAddr(
|
||||
}
|
||||
|
||||
std.debug.assert(reloc_info.parent.atom_index != 0);
|
||||
const atom_index = wasm_file.symbol_atom.get(.{
|
||||
.file = zig_object.index,
|
||||
const atom_index = wasm.symbol_atom.get(.{
|
||||
.file = .zig_object,
|
||||
.index = @enumFromInt(reloc_info.parent.atom_index),
|
||||
}).?;
|
||||
const atom = wasm_file.getAtomPtr(atom_index);
|
||||
const atom = wasm.getAtomPtr(atom_index);
|
||||
const is_wasm32 = target.cpu.arch == .wasm32;
|
||||
if (ip.isFunctionType(ip.getNav(nav_index).typeOf(ip))) {
|
||||
std.debug.assert(reloc_info.addend == 0); // addend not allowed for function relocations
|
||||
@ -790,22 +788,22 @@ pub fn getNavVAddr(
|
||||
|
||||
pub fn getUavVAddr(
|
||||
zig_object: *ZigObject,
|
||||
wasm_file: *Wasm,
|
||||
wasm: *Wasm,
|
||||
uav: InternPool.Index,
|
||||
reloc_info: link.File.RelocInfo,
|
||||
) !u64 {
|
||||
const gpa = wasm_file.base.comp.gpa;
|
||||
const target = wasm_file.base.comp.root_mod.resolved_target.result;
|
||||
const gpa = wasm.base.comp.gpa;
|
||||
const target = wasm.base.comp.root_mod.resolved_target.result;
|
||||
const atom_index = zig_object.uavs.get(uav).?;
|
||||
const target_symbol_index = @intFromEnum(wasm_file.getAtom(atom_index).sym_index);
|
||||
const target_symbol_index = @intFromEnum(wasm.getAtom(atom_index).sym_index);
|
||||
|
||||
const parent_atom_index = wasm_file.symbol_atom.get(.{
|
||||
.file = zig_object.index,
|
||||
const parent_atom_index = wasm.symbol_atom.get(.{
|
||||
.file = .zig_object,
|
||||
.index = @enumFromInt(reloc_info.parent.atom_index),
|
||||
}).?;
|
||||
const parent_atom = wasm_file.getAtomPtr(parent_atom_index);
|
||||
const parent_atom = wasm.getAtomPtr(parent_atom_index);
|
||||
const is_wasm32 = target.cpu.arch == .wasm32;
|
||||
const zcu = wasm_file.base.comp.zcu.?;
|
||||
const zcu = wasm.base.comp.zcu.?;
|
||||
const ty = Type.fromInterned(zcu.intern_pool.typeOf(uav));
|
||||
if (ty.zigTypeTag(zcu) == .@"fn") {
|
||||
std.debug.assert(reloc_info.addend == 0); // addend not allowed for function relocations
|
||||
@ -832,11 +830,11 @@ pub fn getUavVAddr(
|
||||
|
||||
pub fn deleteExport(
|
||||
zig_object: *ZigObject,
|
||||
wasm_file: *Wasm,
|
||||
wasm: *Wasm,
|
||||
exported: Zcu.Exported,
|
||||
name: InternPool.NullTerminatedString,
|
||||
) void {
|
||||
const zcu = wasm_file.base.comp.zcu.?;
|
||||
const zcu = wasm.base.comp.zcu.?;
|
||||
const nav_index = switch (exported) {
|
||||
.nav => |nav_index| nav_index,
|
||||
.uav => @panic("TODO: implement Wasm linker code for exporting a constant value"),
|
||||
@ -846,15 +844,15 @@ pub fn deleteExport(
|
||||
const sym = zig_object.symbol(sym_index);
|
||||
nav_info.deleteExport(sym_index);
|
||||
std.debug.assert(zig_object.global_syms.remove(sym.name));
|
||||
std.debug.assert(wasm_file.symbol_atom.remove(.{ .file = zig_object.index, .index = sym_index }));
|
||||
zig_object.symbols_free_list.append(wasm_file.base.comp.gpa, sym_index) catch {};
|
||||
std.debug.assert(wasm.symbol_atom.remove(.{ .file = .zig_object, .index = sym_index }));
|
||||
zig_object.symbols_free_list.append(wasm.base.comp.gpa, sym_index) catch {};
|
||||
sym.tag = .dead;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn updateExports(
|
||||
zig_object: *ZigObject,
|
||||
wasm_file: *Wasm,
|
||||
wasm: *Wasm,
|
||||
pt: Zcu.PerThread,
|
||||
exported: Zcu.Exported,
|
||||
export_indices: []const u32,
|
||||
@ -869,10 +867,10 @@ pub fn updateExports(
|
||||
},
|
||||
};
|
||||
const nav = ip.getNav(nav_index);
|
||||
const atom_index = try zig_object.getOrCreateAtomForNav(wasm_file, pt, nav_index);
|
||||
const atom_index = try zig_object.getOrCreateAtomForNav(wasm, pt, nav_index);
|
||||
const nav_info = zig_object.navs.getPtr(nav_index).?;
|
||||
const atom = wasm_file.getAtom(atom_index);
|
||||
const atom_sym = atom.symbolLoc().getSymbol(wasm_file).*;
|
||||
const atom = wasm.getAtom(atom_index);
|
||||
const atom_sym = wasm.symbolLocSymbol(atom.symbolLoc()).*;
|
||||
const gpa = zcu.gpa;
|
||||
log.debug("Updating exports for decl '{}'", .{nav.name.fmt(ip)});
|
||||
|
||||
@ -926,17 +924,17 @@ pub fn updateExports(
|
||||
}
|
||||
log.debug(" with name '{s}' - {}", .{ export_string, sym });
|
||||
try zig_object.global_syms.put(gpa, export_name, sym_index);
|
||||
try wasm_file.symbol_atom.put(gpa, .{ .file = zig_object.index, .index = sym_index }, atom_index);
|
||||
try wasm.symbol_atom.put(gpa, .{ .file = .zig_object, .index = sym_index }, atom_index);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn freeNav(zig_object: *ZigObject, wasm_file: *Wasm, nav_index: InternPool.Nav.Index) void {
|
||||
const gpa = wasm_file.base.comp.gpa;
|
||||
const zcu = wasm_file.base.comp.zcu.?;
|
||||
pub fn freeNav(zig_object: *ZigObject, wasm: *Wasm, nav_index: InternPool.Nav.Index) void {
|
||||
const gpa = wasm.base.comp.gpa;
|
||||
const zcu = wasm.base.comp.zcu.?;
|
||||
const ip = &zcu.intern_pool;
|
||||
const nav_info = zig_object.navs.getPtr(nav_index).?;
|
||||
const atom_index = nav_info.atom;
|
||||
const atom = wasm_file.getAtomPtr(atom_index);
|
||||
const atom = wasm.getAtomPtr(atom_index);
|
||||
zig_object.symbols_free_list.append(gpa, atom.sym_index) catch {};
|
||||
for (nav_info.exports.items) |exp_sym_index| {
|
||||
const exp_sym = zig_object.symbol(exp_sym_index);
|
||||
@ -947,11 +945,11 @@ pub fn freeNav(zig_object: *ZigObject, wasm_file: *Wasm, nav_index: InternPool.N
|
||||
std.debug.assert(zig_object.navs.remove(nav_index));
|
||||
const sym = &zig_object.symbols.items[atom.sym_index];
|
||||
for (atom.locals.items) |local_atom_index| {
|
||||
const local_atom = wasm_file.getAtom(local_atom_index);
|
||||
const local_atom = wasm.getAtom(local_atom_index);
|
||||
const local_symbol = &zig_object.symbols.items[local_atom.sym_index];
|
||||
std.debug.assert(local_symbol.tag == .data);
|
||||
zig_object.symbols_free_list.append(gpa, local_atom.sym_index) catch {};
|
||||
std.debug.assert(wasm_file.symbol_atom.remove(local_atom.symbolLoc()));
|
||||
std.debug.assert(wasm.symbol_atom.remove(local_atom.symbolLoc()));
|
||||
local_symbol.tag = .dead; // also for any local symbol
|
||||
const segment = &zig_object.segment_info.items[local_atom.sym_index];
|
||||
gpa.free(segment.name);
|
||||
@ -962,7 +960,7 @@ pub fn freeNav(zig_object: *ZigObject, wasm_file: *Wasm, nav_index: InternPool.N
|
||||
if (ip.indexToKey(nav_val) == .@"extern") {
|
||||
std.debug.assert(zig_object.imports.remove(atom.sym_index));
|
||||
}
|
||||
std.debug.assert(wasm_file.symbol_atom.remove(atom.symbolLoc()));
|
||||
std.debug.assert(wasm.symbol_atom.remove(atom.symbolLoc()));
|
||||
|
||||
// if (wasm.dwarf) |*dwarf| {
|
||||
// dwarf.freeDecl(decl_index);
|
||||
@ -1014,15 +1012,15 @@ pub fn putOrGetFuncType(zig_object: *ZigObject, gpa: std.mem.Allocator, func_typ
|
||||
|
||||
/// Generates an atom containing the global error set' size.
|
||||
/// This will only be generated if the symbol exists.
|
||||
fn setupErrorsLen(zig_object: *ZigObject, wasm_file: *Wasm) !void {
|
||||
const gpa = wasm_file.base.comp.gpa;
|
||||
fn setupErrorsLen(zig_object: *ZigObject, wasm: *Wasm) !void {
|
||||
const gpa = wasm.base.comp.gpa;
|
||||
const sym_index = zig_object.findGlobalSymbol("__zig_errors_len") orelse return;
|
||||
|
||||
const errors_len = 1 + wasm_file.base.comp.zcu.?.intern_pool.global_error_set.getNamesFromMainThread().len;
|
||||
const errors_len = 1 + wasm.base.comp.zcu.?.intern_pool.global_error_set.getNamesFromMainThread().len;
|
||||
// overwrite existing atom if it already exists (maybe the error set has increased)
|
||||
// if not, allocate a new atom.
|
||||
const atom_index = if (wasm_file.symbol_atom.get(.{ .file = zig_object.index, .index = sym_index })) |index| blk: {
|
||||
const atom = wasm_file.getAtomPtr(index);
|
||||
const atom_index = if (wasm.symbol_atom.get(.{ .file = .zig_object, .index = sym_index })) |index| blk: {
|
||||
const atom = wasm.getAtomPtr(index);
|
||||
atom.prev = .null;
|
||||
atom.deinit(gpa);
|
||||
break :blk index;
|
||||
@ -1036,10 +1034,10 @@ fn setupErrorsLen(zig_object: *ZigObject, wasm_file: *Wasm) !void {
|
||||
sym.tag = .data;
|
||||
const segment_name = try gpa.dupe(u8, ".rodata.__zig_errors_len");
|
||||
sym.index = try zig_object.createDataSegment(gpa, segment_name, .@"2");
|
||||
break :idx try wasm_file.createAtom(sym_index, zig_object.index);
|
||||
break :idx try wasm.createAtom(sym_index, .zig_object);
|
||||
};
|
||||
|
||||
const atom = wasm_file.getAtomPtr(atom_index);
|
||||
const atom = wasm.getAtomPtr(atom_index);
|
||||
atom.code.clearRetainingCapacity();
|
||||
atom.sym_index = sym_index;
|
||||
atom.size = 2;
|
||||
@ -1073,15 +1071,15 @@ pub fn initDebugSections(zig_object: *ZigObject) !void {
|
||||
/// From a given index variable, creates a new debug section.
|
||||
/// This initializes the index, appends a new segment,
|
||||
/// and finally, creates a managed `Atom`.
|
||||
pub fn createDebugSectionForIndex(zig_object: *ZigObject, wasm_file: *Wasm, index: *?u32, name: []const u8) !Atom.Index {
|
||||
const gpa = wasm_file.base.comp.gpa;
|
||||
pub fn createDebugSectionForIndex(zig_object: *ZigObject, wasm: *Wasm, index: *?u32, name: []const u8) !Atom.Index {
|
||||
const gpa = wasm.base.comp.gpa;
|
||||
const new_index: u32 = @intCast(zig_object.segments.items.len);
|
||||
index.* = new_index;
|
||||
try zig_object.appendDummySegment();
|
||||
|
||||
const sym_index = try zig_object.allocateSymbol(gpa);
|
||||
const atom_index = try wasm_file.createAtom(sym_index, zig_object.index);
|
||||
const atom = wasm_file.getAtomPtr(atom_index);
|
||||
const atom_index = try wasm.createAtom(sym_index, .zig_object);
|
||||
const atom = wasm.getAtomPtr(atom_index);
|
||||
zig_object.symbols.items[sym_index] = .{
|
||||
.tag = .section,
|
||||
.name = try zig_object.string_table.put(gpa, name),
|
||||
@ -1148,13 +1146,13 @@ pub fn storeDeclType(zig_object: *ZigObject, gpa: std.mem.Allocator, nav_index:
|
||||
/// The symbols in ZigObject are already represented by an atom as we need to store its data.
|
||||
/// So rather than creating a new Atom and returning its index, we use this opportunity to scan
|
||||
/// its relocations and create any GOT symbols or function table indexes it may require.
|
||||
pub fn parseSymbolIntoAtom(zig_object: *ZigObject, wasm_file: *Wasm, index: Symbol.Index) !Atom.Index {
|
||||
const gpa = wasm_file.base.comp.gpa;
|
||||
const loc: Wasm.SymbolLoc = .{ .file = zig_object.index, .index = index };
|
||||
const atom_index = wasm_file.symbol_atom.get(loc).?;
|
||||
const final_index = try wasm_file.getMatchingSegment(zig_object.index, index);
|
||||
try wasm_file.appendAtomAtIndex(final_index, atom_index);
|
||||
const atom = wasm_file.getAtom(atom_index);
|
||||
pub fn parseSymbolIntoAtom(zig_object: *ZigObject, wasm: *Wasm, index: Symbol.Index) !Atom.Index {
|
||||
const gpa = wasm.base.comp.gpa;
|
||||
const loc: Wasm.SymbolLoc = .{ .file = .zig_object, .index = index };
|
||||
const atom_index = wasm.symbol_atom.get(loc).?;
|
||||
const final_index = try wasm.getMatchingSegment(.zig_object, index);
|
||||
try wasm.appendAtomAtIndex(final_index, atom_index);
|
||||
const atom = wasm.getAtom(atom_index);
|
||||
for (atom.relocs.items) |reloc| {
|
||||
const reloc_index: Symbol.Index = @enumFromInt(reloc.index);
|
||||
switch (reloc.relocation_type) {
|
||||
@ -1163,8 +1161,8 @@ pub fn parseSymbolIntoAtom(zig_object: *ZigObject, wasm_file: *Wasm, index: Symb
|
||||
.R_WASM_TABLE_INDEX_SLEB,
|
||||
.R_WASM_TABLE_INDEX_SLEB64,
|
||||
=> {
|
||||
try wasm_file.function_table.put(gpa, .{
|
||||
.file = zig_object.index,
|
||||
try wasm.function_table.put(gpa, .{
|
||||
.file = .zig_object,
|
||||
.index = reloc_index,
|
||||
}, 0);
|
||||
},
|
||||
@ -1173,8 +1171,8 @@ pub fn parseSymbolIntoAtom(zig_object: *ZigObject, wasm_file: *Wasm, index: Symb
|
||||
=> {
|
||||
const sym = zig_object.symbol(reloc_index);
|
||||
if (sym.tag != .global) {
|
||||
try wasm_file.got_symbols.append(gpa, .{
|
||||
.file = zig_object.index,
|
||||
try wasm.got_symbols.append(gpa, .{
|
||||
.file = .zig_object,
|
||||
.index = reloc_index,
|
||||
});
|
||||
}
|
||||
@ -1189,13 +1187,13 @@ pub fn parseSymbolIntoAtom(zig_object: *ZigObject, wasm_file: *Wasm, index: Symb
|
||||
/// Returns the symbol index of the new function.
|
||||
pub fn createFunction(
|
||||
zig_object: *ZigObject,
|
||||
wasm_file: *Wasm,
|
||||
wasm: *Wasm,
|
||||
symbol_name: []const u8,
|
||||
func_ty: std.wasm.Type,
|
||||
function_body: *std.ArrayList(u8),
|
||||
relocations: *std.ArrayList(types.Relocation),
|
||||
relocations: *std.ArrayList(Wasm.Relocation),
|
||||
) !Symbol.Index {
|
||||
const gpa = wasm_file.base.comp.gpa;
|
||||
const gpa = wasm.base.comp.gpa;
|
||||
const sym_index = try zig_object.allocateSymbol(gpa);
|
||||
const sym = zig_object.symbol(sym_index);
|
||||
sym.tag = .function;
|
||||
@ -1203,8 +1201,8 @@ pub fn createFunction(
|
||||
const type_index = try zig_object.putOrGetFuncType(gpa, func_ty);
|
||||
sym.index = try zig_object.appendFunction(gpa, .{ .type_index = type_index });
|
||||
|
||||
const atom_index = try wasm_file.createAtom(sym_index, zig_object.index);
|
||||
const atom = wasm_file.getAtomPtr(atom_index);
|
||||
const atom_index = try wasm.createAtom(sym_index, .zig_object);
|
||||
const atom = wasm.getAtomPtr(atom_index);
|
||||
atom.size = @intCast(function_body.items.len);
|
||||
atom.code = function_body.moveToUnmanaged();
|
||||
atom.relocs = relocations.moveToUnmanaged();
|
||||
@ -1227,9 +1225,9 @@ fn appendFunction(zig_object: *ZigObject, gpa: std.mem.Allocator, func: std.wasm
|
||||
return index;
|
||||
}
|
||||
|
||||
pub fn flushModule(zig_object: *ZigObject, wasm_file: *Wasm, tid: Zcu.PerThread.Id) !void {
|
||||
try zig_object.populateErrorNameTable(wasm_file, tid);
|
||||
try zig_object.setupErrorsLen(wasm_file);
|
||||
pub fn flushModule(zig_object: *ZigObject, wasm: *Wasm, tid: Zcu.PerThread.Id) !void {
|
||||
try zig_object.populateErrorNameTable(wasm, tid);
|
||||
try zig_object.setupErrorsLen(wasm);
|
||||
}
|
||||
|
||||
const build_options = @import("build_options");
|
||||
@ -1238,12 +1236,10 @@ const codegen = @import("../../codegen.zig");
|
||||
const link = @import("../../link.zig");
|
||||
const log = std.log.scoped(.zig_object);
|
||||
const std = @import("std");
|
||||
const types = @import("types.zig");
|
||||
|
||||
const Air = @import("../../Air.zig");
|
||||
const Atom = @import("Atom.zig");
|
||||
const Atom = Wasm.Atom;
|
||||
const Dwarf = @import("../Dwarf.zig");
|
||||
const File = @import("file.zig").File;
|
||||
const InternPool = @import("../../InternPool.zig");
|
||||
const Liveness = @import("../../Liveness.zig");
|
||||
const Zcu = @import("../../Zcu.zig");
|
||||
|
||||
@ -1,132 +0,0 @@
|
||||
pub const File = union(enum) {
|
||||
zig_object: *ZigObject,
|
||||
object: *Object,
|
||||
|
||||
pub const Index = enum(u16) {
|
||||
null = std.math.maxInt(u16),
|
||||
_,
|
||||
};
|
||||
|
||||
pub fn path(file: File) []const u8 {
|
||||
return switch (file) {
|
||||
inline else => |obj| obj.path,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn segmentInfo(file: File) []const types.Segment {
|
||||
return switch (file) {
|
||||
.zig_object => |obj| obj.segment_info.items,
|
||||
.object => |obj| obj.segment_info,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn symbol(file: File, index: Symbol.Index) *Symbol {
|
||||
return switch (file) {
|
||||
.zig_object => |obj| &obj.symbols.items[@intFromEnum(index)],
|
||||
.object => |obj| &obj.symtable[@intFromEnum(index)],
|
||||
};
|
||||
}
|
||||
|
||||
pub fn symbols(file: File) []const Symbol {
|
||||
return switch (file) {
|
||||
.zig_object => |obj| obj.symbols.items,
|
||||
.object => |obj| obj.symtable,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn symbolName(file: File, index: Symbol.Index) []const u8 {
|
||||
switch (file) {
|
||||
.zig_object => |obj| {
|
||||
const sym = obj.symbols.items[@intFromEnum(index)];
|
||||
return obj.string_table.get(sym.name).?;
|
||||
},
|
||||
.object => |obj| {
|
||||
const sym = obj.symtable[@intFromEnum(index)];
|
||||
return obj.string_table.get(sym.name);
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parseSymbolIntoAtom(file: File, wasm_file: *Wasm, index: Symbol.Index) !AtomIndex {
|
||||
return switch (file) {
|
||||
inline else => |obj| obj.parseSymbolIntoAtom(wasm_file, index),
|
||||
};
|
||||
}
|
||||
|
||||
/// For a given symbol index, find its corresponding import.
|
||||
/// Asserts import exists.
|
||||
pub fn import(file: File, symbol_index: Symbol.Index) types.Import {
|
||||
return switch (file) {
|
||||
.zig_object => |obj| obj.imports.get(symbol_index).?,
|
||||
.object => |obj| obj.findImport(obj.symtable[@intFromEnum(symbol_index)]),
|
||||
};
|
||||
}
|
||||
|
||||
/// For a given offset, returns its string value.
|
||||
/// Asserts string exists in the object string table.
|
||||
pub fn string(file: File, offset: u32) []const u8 {
|
||||
return switch (file) {
|
||||
.zig_object => |obj| obj.string_table.get(offset).?,
|
||||
.object => |obj| obj.string_table.get(offset),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn importedGlobals(file: File) u32 {
|
||||
return switch (file) {
|
||||
inline else => |obj| obj.imported_globals_count,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn importedFunctions(file: File) u32 {
|
||||
return switch (file) {
|
||||
inline else => |obj| obj.imported_functions_count,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn importedTables(file: File) u32 {
|
||||
return switch (file) {
|
||||
inline else => |obj| obj.imported_tables_count,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn function(file: File, sym_index: Symbol.Index) std.wasm.Func {
|
||||
switch (file) {
|
||||
.zig_object => |obj| {
|
||||
const sym = obj.symbols.items[@intFromEnum(sym_index)];
|
||||
return obj.functions.items[sym.index];
|
||||
},
|
||||
.object => |obj| {
|
||||
const sym = obj.symtable[@intFromEnum(sym_index)];
|
||||
return obj.functions[sym.index - obj.imported_functions_count];
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn globals(file: File) []const std.wasm.Global {
|
||||
return switch (file) {
|
||||
.zig_object => |obj| obj.globals.items,
|
||||
.object => |obj| obj.globals,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn funcTypes(file: File) []const std.wasm.Type {
|
||||
return switch (file) {
|
||||
.zig_object => |obj| obj.func_types.items,
|
||||
.object => |obj| obj.func_types,
|
||||
};
|
||||
}
|
||||
|
||||
pub const Entry = union(enum) {
|
||||
zig_object: ZigObject,
|
||||
object: Object,
|
||||
};
|
||||
};
|
||||
|
||||
const std = @import("std");
|
||||
const types = @import("types.zig");
|
||||
|
||||
const AtomIndex = @import("Atom.zig").Index;
|
||||
const Object = @import("Object.zig");
|
||||
const Symbol = @import("Symbol.zig");
|
||||
const Wasm = @import("../Wasm.zig");
|
||||
const ZigObject = @import("ZigObject.zig");
|
||||
@ -1,267 +0,0 @@
|
||||
//! This file contains all constants and related to wasm's object format.
|
||||
|
||||
const std = @import("std");
|
||||
|
||||
pub const Relocation = struct {
|
||||
/// Represents the type of the `Relocation`
|
||||
relocation_type: RelocationType,
|
||||
/// Offset of the value to rewrite relative to the relevant section's contents.
|
||||
/// When `offset` is zero, its position is immediately after the id and size of the section.
|
||||
offset: u32,
|
||||
/// The index of the symbol used.
|
||||
/// When the type is `R_WASM_TYPE_INDEX_LEB`, it represents the index of the type.
|
||||
index: u32,
|
||||
/// Addend to add to the address.
|
||||
/// This field is only non-zero for `R_WASM_MEMORY_ADDR_*`, `R_WASM_FUNCTION_OFFSET_I32` and `R_WASM_SECTION_OFFSET_I32`.
|
||||
addend: i32 = 0,
|
||||
|
||||
/// All possible relocation types currently existing.
|
||||
/// This enum is exhaustive as the spec is WIP and new types
|
||||
/// can be added which means that a generated binary will be invalid,
|
||||
/// so instead we will show an error in such cases.
|
||||
pub const RelocationType = enum(u8) {
|
||||
R_WASM_FUNCTION_INDEX_LEB = 0,
|
||||
R_WASM_TABLE_INDEX_SLEB = 1,
|
||||
R_WASM_TABLE_INDEX_I32 = 2,
|
||||
R_WASM_MEMORY_ADDR_LEB = 3,
|
||||
R_WASM_MEMORY_ADDR_SLEB = 4,
|
||||
R_WASM_MEMORY_ADDR_I32 = 5,
|
||||
R_WASM_TYPE_INDEX_LEB = 6,
|
||||
R_WASM_GLOBAL_INDEX_LEB = 7,
|
||||
R_WASM_FUNCTION_OFFSET_I32 = 8,
|
||||
R_WASM_SECTION_OFFSET_I32 = 9,
|
||||
R_WASM_EVENT_INDEX_LEB = 10,
|
||||
R_WASM_GLOBAL_INDEX_I32 = 13,
|
||||
R_WASM_MEMORY_ADDR_LEB64 = 14,
|
||||
R_WASM_MEMORY_ADDR_SLEB64 = 15,
|
||||
R_WASM_MEMORY_ADDR_I64 = 16,
|
||||
R_WASM_TABLE_INDEX_SLEB64 = 18,
|
||||
R_WASM_TABLE_INDEX_I64 = 19,
|
||||
R_WASM_TABLE_NUMBER_LEB = 20,
|
||||
R_WASM_MEMORY_ADDR_TLS_SLEB = 21,
|
||||
R_WASM_MEMORY_ADDR_TLS_SLEB64 = 25,
|
||||
|
||||
/// Returns true for relocation types where the `addend` field is present.
|
||||
pub fn addendIsPresent(self: RelocationType) bool {
|
||||
return switch (self) {
|
||||
.R_WASM_MEMORY_ADDR_LEB,
|
||||
.R_WASM_MEMORY_ADDR_SLEB,
|
||||
.R_WASM_MEMORY_ADDR_I32,
|
||||
.R_WASM_MEMORY_ADDR_LEB64,
|
||||
.R_WASM_MEMORY_ADDR_SLEB64,
|
||||
.R_WASM_MEMORY_ADDR_I64,
|
||||
.R_WASM_MEMORY_ADDR_TLS_SLEB,
|
||||
.R_WASM_MEMORY_ADDR_TLS_SLEB64,
|
||||
.R_WASM_FUNCTION_OFFSET_I32,
|
||||
.R_WASM_SECTION_OFFSET_I32,
|
||||
=> true,
|
||||
else => false,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
/// Verifies the relocation type of a given `Relocation` and returns
|
||||
/// true when the relocation references a function call or address to a function.
|
||||
pub fn isFunction(self: Relocation) bool {
|
||||
return switch (self.relocation_type) {
|
||||
.R_WASM_FUNCTION_INDEX_LEB,
|
||||
.R_WASM_TABLE_INDEX_SLEB,
|
||||
=> true,
|
||||
else => false,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn format(self: Relocation, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void {
|
||||
_ = fmt;
|
||||
_ = options;
|
||||
try writer.print("{s} offset=0x{x:0>6} symbol={d}", .{
|
||||
@tagName(self.relocation_type),
|
||||
self.offset,
|
||||
self.index,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/// Unlike the `Import` object defined by the wasm spec, and existing
|
||||
/// in the std.wasm namespace, this construct saves the 'module name' and 'name'
|
||||
/// of the import using offsets into a string table, rather than the slices itself.
|
||||
/// This saves us (potentially) 24 bytes per import on 64bit machines.
|
||||
pub const Import = struct {
|
||||
module_name: u32,
|
||||
name: u32,
|
||||
kind: std.wasm.Import.Kind,
|
||||
};
|
||||
|
||||
/// Unlike the `Export` object defined by the wasm spec, and existing
|
||||
/// in the std.wasm namespace, this construct saves the 'name'
|
||||
/// of the export using offsets into a string table, rather than the slice itself.
|
||||
/// This saves us (potentially) 12 bytes per export on 64bit machines.
|
||||
pub const Export = struct {
|
||||
name: u32,
|
||||
index: u32,
|
||||
kind: std.wasm.ExternalKind,
|
||||
};
|
||||
|
||||
pub const SubsectionType = enum(u8) {
|
||||
WASM_SEGMENT_INFO = 5,
|
||||
WASM_INIT_FUNCS = 6,
|
||||
WASM_COMDAT_INFO = 7,
|
||||
WASM_SYMBOL_TABLE = 8,
|
||||
};
|
||||
|
||||
pub const Alignment = @import("../../InternPool.zig").Alignment;
|
||||
|
||||
pub const Segment = struct {
|
||||
/// Segment's name, encoded as UTF-8 bytes.
|
||||
name: []const u8,
|
||||
/// The required alignment of the segment, encoded as a power of 2
|
||||
alignment: Alignment,
|
||||
/// Bitfield containing flags for a segment
|
||||
flags: u32,
|
||||
|
||||
pub fn isTLS(segment: Segment) bool {
|
||||
return segment.flags & @intFromEnum(Flags.WASM_SEG_FLAG_TLS) != 0;
|
||||
}
|
||||
|
||||
/// Returns the name as how it will be output into the final object
|
||||
/// file or binary. When `merge_segments` is true, this will return the
|
||||
/// short name. i.e. ".rodata". When false, it returns the entire name instead.
|
||||
pub fn outputName(segment: Segment, merge_segments: bool) []const u8 {
|
||||
if (segment.isTLS()) {
|
||||
return ".tdata";
|
||||
} else if (!merge_segments) {
|
||||
return segment.name;
|
||||
} else if (std.mem.startsWith(u8, segment.name, ".rodata.")) {
|
||||
return ".rodata";
|
||||
} else if (std.mem.startsWith(u8, segment.name, ".text.")) {
|
||||
return ".text";
|
||||
} else if (std.mem.startsWith(u8, segment.name, ".data.")) {
|
||||
return ".data";
|
||||
} else if (std.mem.startsWith(u8, segment.name, ".bss.")) {
|
||||
return ".bss";
|
||||
}
|
||||
return segment.name;
|
||||
}
|
||||
|
||||
pub const Flags = enum(u32) {
|
||||
WASM_SEG_FLAG_STRINGS = 0x1,
|
||||
WASM_SEG_FLAG_TLS = 0x2,
|
||||
};
|
||||
};
|
||||
|
||||
pub const InitFunc = struct {
|
||||
/// Priority of the init function
|
||||
priority: u32,
|
||||
/// The symbol index of init function (not the function index).
|
||||
symbol_index: u32,
|
||||
};
|
||||
|
||||
pub const Comdat = struct {
|
||||
name: []const u8,
|
||||
/// Must be zero, no flags are currently defined by the tool-convention.
|
||||
flags: u32,
|
||||
symbols: []const ComdatSym,
|
||||
};
|
||||
|
||||
pub const ComdatSym = struct {
|
||||
kind: Type,
|
||||
/// Index of the data segment/function/global/event/table within a WASM module.
|
||||
/// The object must not be an import.
|
||||
index: u32,
|
||||
|
||||
pub const Type = enum(u8) {
|
||||
WASM_COMDAT_DATA = 0,
|
||||
WASM_COMDAT_FUNCTION = 1,
|
||||
WASM_COMDAT_GLOBAL = 2,
|
||||
WASM_COMDAT_EVENT = 3,
|
||||
WASM_COMDAT_TABLE = 4,
|
||||
WASM_COMDAT_SECTION = 5,
|
||||
};
|
||||
};
|
||||
|
||||
pub const Feature = struct {
|
||||
/// Provides information about the usage of the feature.
|
||||
/// - '0x2b' (+): Object uses this feature, and the link fails if feature is not in the allowed set.
|
||||
/// - '0x2d' (-): Object does not use this feature, and the link fails if this feature is in the allowed set.
|
||||
/// - '0x3d' (=): Object uses this feature, and the link fails if this feature is not in the allowed set,
|
||||
/// or if any object does not use this feature.
|
||||
prefix: Prefix,
|
||||
/// Type of the feature, must be unique in the sequence of features.
|
||||
tag: Tag,
|
||||
|
||||
/// Unlike `std.Target.wasm.Feature` this also contains linker-features such as shared-mem
|
||||
pub const Tag = enum {
|
||||
atomics,
|
||||
bulk_memory,
|
||||
exception_handling,
|
||||
extended_const,
|
||||
half_precision,
|
||||
multimemory,
|
||||
multivalue,
|
||||
mutable_globals,
|
||||
nontrapping_fptoint,
|
||||
reference_types,
|
||||
relaxed_simd,
|
||||
sign_ext,
|
||||
simd128,
|
||||
tail_call,
|
||||
shared_mem,
|
||||
|
||||
/// From a given cpu feature, returns its linker feature
|
||||
pub fn fromCpuFeature(feature: std.Target.wasm.Feature) Tag {
|
||||
return @as(Tag, @enumFromInt(@intFromEnum(feature)));
|
||||
}
|
||||
|
||||
pub fn format(tag: Tag, comptime fmt: []const u8, opt: std.fmt.FormatOptions, writer: anytype) !void {
|
||||
_ = fmt;
|
||||
_ = opt;
|
||||
try writer.writeAll(switch (tag) {
|
||||
.atomics => "atomics",
|
||||
.bulk_memory => "bulk-memory",
|
||||
.exception_handling => "exception-handling",
|
||||
.extended_const => "extended-const",
|
||||
.half_precision => "half-precision",
|
||||
.multimemory => "multimemory",
|
||||
.multivalue => "multivalue",
|
||||
.mutable_globals => "mutable-globals",
|
||||
.nontrapping_fptoint => "nontrapping-fptoint",
|
||||
.reference_types => "reference-types",
|
||||
.relaxed_simd => "relaxed-simd",
|
||||
.sign_ext => "sign-ext",
|
||||
.simd128 => "simd128",
|
||||
.tail_call => "tail-call",
|
||||
.shared_mem => "shared-mem",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
pub const Prefix = enum(u8) {
|
||||
used = '+',
|
||||
disallowed = '-',
|
||||
required = '=',
|
||||
};
|
||||
|
||||
pub fn format(feature: Feature, comptime fmt: []const u8, opt: std.fmt.FormatOptions, writer: anytype) !void {
|
||||
_ = opt;
|
||||
_ = fmt;
|
||||
try writer.print("{c} {}", .{ feature.prefix, feature.tag });
|
||||
}
|
||||
};
|
||||
|
||||
pub const known_features = std.StaticStringMap(Feature.Tag).initComptime(.{
|
||||
.{ "atomics", .atomics },
|
||||
.{ "bulk-memory", .bulk_memory },
|
||||
.{ "exception-handling", .exception_handling },
|
||||
.{ "extended-const", .extended_const },
|
||||
.{ "half-precision", .half_precision },
|
||||
.{ "multimemory", .multimemory },
|
||||
.{ "multivalue", .multivalue },
|
||||
.{ "mutable-globals", .mutable_globals },
|
||||
.{ "nontrapping-fptoint", .nontrapping_fptoint },
|
||||
.{ "reference-types", .reference_types },
|
||||
.{ "relaxed-simd", .relaxed_simd },
|
||||
.{ "sign-ext", .sign_ext },
|
||||
.{ "simd128", .simd128 },
|
||||
.{ "tail-call", .tail_call },
|
||||
.{ "shared-mem", .shared_mem },
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user