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:
@@ -40,13 +40,7 @@ export fn emitu32(a: *asm_, v: u32) void = {
|
||||
};
|
||||
|
||||
export fn addreloc(a: *asm_, off: u64, kind: i32, s: *asym, add: i64) void = {
|
||||
let r: *areloc = amalloc(a.a, 64u64): *areloc;
|
||||
r.off = off;
|
||||
r.section = 0; // .text
|
||||
r.kind = kind;
|
||||
r.asy = s;
|
||||
r.addend = add;
|
||||
r.rnext = a.relocs;
|
||||
let r: *areloc = alloc(areloc { off = off, section = 0, kind = kind, asy = s, addend = add, rnext = a.relocs })!;
|
||||
a.relocs = r;
|
||||
};
|
||||
|
||||
@@ -54,13 +48,7 @@ export fn addreloc(a: *asm_, off: u64, kind: i32, s: *asym, add: i64) void = {
|
||||
// DATAR to patch a 64-bit slot with a symbol's runtime VA. obj.ww
|
||||
// separates these into .rela.data when emitting the .o.
|
||||
export fn addrelocdata(a: *asm_, off: u64, kind: i32, s: *asym, add: i64) void = {
|
||||
let r: *areloc = amalloc(a.a, 64u64): *areloc;
|
||||
r.off = off;
|
||||
r.section = 1; // .data
|
||||
r.kind = kind;
|
||||
r.asy = s;
|
||||
r.addend = add;
|
||||
r.rnext = a.relocs;
|
||||
let r: *areloc = alloc(areloc { off = off, section = 1, kind = kind, asy = s, addend = add, rnext = a.relocs })!;
|
||||
a.relocs = r;
|
||||
};
|
||||
|
||||
@@ -254,10 +242,7 @@ fn labeldefined(a: *asm_, name: str) bool = {
|
||||
// ---- fixup helper -----------------------------------------------------
|
||||
|
||||
fn addfixup(a: *asm_, off: u64, label: str) void = {
|
||||
let f: *afixup = amalloc(a.a, 48u64): *afixup;
|
||||
f.off = off;
|
||||
f.label = label;
|
||||
f.fnext = a.fixups;
|
||||
let f: *afixup = alloc(afixup { off = off, label = label, fnext = a.fixups })!;
|
||||
a.fixups = f;
|
||||
};
|
||||
|
||||
|
||||
@@ -1783,13 +1783,7 @@ export fn emitu32(a: *asm_, v: u32) void = {
|
||||
};
|
||||
|
||||
export fn addreloc(a: *asm_, off: u64, kind: i32, s: *asym, add: i64) void = {
|
||||
let r: *areloc = amalloc(a.a, 64u64): *areloc;
|
||||
r.off = off;
|
||||
r.section = 0; // .text
|
||||
r.kind = kind;
|
||||
r.asy = s;
|
||||
r.addend = add;
|
||||
r.rnext = a.relocs;
|
||||
let r: *areloc = alloc(areloc { off = off, section = 0, kind = kind, asy = s, addend = add, rnext = a.relocs })!;
|
||||
a.relocs = r;
|
||||
};
|
||||
|
||||
@@ -1797,13 +1791,7 @@ export fn addreloc(a: *asm_, off: u64, kind: i32, s: *asym, add: i64) void = {
|
||||
// DATAR to patch a 64-bit slot with a symbol's runtime VA. obj.ww
|
||||
// separates these into .rela.data when emitting the .o.
|
||||
export fn addrelocdata(a: *asm_, off: u64, kind: i32, s: *asym, add: i64) void = {
|
||||
let r: *areloc = amalloc(a.a, 64u64): *areloc;
|
||||
r.off = off;
|
||||
r.section = 1; // .data
|
||||
r.kind = kind;
|
||||
r.asy = s;
|
||||
r.addend = add;
|
||||
r.rnext = a.relocs;
|
||||
let r: *areloc = alloc(areloc { off = off, section = 1, kind = kind, asy = s, addend = add, rnext = a.relocs })!;
|
||||
a.relocs = r;
|
||||
};
|
||||
|
||||
@@ -1997,10 +1985,7 @@ fn labeldefined(a: *asm_, name: str) bool = {
|
||||
// ---- fixup helper -----------------------------------------------------
|
||||
|
||||
fn addfixup(a: *asm_, off: u64, label: str) void = {
|
||||
let f: *afixup = amalloc(a.a, 48u64): *afixup;
|
||||
f.off = off;
|
||||
f.label = label;
|
||||
f.fnext = a.fixups;
|
||||
let f: *afixup = alloc(afixup { off = off, label = label, fnext = a.fixups })!;
|
||||
a.fixups = f;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user