diff options
| author | Luuk de Gram <luuk@degram.dev> | 2024-01-21 12:06:33 +0100 |
|---|---|---|
| committer | Luuk de Gram <luuk@degram.dev> | 2024-02-29 15:23:03 +0100 |
| commit | 0a030d6598a42eae6f6af829e03bba053336b51c (patch) | |
| tree | dc18ba8e2eebf6b1b13c5a17bf317e7aa792b928 /src/link/Wasm/Atom.zig | |
| parent | 94f3a18c88eaee9a36a08a1b00c9df0584a01b05 (diff) | |
| download | zig-0a030d6598a42eae6f6af829e03bba053336b51c.tar.gz zig-0a030d6598a42eae6f6af829e03bba053336b51c.zip | |
wasm: Use `File.Index` for symbol locations
Rather than using the optional, we now directly use `File.Index` which
can already represent an unknown file due to its `.null` value. This
means we do not pay for the memory cost.
This type of index is now used for:
- SymbolLoc
- Key of the functions map
- InitFunc
Now we can simply pass things like atom.file, object.file, loc.file etc
whenever we need to access its representing object file which makes it
a lot easier.
Diffstat (limited to 'src/link/Wasm/Atom.zig')
| -rw-r--r-- | src/link/Wasm/Atom.zig | 15 |
1 files changed, 4 insertions, 11 deletions
diff --git a/src/link/Wasm/Atom.zig b/src/link/Wasm/Atom.zig index ad2b811c0b..ade66b687f 100644 --- a/src/link/Wasm/Atom.zig +++ b/src/link/Wasm/Atom.zig @@ -59,10 +59,7 @@ pub fn format(atom: Atom, comptime fmt: []const u8, options: std.fmt.FormatOptio /// Returns the location of the symbol that represents this `Atom` pub fn symbolLoc(atom: Atom) Wasm.SymbolLoc { - if (atom.file == .null) { - return .{ .file = null, .index = atom.sym_index }; - } - return .{ .file = @intFromEnum(atom.file), .index = atom.sym_index }; + return .{ .file = atom.file, .index = atom.sym_index }; } pub fn getSymbolIndex(atom: Atom) ?u32 { @@ -83,7 +80,7 @@ pub fn resolveRelocs(atom: *Atom, wasm_bin: *const Wasm) void { 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 = @intFromEnum(atom.file), .index = reloc.index }).getName(wasm_bin), + (Wasm.SymbolLoc{ .file = atom.file, .index = reloc.index }).getName(wasm_bin), symbol_name, reloc.offset, value, @@ -122,11 +119,7 @@ pub fn resolveRelocs(atom: *Atom, wasm_bin: *const Wasm) void { /// 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 = if (atom.file == .null) - (Wasm.SymbolLoc{ .file = null, .index = relocation.index }).finalLoc(wasm_bin) - else - (Wasm.SymbolLoc{ .file = @intFromEnum(atom.file), .index = relocation.index }).finalLoc(wasm_bin); - + const target_loc = (Wasm.SymbolLoc{ .file = atom.file, .index = 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 @@ -142,7 +135,7 @@ fn relocationValue(atom: Atom, relocation: types.Relocation, wasm_bin: *const Wa .R_WASM_TABLE_INDEX_I64, .R_WASM_TABLE_INDEX_SLEB, .R_WASM_TABLE_INDEX_SLEB64, - => return wasm_bin.function_table.get(.{ .file = @intFromEnum(atom.file), .index = relocation.index }) orelse 0, + => return wasm_bin.function_table.get(.{ .file = atom.file, .index = 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]; |
