6l: fix text PT_LOAD to use Plan9 ELF convention (off=HEADR, vaddr=IN…#146
Conversation
…ITTEXT) Linux-style text PT_LOAD (off=0, vaddr=INITTEXT-HEADR=0x200000) causes Plan9's kernel ELF loader to map the binary incorrectly, producing "general protection violation" on every ELF binary. Plan9 convention (matching original 6l case 5 and 8l): off=HEADR=0xC00, vaddr=INITTEXT=0x200C00, filesz=textsize, align=INITRND=0x200000. The alignment constraint is satisfied: 0xC00 ≡ 0x200C00 (mod 0x200000). https://claude.ai/code/session_01WGAwvvTwDg2yknFkmZ3qzs
There was a problem hiding this comment.
Code Review
This pull request modifies the ELF program header generation in 6l to align with Plan 9 conventions by setting the file offset to the header size and the virtual address to INITTEXT. A review comment points out that the new alignment logic is fragile because it assumes the header size matches the sub-page offset of INITTEXT; it suggests adding a check to ensure the ELF alignment requirement is maintained to prevent the generation of malformed binaries if the header size changes.
| ph->off = textfoff; /* HEADR=0xC00; Plan9 convention: off=HEADR not 0 */ | ||
| ph->vaddr = INITTEXT; /* 0x200C00; alignment ok: 0xC00 ≡ 0x200C00 (mod 0x200000) */ | ||
| ph->paddr = INITTEXT; | ||
| ph->filesz = textsize; | ||
| ph->memsz = textsize; | ||
| ph->align = INITRND; /* 0x200000 */ |
There was a problem hiding this comment.
The alignment constraint vaddr % align == off % align now depends on textfoff matching the sub-page offset of INITTEXT (e.g., 0xC00). While this works for the current fixed header size, it is fragile. If textfoff changes (e.g., due to additional program headers), the ELF alignment requirement will be violated for the 2MB INITRND. Consider adding a check to ensure textfoff % INITRND == INITTEXT % INITRND to prevent generating malformed binaries if the header size ever deviates.
…ITTEXT)
Linux-style text PT_LOAD (off=0, vaddr=INITTEXT-HEADR=0x200000) causes Plan9's kernel ELF loader to map the binary incorrectly, producing "general protection violation" on every ELF binary.
Plan9 convention (matching original 6l case 5 and 8l): off=HEADR=0xC00, vaddr=INITTEXT=0x200C00, filesz=textsize, align=INITRND=0x200000.
The alignment constraint is satisfied: 0xC00 ≡ 0x200C00 (mod 0x200000).
https://claude.ai/code/session_01WGAwvvTwDg2yknFkmZ3qzs