authorgravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2023-11-22 06:51:50+01:00
committergravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2023-11-28 15:47:07+01:00
log8447d4fb1f5b628b3c0c9f2b1254d8ddc7801ab1
tree27215b80d31309497606aeb00a9ae5c0aa1ce2c9
parentf7d4f72fd5e3e3026e395f43c5b2b2c3cb49fce2
signature Commit is signed but in an unrecognized format.

wasm-linker: handle debug info during gc

When we encounter a debug info symbol, we initially have to parse it into an atom to find its relocations. We then go through its relocations to find out if any of the target symbols are marked alive. When it finds an alive symbol, we also mark the debug symbol as alive to ensure this piece of debug info is emit to the binary. When it does not encounter any alive symbols, the debug symbol remains dead and will be garbage- collected during `allocateAtoms`.

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

src/link/Wasm.zig+17
......@@ -5115,6 +5115,23 @@ fn markReferences(wasm: *Wasm) !void {
51155115 if (sym.isExported(wasm.base.options.rdynamic) or sym.isNoStrip()) {
51165116 try wasm.mark(sym_loc);
51175117 }
5118
5119 // Debug sections may require to be parsed and marked when it contains
5120 // relocations to alive symbols.
5121 if (sym.tag == .section and !wasm.base.options.strip) {
5122 const file = sym_loc.file orelse continue; // Incremental debug info is done independently
5123 const object = &wasm.objects.items[file];
5124 const atom_index = try Object.parseSymbolIntoAtom(object, file, sym_loc.index, wasm);
5125 const atom = wasm.getAtom(atom_index);
5126 for (atom.relocs.items) |reloc| {
5127 const target_loc: SymbolLoc = .{ .index = reloc.index, .file = atom.file };
5128 const target_sym = target_loc.getSymbol(wasm);
5129 if (target_sym.isAlive()) {
5130 sym.mark();
5131 continue; // Skip all other relocations as this debug atom is already marked now
5132 }
5133 }
5134 }
51185135 }
51195136}
51205137