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`.
This commit is contained in:
Luuk de Gram
2023-11-22 06:51:50 +01:00
parent f7d4f72fd5
commit 8447d4fb1f

View File

@@ -5115,6 +5115,23 @@ fn markReferences(wasm: *Wasm) !void {
if (sym.isExported(wasm.base.options.rdynamic) or sym.isNoStrip()) {
try wasm.mark(sym_loc);
}
// Debug sections may require to be parsed and marked when it contains
// relocations to alive symbols.
if (sym.tag == .section and !wasm.base.options.strip) {
const file = sym_loc.file orelse continue; // Incremental debug info is done independently
const object = &wasm.objects.items[file];
const atom_index = try Object.parseSymbolIntoAtom(object, file, sym_loc.index, wasm);
const atom = wasm.getAtom(atom_index);
for (atom.relocs.items) |reloc| {
const target_loc: SymbolLoc = .{ .index = reloc.index, .file = atom.file };
const target_sym = target_loc.getSymbol(wasm);
if (target_sym.isAlive()) {
sym.mark();
continue; // Skip all other relocations as this debug atom is already marked now
}
}
}
}
}