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 = {
|
export fn addreloc(a: *asm_, off: u64, kind: i32, s: *asym, add: i64) void = {
|
||||||
let r: *areloc = amalloc(a.a, 64u64): *areloc;
|
let r: *areloc = alloc(areloc { off = off, section = 0, kind = kind, asy = s, addend = add, rnext = a.relocs })!;
|
||||||
r.off = off;
|
|
||||||
r.section = 0; // .text
|
|
||||||
r.kind = kind;
|
|
||||||
r.asy = s;
|
|
||||||
r.addend = add;
|
|
||||||
r.rnext = a.relocs;
|
|
||||||
a.relocs = r;
|
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
|
// DATAR to patch a 64-bit slot with a symbol's runtime VA. obj.ww
|
||||||
// separates these into .rela.data when emitting the .o.
|
// separates these into .rela.data when emitting the .o.
|
||||||
export fn addrelocdata(a: *asm_, off: u64, kind: i32, s: *asym, add: i64) void = {
|
export fn addrelocdata(a: *asm_, off: u64, kind: i32, s: *asym, add: i64) void = {
|
||||||
let r: *areloc = amalloc(a.a, 64u64): *areloc;
|
let r: *areloc = alloc(areloc { off = off, section = 1, kind = kind, asy = s, addend = add, rnext = a.relocs })!;
|
||||||
r.off = off;
|
|
||||||
r.section = 1; // .data
|
|
||||||
r.kind = kind;
|
|
||||||
r.asy = s;
|
|
||||||
r.addend = add;
|
|
||||||
r.rnext = a.relocs;
|
|
||||||
a.relocs = r;
|
a.relocs = r;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -254,10 +242,7 @@ fn labeldefined(a: *asm_, name: str) bool = {
|
|||||||
// ---- fixup helper -----------------------------------------------------
|
// ---- fixup helper -----------------------------------------------------
|
||||||
|
|
||||||
fn addfixup(a: *asm_, off: u64, label: str) void = {
|
fn addfixup(a: *asm_, off: u64, label: str) void = {
|
||||||
let f: *afixup = amalloc(a.a, 48u64): *afixup;
|
let f: *afixup = alloc(afixup { off = off, label = label, fnext = a.fixups })!;
|
||||||
f.off = off;
|
|
||||||
f.label = label;
|
|
||||||
f.fnext = a.fixups;
|
|
||||||
a.fixups = f;
|
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 = {
|
export fn addreloc(a: *asm_, off: u64, kind: i32, s: *asym, add: i64) void = {
|
||||||
let r: *areloc = amalloc(a.a, 64u64): *areloc;
|
let r: *areloc = alloc(areloc { off = off, section = 0, kind = kind, asy = s, addend = add, rnext = a.relocs })!;
|
||||||
r.off = off;
|
|
||||||
r.section = 0; // .text
|
|
||||||
r.kind = kind;
|
|
||||||
r.asy = s;
|
|
||||||
r.addend = add;
|
|
||||||
r.rnext = a.relocs;
|
|
||||||
a.relocs = r;
|
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
|
// DATAR to patch a 64-bit slot with a symbol's runtime VA. obj.ww
|
||||||
// separates these into .rela.data when emitting the .o.
|
// separates these into .rela.data when emitting the .o.
|
||||||
export fn addrelocdata(a: *asm_, off: u64, kind: i32, s: *asym, add: i64) void = {
|
export fn addrelocdata(a: *asm_, off: u64, kind: i32, s: *asym, add: i64) void = {
|
||||||
let r: *areloc = amalloc(a.a, 64u64): *areloc;
|
let r: *areloc = alloc(areloc { off = off, section = 1, kind = kind, asy = s, addend = add, rnext = a.relocs })!;
|
||||||
r.off = off;
|
|
||||||
r.section = 1; // .data
|
|
||||||
r.kind = kind;
|
|
||||||
r.asy = s;
|
|
||||||
r.addend = add;
|
|
||||||
r.rnext = a.relocs;
|
|
||||||
a.relocs = r;
|
a.relocs = r;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1997,10 +1985,7 @@ fn labeldefined(a: *asm_, name: str) bool = {
|
|||||||
// ---- fixup helper -----------------------------------------------------
|
// ---- fixup helper -----------------------------------------------------
|
||||||
|
|
||||||
fn addfixup(a: *asm_, off: u64, label: str) void = {
|
fn addfixup(a: *asm_, off: u64, label: str) void = {
|
||||||
let f: *afixup = amalloc(a.a, 48u64): *afixup;
|
let f: *afixup = alloc(afixup { off = off, label = label, fnext = a.fixups })!;
|
||||||
f.off = off;
|
|
||||||
f.label = label;
|
|
||||||
f.fnext = a.fixups;
|
|
||||||
a.fixups = f;
|
a.fixups = f;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -289,10 +289,7 @@ export fn loadso(l: *lnk, path: *u8) i32 = {
|
|||||||
|
|
||||||
// Build the lso. Exports are appended in dynsym order so
|
// Build the lso. Exports are appended in dynsym order so
|
||||||
// soprovides_v's first-match semantics match the C version.
|
// soprovides_v's first-match semantics match the C version.
|
||||||
let so: *lso = amalloc(l.a, 64u64): *lso;
|
let so: *lso = alloc(lso { path = dcstrtostr(l.a, path), soname = dcstrtostr(l.a, sonamecs) })!;
|
||||||
so.path = dcstrtostr(l.a, path);
|
|
||||||
so.soname = dcstrtostr(l.a, sonamecs);
|
|
||||||
so.exports = nil;
|
|
||||||
let tail: *lexport = nil;
|
let tail: *lexport = nil;
|
||||||
|
|
||||||
let si: u64 = 1u64;
|
let si: u64 = 1u64;
|
||||||
@@ -344,15 +341,10 @@ export fn loadso(l: *lnk, path: *u8) i32 = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (keep != 0) {
|
if (keep != 0) {
|
||||||
let e: *lexport = amalloc(l.a, 48u64): *lexport;
|
let e: *lexport = alloc(lexport { name = dcstrtostr(l.a, nmp) })!;
|
||||||
e.name = dcstrtostr(l.a, nmp);
|
if (vernamecs != nil) {
|
||||||
if (vernamecs == nil) {
|
|
||||||
e.version.ptr = nil;
|
|
||||||
e.version.len = 0i32;
|
|
||||||
} else {
|
|
||||||
e.version = dcstrtostr(l.a, vernamecs);
|
e.version = dcstrtostr(l.a, vernamecs);
|
||||||
};
|
};
|
||||||
e.enext = nil;
|
|
||||||
if (tail == nil) {
|
if (tail == nil) {
|
||||||
so.exports = e;
|
so.exports = e;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -877,7 +877,7 @@ type lsym = struct {
|
|||||||
idxinowner: i32,
|
idxinowner: i32,
|
||||||
// Dynamic-linking fields. Set by resolve when an undefined sym
|
// Dynamic-linking fields. Set by resolve when an undefined sym
|
||||||
// is provided by some loaded lso. pltidx and dynsymidx default
|
// 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,
|
isdyn: i32,
|
||||||
dynlib: *lso,
|
dynlib: *lso,
|
||||||
dynversion: str, // matched export's version; len 0 if none
|
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; };
|
if (streq(s.name, name)) { return s; };
|
||||||
s = s.snext;
|
s = s.snext;
|
||||||
};
|
};
|
||||||
let n: *lsym = amalloc(l.a, 96u64): *lsym;
|
let n: *lsym = alloc(lsym { name = name, snext = l.syms })!;
|
||||||
n.name = name;
|
|
||||||
n.snext = l.syms;
|
|
||||||
l.syms = n;
|
l.syms = n;
|
||||||
return 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
|
// Build the lso. Exports are appended in dynsym order so
|
||||||
// soprovides_v's first-match semantics match the C version.
|
// soprovides_v's first-match semantics match the C version.
|
||||||
let so: *lso = amalloc(l.a, 64u64): *lso;
|
let so: *lso = alloc(lso { path = dcstrtostr(l.a, path), soname = dcstrtostr(l.a, sonamecs) })!;
|
||||||
so.path = dcstrtostr(l.a, path);
|
|
||||||
so.soname = dcstrtostr(l.a, sonamecs);
|
|
||||||
so.exports = nil;
|
|
||||||
let tail: *lexport = nil;
|
let tail: *lexport = nil;
|
||||||
|
|
||||||
let si: u64 = 1u64;
|
let si: u64 = 1u64;
|
||||||
@@ -1931,15 +1926,10 @@ export fn loadso(l: *lnk, path: *u8) i32 = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (keep != 0) {
|
if (keep != 0) {
|
||||||
let e: *lexport = amalloc(l.a, 48u64): *lexport;
|
let e: *lexport = alloc(lexport { name = dcstrtostr(l.a, nmp) })!;
|
||||||
e.name = dcstrtostr(l.a, nmp);
|
if (vernamecs != nil) {
|
||||||
if (vernamecs == nil) {
|
|
||||||
e.version.ptr = nil;
|
|
||||||
e.version.len = 0i32;
|
|
||||||
} else {
|
|
||||||
e.version = dcstrtostr(l.a, vernamecs);
|
e.version = dcstrtostr(l.a, vernamecs);
|
||||||
};
|
};
|
||||||
e.enext = nil;
|
|
||||||
if (tail == nil) {
|
if (tail == nil) {
|
||||||
so.exports = e;
|
so.exports = e;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ type lsym = struct {
|
|||||||
idxinowner: i32,
|
idxinowner: i32,
|
||||||
// Dynamic-linking fields. Set by resolve when an undefined sym
|
// Dynamic-linking fields. Set by resolve when an undefined sym
|
||||||
// is provided by some loaded lso. pltidx and dynsymidx default
|
// 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,
|
isdyn: i32,
|
||||||
dynlib: *lso,
|
dynlib: *lso,
|
||||||
dynversion: str, // matched export's version; len 0 if none
|
dynversion: str, // matched export's version; len 0 if none
|
||||||
@@ -96,9 +96,7 @@ export fn intern(l: *lnk, name: str) *lsym = {
|
|||||||
if (streq(s.name, name)) { return s; };
|
if (streq(s.name, name)) { return s; };
|
||||||
s = s.snext;
|
s = s.snext;
|
||||||
};
|
};
|
||||||
let n: *lsym = amalloc(l.a, 96u64): *lsym;
|
let n: *lsym = alloc(lsym { name = name, snext = l.syms })!;
|
||||||
n.name = name;
|
|
||||||
n.snext = l.syms;
|
|
||||||
l.syms = n;
|
l.syms = n;
|
||||||
return n;
|
return n;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user