authorgravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2022-09-06 20:21:33+02:00
committergravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2022-09-07 18:59:36+02:00
loga8d137d05ae36870d4e896cf5e37b591d9fa219c
tree720dde8e8f150bb6bb2e63e5506ca337e50eee3d
parent971327d6e0a2cdcfd1a7695d1dea86dbbebd730e
signaturelock-open Commit is signed but in an unrecognized format.

wasm-linker: support incremental debug info

Although the wasm-linker previously already supported debug information in incremental-mode, this was no longer working as-is with the addition of supporting object-file-parsed debug information. This commit implements the Zig-created debug information structure from scratch which is a lot more robust and also allows being linked with debug information from other object files.

4 files changed, 141 insertions(+), 98 deletions(-)

src/link/Dwarf.zig+27-46
......@@ -861,9 +861,7 @@ pub fn commitDeclState(
861861 },
862862 .wasm => {
863863 const wasm_file = file.cast(File.Wasm).?;
864 const segment_index = wasm_file.debug_line_index.?;
865 const atom = wasm_file.atoms.get(segment_index).?;
866 const debug_line = atom.getFirstZigAtom().code;
864 const debug_line = wasm_file.debug_line_atom.?.code;
867865 writeDbgLineNopsBuffered(debug_line.items, src_fn.off, 0, &.{}, src_fn.len);
868866 },
869867 else => unreachable,
......@@ -975,24 +973,21 @@ pub fn commitDeclState(
975973 },
976974 .wasm => {
977975 const wasm_file = file.cast(File.Wasm).?;
978 const segment_index = wasm_file.debug_line_index.?;
979 const segment = &wasm_file.segments.items[segment_index];
980 const atom = wasm_file.atoms.get(segment_index).?;
981 const debug_line = &atom.getFirstZigAtom().code;
982 if (needed_size != segment.size) {
976 const atom = wasm_file.debug_line_atom.?;
977 const debug_line = &atom.code;
978 const segment_size = debug_line.items.len;
979 if (needed_size != segment_size) {
983980 log.debug(" needed size does not equal allocated size: {d}", .{needed_size});
984 if (needed_size > segment.size) {
985 log.debug(" allocating {d} bytes for 'debug line' information", .{needed_size - segment.size});
981 if (needed_size > segment_size) {
982 log.debug(" allocating {d} bytes for 'debug line' information", .{needed_size - segment_size});
986983 try debug_line.resize(self.allocator, needed_size);
987 mem.set(u8, debug_line.items[segment.size..], 0);
984 mem.set(u8, debug_line.items[segment_size..], 0);
988985 }
989 segment.size = needed_size;
990986 debug_line.items.len = needed_size;
991987 }
992 const offset = segment.offset + src_fn.off;
993988 writeDbgLineNopsBuffered(
994989 debug_line.items,
995 offset,
990 src_fn.off,
996991 prev_padding_size,
997992 dbg_line_buffer.items,
998993 next_padding_size,
......@@ -1150,12 +1145,8 @@ fn updateDeclDebugInfoAllocation(self: *Dwarf, file: *File, atom: *Atom, len: u3
11501145 },
11511146 .wasm => {
11521147 const wasm_file = file.cast(File.Wasm).?;
1153 const segment_index = wasm_file.debug_info_index.?;
1154 const segment = &wasm_file.segments.items[segment_index];
1155 const info_atom = wasm_file.atoms.get(segment_index).?;
1156 const debug_info = &info_atom.getFirstZigAtom().code;
1157 const offset = segment.offset + atom.off;
1158 try writeDbgInfoNopsToArrayList(gpa, debug_info, offset, 0, &.{0}, atom.len, false);
1148 const debug_info = &wasm_file.debug_info_atom.?.code;
1149 try writeDbgInfoNopsToArrayList(gpa, debug_info, atom.off, 0, &.{0}, atom.len, false);
11591150 },
11601151 else => unreachable,
11611152 }
......@@ -1282,28 +1273,25 @@ fn writeDeclDebugInfo(self: *Dwarf, file: *File, atom: *Atom, dbg_info_buf: []co
12821273 },
12831274 .wasm => {
12841275 const wasm_file = file.cast(File.Wasm).?;
1285 const segment_index = wasm_file.debug_info_index.?;
1286 const segment = &wasm_file.segments.items[segment_index];
1287 const info_atom = wasm_file.atoms.get(segment_index).?;
1288 const debug_info = &info_atom.getFirstZigAtom().code;
1289 if (needed_size != segment.size) {
1276 const info_atom = wasm_file.debug_info_atom.?;
1277 const debug_info = &info_atom.code;
1278 const segment_size = debug_info.items.len;
1279 if (needed_size != segment_size) {
12901280 log.debug(" needed size does not equal allocated size: {d}", .{needed_size});
1291 if (needed_size > segment.size) {
1292 log.debug(" allocating {d} bytes for 'debug info' information", .{needed_size - segment.size});
1281 if (needed_size > segment_size) {
1282 log.debug(" allocating {d} bytes for 'debug info' information", .{needed_size - segment_size});
12931283 try debug_info.resize(self.allocator, needed_size);
1294 mem.set(u8, debug_info.items[segment.size..], 0);
1284 mem.set(u8, debug_info.items[segment_size..], 0);
12951285 }
1296 segment.size = needed_size;
12971286 debug_info.items.len = needed_size;
12981287 }
1299 const offset = segment.offset + atom.off;
13001288 log.debug(" writeDbgInfoNopsToArrayList debug_info_len={d} offset={d} content_len={d} next_padding_size={d}", .{
1301 debug_info.items.len, offset, dbg_info_buf.len, next_padding_size,
1289 debug_info.items.len, atom.off, dbg_info_buf.len, next_padding_size,
13021290 });
13031291 try writeDbgInfoNopsToArrayList(
13041292 gpa,
13051293 debug_info,
1306 offset,
1294 atom.off,
13071295 prev_padding_size,
13081296 dbg_info_buf,
13091297 next_padding_size,
......@@ -1344,10 +1332,8 @@ pub fn updateDeclLineNumber(self: *Dwarf, file: *File, decl: *const Module.Decl)
13441332 },
13451333 .wasm => {
13461334 const wasm_file = file.cast(File.Wasm).?;
1347 const segment_index = wasm_file.debug_line_index.?;
1348 const segment = wasm_file.segments.items[segment_index];
1349 const offset = segment.offset + decl.fn_link.wasm.src_fn.off + self.getRelocDbgLineOff();
1350 const atom = wasm_file.atoms.get(segment_index).?.getFirstZigAtom();
1335 const offset = decl.fn_link.wasm.src_fn.off + self.getRelocDbgLineOff();
1336 const atom = wasm_file.debug_line_atom.?;
13511337 mem.copy(u8, atom.code.items[offset..], &data);
13521338 },
13531339 else => unreachable,
......@@ -1584,8 +1570,7 @@ pub fn writeDbgAbbrev(self: *Dwarf, file: *File) !void {
15841570 },
15851571 .wasm => {
15861572 const wasm_file = file.cast(File.Wasm).?;
1587 const segment_index = wasm_file.debug_abbrev_index.?;
1588 const debug_abbrev = &wasm_file.atoms.get(segment_index).?.getFirstZigAtom().code;
1573 const debug_abbrev = &wasm_file.debug_abbrev_atom.?.code;
15891574 try debug_abbrev.resize(wasm_file.base.allocator, needed_size);
15901575 mem.copy(u8, debug_abbrev.items, &abbrev_buf);
15911576 },
......@@ -1697,8 +1682,7 @@ pub fn writeDbgInfoHeader(self: *Dwarf, file: *File, module: *Module, low_pc: u6
16971682 },
16981683 .wasm => {
16991684 const wasm_file = file.cast(File.Wasm).?;
1700 const segment_index = wasm_file.debug_info_index.?;
1701 const debug_info = &wasm_file.atoms.get(segment_index).?.getFirstZigAtom().code;
1685 const debug_info = &wasm_file.debug_info_atom.?.code;
17021686 try writeDbgInfoNopsToArrayList(self.allocator, debug_info, 0, 0, di_buf.items, jmp_amt, false);
17031687 },
17041688 else => unreachable,
......@@ -2028,8 +2012,7 @@ pub fn writeDbgAranges(self: *Dwarf, file: *File, addr: u64, size: u64) !void {
20282012 },
20292013 .wasm => {
20302014 const wasm_file = file.cast(File.Wasm).?;
2031 const segment_index = wasm_file.debug_ranges_index.?;
2032 const debug_ranges = &wasm_file.atoms.get(segment_index).?.getFirstZigAtom().code;
2015 const debug_ranges = &wasm_file.debug_ranges_atom.?.code;
20332016 try debug_ranges.resize(wasm_file.base.allocator, needed_size);
20342017 mem.copy(u8, debug_ranges.items, di_buf.items);
20352018 },
......@@ -2153,8 +2136,7 @@ pub fn writeDbgLineHeader(self: *Dwarf, file: *File, module: *Module) !void {
21532136 },
21542137 .wasm => {
21552138 const wasm_file = file.cast(File.Wasm).?;
2156 const segment_index = wasm_file.debug_line_index.?;
2157 const debug_line = wasm_file.atoms.get(segment_index).?.getFirstZigAtom().code;
2139 const debug_line = wasm_file.debug_line_atom.?.code;
21582140 writeDbgLineNopsBuffered(debug_line.items, 0, 0, di_buf.items, jmp_amt);
21592141 },
21602142 else => unreachable,
......@@ -2303,8 +2285,7 @@ pub fn flushModule(self: *Dwarf, file: *File, module: *Module) !void {
23032285 },
23042286 .wasm => {
23052287 const wasm_file = file.cast(File.Wasm).?;
2306 const segment_index = wasm_file.debug_info_index.?;
2307 const debug_info = wasm_file.atoms.get(segment_index).?.getFirstZigAtom().code;
2288 const debug_info = wasm_file.debug_info_atom.?.code;
23082289 mem.copy(u8, debug_info.items[reloc.atom.off + reloc.offset ..], &buf);
23092290 },
23102291 else => unreachable,
src/link/Wasm.zig+112-44
......@@ -95,9 +95,10 @@ imports: std.AutoHashMapUnmanaged(SymbolLoc, types.Import) = .{},
9595segments: std.ArrayListUnmanaged(Segment) = .{},
9696/// Maps a data segment key (such as .rodata) to the index into `segments`.
9797data_segments: std.StringArrayHashMapUnmanaged(u32) = .{},
98/// A list of `types.Segment` which provide meta data
99/// about a data symbol such as its name
100segment_info: std.ArrayListUnmanaged(types.Segment) = .{},
98/// A table of `types.Segment` which provide meta data
99/// about a data symbol such as its name where the key is
100/// the segment index, which can be found from `data_segments`
101segment_info: std.AutoArrayHashMapUnmanaged(u32, types.Segment) = .{},
101102/// Deduplicated string table for strings used by symbols, imports and exports.
102103string_table: StringTable = .{},
103104/// Debug information for wasm
......@@ -158,6 +159,19 @@ export_names: std.AutoHashMapUnmanaged(SymbolLoc, u32) = .{},
158159/// The actual table is populated during `flush`.
159160error_table_symbol: ?u32 = null,
160161
162// Debug section atoms. These are only set when the current compilation
163// unit contains Zig code. The lifetime of these atoms are extended
164// until the end of the compiler's lifetime. Meaning they're not freed
165// during `flush()` in incremental-mode.
166debug_info_atom: ?*Atom = null,
167debug_line_atom: ?*Atom = null,
168debug_loc_atom: ?*Atom = null,
169debug_ranges_atom: ?*Atom = null,
170debug_abbrev_atom: ?*Atom = null,
171debug_str_atom: ?*Atom = null,
172debug_pubnames_atom: ?*Atom = null,
173debug_pubtypes_atom: ?*Atom = null,
174
161175pub const Segment = struct {
162176 alignment: u32,
163177 size: u32,
......@@ -384,15 +398,16 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*Wasm {
384398/// and symbols come from the object files instead.
385399pub fn initDebugSections(self: *Wasm) !void {
386400 if (self.dwarf == null) return; // not compiling Zig code, so no need to pre-initialize debug sections
401 assert(self.debug_info_index == null);
387402 // this will create an Atom and set the index for us.
388 try self.createDebugSectionForIndex(&self.debug_info_index);
389 try self.createDebugSectionForIndex(&self.debug_line_index);
390 try self.createDebugSectionForIndex(&self.debug_loc_index);
391 try self.createDebugSectionForIndex(&self.debug_abbrev_index);
392 try self.createDebugSectionForIndex(&self.debug_ranges_index);
393 try self.createDebugSectionForIndex(&self.debug_str_index);
394 try self.createDebugSectionForIndex(&self.debug_pubnames_index);
395 try self.createDebugSectionForIndex(&self.debug_pubtypes_index);
403 self.debug_info_atom = try self.createDebugSectionForIndex(&self.debug_info_index, ".debug_info");
404 self.debug_line_atom = try self.createDebugSectionForIndex(&self.debug_line_index, ".debug_line");
405 self.debug_loc_atom = try self.createDebugSectionForIndex(&self.debug_loc_index, ".debug_loc");
406 self.debug_abbrev_atom = try self.createDebugSectionForIndex(&self.debug_abbrev_index, ".debug_abbrev");
407 self.debug_ranges_atom = try self.createDebugSectionForIndex(&self.debug_ranges_index, ".debug_ranges");
408 self.debug_str_atom = try self.createDebugSectionForIndex(&self.debug_str_index, ".debug_str");
409 self.debug_pubnames_atom = try self.createDebugSectionForIndex(&self.debug_pubnames_index, ".debug_pubnames");
410 self.debug_pubtypes_atom = try self.createDebugSectionForIndex(&self.debug_pubtypes_index, ".debug_pubtypes");
396411}
397412
398413fn parseInputFiles(self: *Wasm, files: []const []const u8) !void {
......@@ -676,7 +691,7 @@ pub fn deinit(self: *Wasm) void {
676691 for (self.func_types.items) |*func_type| {
677692 func_type.deinit(gpa);
678693 }
679 for (self.segment_info.items) |segment_info| {
694 for (self.segment_info.values()) |segment_info| {
680695 gpa.free(segment_info.name);
681696 }
682697 for (self.objects.items) |*object| {
......@@ -1364,16 +1379,7 @@ fn parseAtom(self: *Wasm, atom: *Atom, kind: Kind) !void {
13641379 const index = gop.value_ptr.*;
13651380 self.segments.items[index].size += atom.size;
13661381
1367 // segment indexes can be off by 1 due to also containing a segment
1368 // for the code section, so we must check if the existing segment
1369 // is larger than that of the code section, and substract the index by 1 in such case.
1370 var info_add = if (self.code_section_index) |idx| blk: {
1371 if (idx < index) break :blk @as(u32, 1);
1372 break :blk 0;
1373 } else @as(u32, 0);
1374 if (self.debug_info_index != null) info_add += 1;
1375 if (self.debug_line_index != null) info_add += 1;
1376 symbol.index = index - info_add;
1382 symbol.index = @intCast(u32, self.segment_info.getIndex(index).?);
13771383 // segment info already exists, so free its memory
13781384 self.base.allocator.free(segment_name);
13791385 break :result index;
......@@ -1386,8 +1392,8 @@ fn parseAtom(self: *Wasm, atom: *Atom, kind: Kind) !void {
13861392 });
13871393 gop.value_ptr.* = index;
13881394
1389 const info_index = @intCast(u32, self.segment_info.items.len);
1390 try self.segment_info.append(self.base.allocator, segment_info);
1395 const info_index = @intCast(u32, self.segment_info.count());
1396 try self.segment_info.put(self.base.allocator, index, segment_info);
13911397 symbol.index = info_index;
13921398 break :result index;
13931399 }
......@@ -1397,18 +1403,54 @@ fn parseAtom(self: *Wasm, atom: *Atom, kind: Kind) !void {
13971403 const segment: *Segment = &self.segments.items[final_index];
13981404 segment.alignment = std.math.max(segment.alignment, atom.alignment);
13991405
1400 if (self.atoms.getPtr(final_index)) |last| {
1406 try self.appendAtomAtIndex(final_index, atom);
1407}
1408
1409/// From a given index, append the given `Atom` at the back of the linked list.
1410/// Simply inserts it into the map of atoms when it doesn't exist yet.
1411pub fn appendAtomAtIndex(self: *Wasm, index: u32, atom: *Atom) !void {
1412 if (self.atoms.getPtr(index)) |last| {
14011413 last.*.next = atom;
14021414 atom.prev = last.*;
14031415 last.* = atom;
14041416 } else {
1405 try self.atoms.putNoClobber(self.base.allocator, final_index, atom);
1417 try self.atoms.putNoClobber(self.base.allocator, index, atom);
14061418 }
14071419}
14081420
1421/// Allocates debug atoms into their respective debug sections
1422/// to merge them with maybe-existing debug atoms from object files.
1423fn allocateDebugAtoms(self: *Wasm) !void {
1424 if (self.dwarf == null) return;
1425
1426 const allocAtom = struct {
1427 fn f(bin: *Wasm, maybe_index: *?u32, atom: *Atom) !void {
1428 const index = maybe_index.* orelse idx: {
1429 const index = @intCast(u32, bin.segments.items.len);
1430 try bin.appendDummySegment();
1431 maybe_index.* = index;
1432 break :idx index;
1433 };
1434 atom.size = @intCast(u32, atom.code.items.len);
1435 bin.symbols.items[atom.sym_index].index = index;
1436 try bin.appendAtomAtIndex(index, atom);
1437 }
1438 }.f;
1439
1440 try allocAtom(self, &self.debug_info_index, self.debug_info_atom.?);
1441 try allocAtom(self, &self.debug_line_index, self.debug_line_atom.?);
1442 try allocAtom(self, &self.debug_loc_index, self.debug_loc_atom.?);
1443 try allocAtom(self, &self.debug_str_index, self.debug_str_atom.?);
1444 try allocAtom(self, &self.debug_ranges_index, self.debug_ranges_atom.?);
1445 try allocAtom(self, &self.debug_abbrev_index, self.debug_abbrev_atom.?);
1446 try allocAtom(self, &self.debug_pubnames_index, self.debug_pubnames_atom.?);
1447 try allocAtom(self, &self.debug_pubtypes_index, self.debug_pubtypes_atom.?);
1448}
1449
14091450fn allocateAtoms(self: *Wasm) !void {
14101451 // first sort the data segments
14111452 try sortDataSegments(self);
1453 try allocateDebugAtoms(self);
14121454
14131455 var it = self.atoms.iterator();
14141456 while (it.next()) |entry| {
......@@ -1426,7 +1468,7 @@ fn allocateAtoms(self: *Wasm) !void {
14261468 atom.size,
14271469 });
14281470 offset += atom.size;
1429 self.symbol_atom.putAssumeCapacity(atom.symbolLoc(), atom); // Update atom pointers
1471 try self.symbol_atom.put(self.base.allocator, atom.symbolLoc(), atom); // Update atom pointers
14301472 atom = atom.next orelse break;
14311473 }
14321474 segment.size = std.mem.alignForwardGeneric(u32, offset, segment.alignment);
......@@ -1989,20 +2031,35 @@ fn populateErrorNameTable(self: *Wasm) !void {
19892031/// From a given index variable, creates a new debug section.
19902032/// This initializes the index, appends a new segment,
19912033/// and finally, creates a managed `Atom`.
1992pub fn createDebugSectionForIndex(self: *Wasm, index: *?u32) !void {
2034pub fn createDebugSectionForIndex(self: *Wasm, index: *?u32, name: []const u8) !*Atom {
19932035 const new_index = @intCast(u32, self.segments.items.len);
19942036 index.* = new_index;
19952037 try self.appendDummySegment();
2038 // _ = index;
2039
2040 const sym_index = self.symbols_free_list.popOrNull() orelse idx: {
2041 const tmp_index = @intCast(u32, self.symbols.items.len);
2042 _ = try self.symbols.addOne(self.base.allocator);
2043 break :idx tmp_index;
2044 };
2045 self.symbols.items[sym_index] = .{
2046 .tag = .section,
2047 .name = try self.string_table.put(self.base.allocator, name),
2048 .index = 0,
2049 .flags = @enumToInt(Symbol.Flag.WASM_SYM_BINDING_LOCAL),
2050 };
19962051
19972052 const atom = try self.base.allocator.create(Atom);
19982053 atom.* = Atom.empty;
19992054 atom.alignment = 1; // debug sections are always 1-byte-aligned
2055 atom.sym_index = sym_index;
20002056 try self.managed_atoms.append(self.base.allocator, atom);
2001 try self.atoms.put(self.base.allocator, new_index, atom);
2057 try self.symbol_atom.put(self.base.allocator, atom.symbolLoc(), atom);
2058 return atom;
20022059}
20032060
20042061fn resetState(self: *Wasm) void {
2005 for (self.segment_info.items) |*segment_info| {
2062 for (self.segment_info.values()) |segment_info| {
20062063 self.base.allocator.free(segment_info.name);
20072064 }
20082065 if (self.base.options.module) |mod| {
......@@ -2029,6 +2086,12 @@ fn resetState(self: *Wasm) void {
20292086 self.code_section_index = null;
20302087 self.debug_info_index = null;
20312088 self.debug_line_index = null;
2089 self.debug_loc_index = null;
2090 self.debug_str_index = null;
2091 self.debug_ranges_index = null;
2092 self.debug_abbrev_index = null;
2093 self.debug_pubnames_index = null;
2094 self.debug_pubtypes_index = null;
20322095}
20332096
20342097pub fn flush(self: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) !void {
......@@ -2508,26 +2571,31 @@ pub fn flushModule(self: *Wasm, comp: *Compilation, prog_node: *std.Progress.Nod
25082571 var debug_bytes = std.ArrayList(u8).init(self.base.allocator);
25092572 defer debug_bytes.deinit();
25102573
2511 const debug_sections = .{
2512 .{ ".debug_info", self.debug_info_index },
2513 .{ ".debug_pubtypes", self.debug_pubtypes_index },
2514 .{ ".debug_abbrev", self.debug_abbrev_index },
2515 .{ ".debug_line", self.debug_line_index },
2516 .{ ".debug_str", self.debug_str_index },
2517 .{ ".debug_pubnames", self.debug_pubnames_index },
2518 .{ ".debug_loc", self.debug_loc_index },
2519 .{ ".debug_ranges", self.debug_ranges_index },
2574 const DebugSection = struct {
2575 name: []const u8,
2576 index: ?u32,
2577 };
2578
2579 const debug_sections: []const DebugSection = &.{
2580 .{ .name = ".debug_info", .index = self.debug_info_index },
2581 .{ .name = ".debug_pubtypes", .index = self.debug_pubtypes_index },
2582 .{ .name = ".debug_abbrev", .index = self.debug_abbrev_index },
2583 .{ .name = ".debug_line", .index = self.debug_line_index },
2584 .{ .name = ".debug_str", .index = self.debug_str_index },
2585 .{ .name = ".debug_pubnames", .index = self.debug_pubnames_index },
2586 .{ .name = ".debug_loc", .index = self.debug_loc_index },
2587 .{ .name = ".debug_ranges", .index = self.debug_ranges_index },
25202588 };
25212589
2522 inline for (debug_sections) |item| {
2523 if (item[1]) |index| {
2590 for (debug_sections) |item| {
2591 if (item.index) |index| {
25242592 var atom = self.atoms.get(index).?.getFirst();
25252593 while (true) {
25262594 atom.resolveRelocs(self);
25272595 try debug_bytes.appendSlice(atom.code.items);
25282596 atom = atom.next orelse break;
25292597 }
2530 try emitDebugSection(file, debug_bytes.items, item[0]);
2598 try emitDebugSection(file, debug_bytes.items, item.name);
25312599 debug_bytes.clearRetainingCapacity();
25322600 }
25332601 }
......@@ -3242,8 +3310,8 @@ fn emitSegmentInfo(self: *Wasm, file: fs.File, arena: Allocator) !void {
32423310 var payload = std.ArrayList(u8).init(arena);
32433311 const writer = payload.writer();
32443312 try leb.writeULEB128(file.writer(), @enumToInt(types.SubsectionType.WASM_SEGMENT_INFO));
3245 try leb.writeULEB128(writer, @intCast(u32, self.segment_info.items.len));
3246 for (self.segment_info.items) |segment_info| {
3313 try leb.writeULEB128(writer, @intCast(u32, self.segment_info.count()));
3314 for (self.segment_info.values()) |segment_info| {
32473315 log.debug("Emit segment: {s} align({d}) flags({b})", .{
32483316 segment_info.name,
32493317 @ctz(segment_info.alignment),
src/link/Wasm/Atom.zig+1-1
......@@ -190,7 +190,7 @@ fn relocationValue(self: Atom, relocation: types.Relocation, wasm_bin: *const Wa
190190 const target_atom = wasm_bin.symbol_atom.get(target_loc).?;
191191 const segment_info = if (target_atom.file) |object_index| blk: {
192192 break :blk wasm_bin.objects.items[object_index].segment_info;
193 } else wasm_bin.segment_info.items;
193 } else wasm_bin.segment_info.values();
194194 const segment_name = segment_info[symbol.index].outputName(merge_segment);
195195 const segment_index = wasm_bin.data_segments.get(segment_name).?;
196196 const segment = wasm_bin.segments.items[segment_index];
src/link/Wasm/Object.zig+1-7
......@@ -953,13 +953,7 @@ pub fn parseIntoAtoms(self: *Object, gpa: Allocator, object_index: u16, wasm_bin
953953 segment.alignment = std.math.max(segment.alignment, atom.alignment);
954954 }
955955
956 if (wasm_bin.atoms.getPtr(final_index)) |last| {
957 last.*.next = atom;
958 atom.prev = last.*;
959 last.* = atom;
960 } else {
961 try wasm_bin.atoms.putNoClobber(gpa, final_index, atom);
962 }
956 try wasm_bin.appendAtomAtIndex(final_index, atom);
963957 log.debug("Parsed into atom: '{s}' at segment index {d}", .{ self.string_table.get(self.symtable[atom.sym_index].name), final_index });
964958 }
965959}