Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions sys/src/cmd/6l/asm.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ asmbelf(long textfoff, vlong datafoff, vlong datva)
ph = newElfPhdr();
ph->type = PT_LOAD;
ph->flags = PF_R | PF_X;
ph->off = 0; /* cover ELF header from offset 0 */
ph->vaddr = INITTEXT - textfoff; /* 0x200C00 - 0xC00 = 0x200000 */
ph->paddr = INITTEXT - textfoff;
ph->filesz = textfoff + textsize; /* header area + text */
ph->memsz = textfoff + textsize;
ph->align = 0x1000;
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 */
Comment on lines +112 to +117

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.


ph = newElfPhdr();
ph->type = PT_LOAD;
Expand Down
Loading