cmd: α/γ-4 rt.malloc → alloc([], N)! (w6a/w6c/w6l file slurps + sized bufs)
Phase 0 #8 fourth α-batch. 10 α/γ conversions across 6 files: - w6a/main.ww slurp (1) - w6c/main.ww slurp (1) - w6l/dyn.ww slurpso (1) - w6l/obj.ww slurp (1) - w6l/dynout.ww filebuf at :661 (1; threads .ptr through ~50 dwr*/dbcopy callees — that's the 139-line w6l/dynout diff) - w6l/out.ww hdr at :92 (1) - w6l/main.ww 4 sites: bufp + γ {inputs, libdirs, lflags} (4) Deferred: - w6l/main.ww 3× 16/8/20-byte δ fixed-bufs at :67/:106/:176 → stack-promote in a separate sub-task. - w6l/obj.ww :113/:135 β text-buffer growth → memio.dynamic refactor. Pattern unchanged from 47918d3/00d88ff/e9eb67d: `alloc([], N: u64)!` + `buf.len = N: i32;` + `buf.ptr` for callees taking `*u8`. γ uses element-count (was bytes): `maxinputs: u64` not `maxinputs*8u64`. Verified 132/132 + 995_self_rebuild byte-identity. Advances #45.
This commit is contained in:
@@ -658,99 +658,96 @@ export fn emitdynelf(l: *lnk, fd: i32, base: u64, entry: u64) i32 = {
|
||||
};
|
||||
|
||||
// ---- assemble file buffer ----
|
||||
let filebuf: *u8 = rt.malloc(fileend): *u8;
|
||||
if (filebuf == nil) {
|
||||
os.write(2, "w6l: out of memory\n".ptr, 18u64);
|
||||
return 1;
|
||||
};
|
||||
let filebuf: []u8 = alloc([], fileend)!;
|
||||
filebuf.len = fileend: i32;
|
||||
|
||||
// Ehdr
|
||||
dwr8(filebuf, 0u64, 127u8);
|
||||
dwr8(filebuf, 1u64, 69u8);
|
||||
dwr8(filebuf, 2u64, 76u8);
|
||||
dwr8(filebuf, 3u64, 70u8);
|
||||
dwr8(filebuf, 4u64, ELFCLASS64_D);
|
||||
dwr8(filebuf, 5u64, ELFDATA2LSB_D);
|
||||
dwr8(filebuf, 6u64, EV_CURRENT_D: u8);
|
||||
dwr16(filebuf, 16u64, ET_EXEC_D);
|
||||
dwr16(filebuf, 18u64, EM_X86_64_D);
|
||||
dwr32(filebuf, 20u64, EV_CURRENT_D);
|
||||
dwr64(filebuf, 24u64, entry);
|
||||
dwr64(filebuf, 32u64, ehdrsz);
|
||||
dwr64(filebuf, 40u64, 0u64);
|
||||
dwr32(filebuf, 48u64, 0u32);
|
||||
dwr16(filebuf, 52u64, ehdrsz: u16);
|
||||
dwr16(filebuf, 54u64, 56u16);
|
||||
dwr16(filebuf, 56u64, nphdrs: u16);
|
||||
dwr16(filebuf, 58u64, 0u16);
|
||||
dwr16(filebuf, 60u64, 0u16);
|
||||
dwr16(filebuf, 62u64, 0u16);
|
||||
dwr8(filebuf.ptr, 0u64, 127u8);
|
||||
dwr8(filebuf.ptr, 1u64, 69u8);
|
||||
dwr8(filebuf.ptr, 2u64, 76u8);
|
||||
dwr8(filebuf.ptr, 3u64, 70u8);
|
||||
dwr8(filebuf.ptr, 4u64, ELFCLASS64_D);
|
||||
dwr8(filebuf.ptr, 5u64, ELFDATA2LSB_D);
|
||||
dwr8(filebuf.ptr, 6u64, EV_CURRENT_D: u8);
|
||||
dwr16(filebuf.ptr, 16u64, ET_EXEC_D);
|
||||
dwr16(filebuf.ptr, 18u64, EM_X86_64_D);
|
||||
dwr32(filebuf.ptr, 20u64, EV_CURRENT_D);
|
||||
dwr64(filebuf.ptr, 24u64, entry);
|
||||
dwr64(filebuf.ptr, 32u64, ehdrsz);
|
||||
dwr64(filebuf.ptr, 40u64, 0u64);
|
||||
dwr32(filebuf.ptr, 48u64, 0u32);
|
||||
dwr16(filebuf.ptr, 52u64, ehdrsz: u16);
|
||||
dwr16(filebuf.ptr, 54u64, 56u16);
|
||||
dwr16(filebuf.ptr, 56u64, nphdrs: u16);
|
||||
dwr16(filebuf.ptr, 58u64, 0u16);
|
||||
dwr16(filebuf.ptr, 60u64, 0u16);
|
||||
dwr16(filebuf.ptr, 62u64, 0u16);
|
||||
|
||||
// Phdrs at offset 64.
|
||||
let p0: u64 = 64u64;
|
||||
dwr32(filebuf, p0 + 0u64, PT_LOAD_D);
|
||||
dwr32(filebuf, p0 + 4u64, PF_R_D | PF_X_D);
|
||||
dwr64(filebuf, p0 + 8u64, 0u64);
|
||||
dwr64(filebuf, p0 + 16u64, base);
|
||||
dwr64(filebuf, p0 + 24u64, base);
|
||||
dwr64(filebuf, p0 + 32u64, rxend);
|
||||
dwr64(filebuf, p0 + 40u64, rxend);
|
||||
dwr64(filebuf, p0 + 48u64, PAGE);
|
||||
dwr32(filebuf.ptr, p0 + 0u64, PT_LOAD_D);
|
||||
dwr32(filebuf.ptr, p0 + 4u64, PF_R_D | PF_X_D);
|
||||
dwr64(filebuf.ptr, p0 + 8u64, 0u64);
|
||||
dwr64(filebuf.ptr, p0 + 16u64, base);
|
||||
dwr64(filebuf.ptr, p0 + 24u64, base);
|
||||
dwr64(filebuf.ptr, p0 + 32u64, rxend);
|
||||
dwr64(filebuf.ptr, p0 + 40u64, rxend);
|
||||
dwr64(filebuf.ptr, p0 + 48u64, PAGE);
|
||||
|
||||
let p1: u64 = 64u64 + 56u64;
|
||||
dwr32(filebuf, p1 + 0u64, PT_LOAD_D);
|
||||
dwr32(filebuf, p1 + 4u64, PF_R_D | PF_W_D);
|
||||
dwr64(filebuf, p1 + 8u64, gotpltoff);
|
||||
dwr64(filebuf, p1 + 16u64, gotpltva);
|
||||
dwr64(filebuf, p1 + 24u64, gotpltva);
|
||||
dwr32(filebuf.ptr, p1 + 0u64, PT_LOAD_D);
|
||||
dwr32(filebuf.ptr, p1 + 4u64, PF_R_D | PF_W_D);
|
||||
dwr64(filebuf.ptr, p1 + 8u64, gotpltoff);
|
||||
dwr64(filebuf.ptr, p1 + 16u64, gotpltva);
|
||||
dwr64(filebuf.ptr, p1 + 24u64, gotpltva);
|
||||
// filesz trims the .data trailing zeros (BSS); memsz covers
|
||||
// .got.plt + .dynamic + the full .data so the loader zero-fills.
|
||||
dwr64(filebuf, p1 + 32u64, filedataend - gotpltoff);
|
||||
dwr64(filebuf, p1 + 40u64, fileend - gotpltoff);
|
||||
dwr64(filebuf, p1 + 48u64, PAGE);
|
||||
dwr64(filebuf.ptr, p1 + 32u64, filedataend - gotpltoff);
|
||||
dwr64(filebuf.ptr, p1 + 40u64, fileend - gotpltoff);
|
||||
dwr64(filebuf.ptr, p1 + 48u64, PAGE);
|
||||
|
||||
let p2: u64 = 64u64 + 112u64;
|
||||
dwr32(filebuf, p2 + 0u64, PT_INTERP_D);
|
||||
dwr32(filebuf, p2 + 4u64, PF_R_D);
|
||||
dwr64(filebuf, p2 + 8u64, interpoff);
|
||||
dwr64(filebuf, p2 + 16u64, interpva);
|
||||
dwr64(filebuf, p2 + 24u64, interpva);
|
||||
dwr64(filebuf, p2 + 32u64, interpsz);
|
||||
dwr64(filebuf, p2 + 40u64, interpsz);
|
||||
dwr64(filebuf, p2 + 48u64, 1u64);
|
||||
dwr32(filebuf.ptr, p2 + 0u64, PT_INTERP_D);
|
||||
dwr32(filebuf.ptr, p2 + 4u64, PF_R_D);
|
||||
dwr64(filebuf.ptr, p2 + 8u64, interpoff);
|
||||
dwr64(filebuf.ptr, p2 + 16u64, interpva);
|
||||
dwr64(filebuf.ptr, p2 + 24u64, interpva);
|
||||
dwr64(filebuf.ptr, p2 + 32u64, interpsz);
|
||||
dwr64(filebuf.ptr, p2 + 40u64, interpsz);
|
||||
dwr64(filebuf.ptr, p2 + 48u64, 1u64);
|
||||
|
||||
let p3: u64 = 64u64 + 168u64;
|
||||
dwr32(filebuf, p3 + 0u64, PT_DYNAMIC_D);
|
||||
dwr32(filebuf, p3 + 4u64, PF_R_D | PF_W_D);
|
||||
dwr64(filebuf, p3 + 8u64, dynamicoff);
|
||||
dwr64(filebuf, p3 + 16u64, dynamicva);
|
||||
dwr64(filebuf, p3 + 24u64, dynamicva);
|
||||
dwr64(filebuf, p3 + 32u64, dynamicsz);
|
||||
dwr64(filebuf, p3 + 40u64, dynamicsz);
|
||||
dwr64(filebuf, p3 + 48u64, 8u64);
|
||||
dwr32(filebuf.ptr, p3 + 0u64, PT_DYNAMIC_D);
|
||||
dwr32(filebuf.ptr, p3 + 4u64, PF_R_D | PF_W_D);
|
||||
dwr64(filebuf.ptr, p3 + 8u64, dynamicoff);
|
||||
dwr64(filebuf.ptr, p3 + 16u64, dynamicva);
|
||||
dwr64(filebuf.ptr, p3 + 24u64, dynamicva);
|
||||
dwr64(filebuf.ptr, p3 + 32u64, dynamicsz);
|
||||
dwr64(filebuf.ptr, p3 + 40u64, dynamicsz);
|
||||
dwr64(filebuf.ptr, p3 + 48u64, 8u64);
|
||||
|
||||
// Sections.
|
||||
dbcopy(filebuf, interpoff, INTERP.ptr, INTERP.len: u64);
|
||||
dwr8(filebuf, interpoff + (INTERP.len: u64), 0u8);
|
||||
dbcopy(filebuf, dynstroff, dynstr, dynstrsz);
|
||||
dbcopy(filebuf, dynsymoff, dynsymbuf, dynsymsz);
|
||||
dbcopy(filebuf, hashoff, hashbuf, hashsz);
|
||||
dbcopy(filebuf, versymoff, versymbuf, versymsz);
|
||||
dbcopy(filebuf.ptr, interpoff, INTERP.ptr, INTERP.len: u64);
|
||||
dwr8(filebuf.ptr, interpoff + (INTERP.len: u64), 0u8);
|
||||
dbcopy(filebuf.ptr, dynstroff, dynstr, dynstrsz);
|
||||
dbcopy(filebuf.ptr, dynsymoff, dynsymbuf, dynsymsz);
|
||||
dbcopy(filebuf.ptr, hashoff, hashbuf, hashsz);
|
||||
dbcopy(filebuf.ptr, versymoff, versymbuf, versymsz);
|
||||
if (verneedsz > 0u64) {
|
||||
dbcopy(filebuf, verneedoff, verneedbuf, verneedsz);
|
||||
dbcopy(filebuf.ptr, verneedoff, verneedbuf, verneedsz);
|
||||
};
|
||||
dbcopy(filebuf, relapltoff, relapltbuf, relapltsz);
|
||||
dbcopy(filebuf.ptr, relapltoff, relapltbuf, relapltsz);
|
||||
if (l.textlen > 0u64) {
|
||||
dbcopy(filebuf, textoff, l.text, l.textlen);
|
||||
dbcopy(filebuf.ptr, textoff, l.text, l.textlen);
|
||||
};
|
||||
dbcopy(filebuf, pltoff, pltbuf, pltsz);
|
||||
dbcopy(filebuf, gotpltoff, gotpltbuf, gotpltsz);
|
||||
dbcopy(filebuf, dynamicoff, dynamicbuf, dynamicsz);
|
||||
dbcopy(filebuf.ptr, pltoff, pltbuf, pltsz);
|
||||
dbcopy(filebuf.ptr, gotpltoff, gotpltbuf, gotpltsz);
|
||||
dbcopy(filebuf.ptr, dynamicoff, dynamicbuf, dynamicsz);
|
||||
if (datafilelen > 0u64) {
|
||||
dbcopy(filebuf, dataoff, l.data, datafilelen);
|
||||
dbcopy(filebuf.ptr, dataoff, l.data, datafilelen);
|
||||
};
|
||||
|
||||
let wr: (i64 | os.oserror) = os.writeall(fd, filebuf, filedataend);
|
||||
let wr: (i64 | os.oserror) = os.writeall(fd, filebuf.ptr, filedataend);
|
||||
match (wr) {
|
||||
case let v: i64 => { if (v != filedataend: i64) { return 1; }; };
|
||||
case let e: os.oserror => return 1;
|
||||
|
||||
Reference in New Issue
Block a user