selfhost/cmd/{w6a,w6l}: migrate 6 amalloc sites to alloc(T{...})!

Phase 0 batch 1. Six typed-struct allocations switch from
amalloc(arena, NNu64): *T over-sized byte counts to alloc(T{...})!
with partial struct literal initialization. MAP_ANON-zero from
rt_alloc covers any field the literal omits — same contract the
amalloc bump arena provided via its explicit zero loop, but
without the rule-13 size literal at the call site.

Converted:
 - w6a/asm.ww  addreloc, addrelocdata, addfixup (areloc, afixup)
 - w6l/sym.ww  intern (lsym)
 - w6l/dyn.ww  loadso (lso), lexport

lexport's `if (vernamecs == nil) { e.version.ptr = nil;
e.version.len = 0i32; }` branch dropped — MAP_ANON-zero provides
the empty-version slot for free; the inverted `if (vernamecs !=
nil)` only takes the dcstrtostr path.

w6l/sym.ww:20 comment updated from "amalloc-zeroing" to
"alloc-zeroing gives 0, not -1" so the documented mechanism
matches the call.

w6a/obj.ww's 2 remaining amalloc sites (bufinit + bufgrow) are
runtime-N *u8 byte buffers, deferred to #8 (runtime-N alloc API).

Verified via 991_w6a_ww + 992_w6l_ww + 995_self_rebuild +
996_dyn_ww byte-identity. make test 132/132.
This commit is contained in:
2026-05-20 18:07:32 +09:00
parent d617a698b0
commit 469ec85551
5 changed files with 16 additions and 66 deletions

View File

@@ -877,7 +877,7 @@ type lsym = struct {
idxinowner: i32,
// Dynamic-linking fields. Set by resolve when an undefined sym
// is provided by some loaded lso. pltidx and dynsymidx default
// to -1 (set explicitly by resolve, not by amalloc-zeroing).
// to -1 (set explicitly by resolve; alloc-zeroing gives 0, not -1).
isdyn: i32,
dynlib: *lso,
dynversion: str, // matched export's version; len 0 if none
@@ -956,9 +956,7 @@ export fn intern(l: *lnk, name: str) *lsym = {
if (streq(s.name, name)) { return s; };
s = s.snext;
};
let n: *lsym = amalloc(l.a, 96u64): *lsym;
n.name = name;
n.snext = l.syms;
let n: *lsym = alloc(lsym { name = name, snext = l.syms })!;
l.syms = n;
return n;
};
@@ -1876,10 +1874,7 @@ export fn loadso(l: *lnk, path: *u8) i32 = {
// Build the lso. Exports are appended in dynsym order so
// soprovides_v's first-match semantics match the C version.
let so: *lso = amalloc(l.a, 64u64): *lso;
so.path = dcstrtostr(l.a, path);
so.soname = dcstrtostr(l.a, sonamecs);
so.exports = nil;
let so: *lso = alloc(lso { path = dcstrtostr(l.a, path), soname = dcstrtostr(l.a, sonamecs) })!;
let tail: *lexport = nil;
let si: u64 = 1u64;
@@ -1931,15 +1926,10 @@ export fn loadso(l: *lnk, path: *u8) i32 = {
};
if (keep != 0) {
let e: *lexport = amalloc(l.a, 48u64): *lexport;
e.name = dcstrtostr(l.a, nmp);
if (vernamecs == nil) {
e.version.ptr = nil;
e.version.len = 0i32;
} else {
let e: *lexport = alloc(lexport { name = dcstrtostr(l.a, nmp) })!;
if (vernamecs != nil) {
e.version = dcstrtostr(l.a, vernamecs);
};
e.enext = nil;
if (tail == nil) {
so.exports = e;
} else {