w6l: purge dead elf branches; pin rx extent

This commit is contained in:
2026-08-09 04:37:33 +09:00
parent e720d4802f
commit ac8ddee6c1
8 changed files with 33 additions and 29 deletions

View File

@@ -315,10 +315,7 @@ export fn loadso(l: *lnk, path: *u8) i32 = {
switch (vidx) {
case VER_NDX_LOCAL_C:
keep = 0; // not exported
case VER_NDX_GLOBAL_C,1u16:
// glibc's BASE entry (vidx==1): treat as
// unversioned. (The C version notes that
// vidx==1 in Verdef maps to the SONAME BASE.)
case VER_NDX_GLOBAL_C:
vernamecs = nil;
case:
if (verstr != nil) {

View File

@@ -668,6 +668,8 @@ export fn emitdynelf(l: *lnk, fd: i32, base: u64, entry: u64) i32 = {
dwr64(filebuf.ptr, p0 + 16u64, base);
dwr64(filebuf.ptr, p0 + 24u64, base);
dwr64(filebuf.ptr, p0 + 32u64, rxend);
// The loader page-rounds mappings; gotpltoff independently starts
// the next page, so padding is not part of the R+X extent.
dwr64(filebuf.ptr, p0 + 40u64, rxend);
dwr64(filebuf.ptr, p0 + 48u64, PAGE);

View File

@@ -14,8 +14,8 @@ def SHT_SYMTAB: i32 = 2;
def SHT_STRTAB: i32 = 3;
def SHT_RELA: i32 = 4;
// w6a/w6l use straight LE on amd64. Reading via byte offsets keeps us off
// the cgen's u16 field-load story for now (MOVZBQ exists; MOVZWQ doesn't).
// ELF64/x86-64 is little-endian; bytewise decoding also avoids alignment
// and host-layout assumptions about input buffers.
fn rdu16(p: *u8, off: u64) u16 = {
let b0: u16 = p[off]: u16;
@@ -507,9 +507,8 @@ fn loadimage(l: *lnk, path: *u8, buf: *u8, len: u64) i32 = {
};
};
// We don't keep a per-object map[] of *lsym. Instead the reloc
// loop re-walks symtab and re-interns by name. Simpler than
// dancing around the cgen's u64-shift gaps.
// Rewalking avoids retaining an nsyms-sized per-object map solely
// for relocation lookup.
let si: u64 = 1u64; // skip index 0 (always undef sentinel)
for (si < nsyms) {
let symp: u64 = symoff + si * SYM_SIZE;
@@ -526,7 +525,6 @@ fn loadimage(l: *lnk, path: *u8, buf: *u8, len: u64) i32 = {
if (idxdata >= 0) {
indt = (stshndx: i32) == idxdata;
};
if (intext && indt) { indt = false; };
if (intext) {
if (gs.defined != 0) {
let m: str = "w6l: duplicate symbol\n";

View File

@@ -111,6 +111,8 @@ export fn emitelf(l: *lnk, fd: i32, base: u64, entry: u64) i32 = {
wru64(hdr.ptr, 80u64, base); // p_vaddr
wru64(hdr.ptr, 88u64, base); // p_paddr
wru64(hdr.ptr, 96u64, rxend); // p_filesz
// The loader page-rounds mappings; when present, dataoff starts
// independently on the next page, so padding is not R+X extent.
wru64(hdr.ptr, 104u64, rxend); // p_memsz
wru64(hdr.ptr, 112u64, TEXT_OFF); // p_align