On Mon, 10 Mar 2025 at 15:27, Chu, Benson <b-c...@ti.com> wrote: > I am working on a linker for the RISC-V target, and I was trying > to use qemu-riscv32 to test my linker.
> However, I have noticed that qemu-riscv32 has some restrictions > about how the program can be laid out in memory, and getting my > linker to place the program in a way that qemu-riscv32 will > accept is very annoying. > > By my understanding, for each segment to be loaded, offset into > the ELF file must match the offset into a target page, which > seems to be 4KiB. > > I noticed that GNU ld and LLVM’s lld both follow this placement > by default. Is there some ABI that’s being conformed to for this? > Is there any documentation describing why placement needs to be > done this way? I think that is part of the standard SysV ELF ABI, usually described as the p_offset and p_vaddr having to be "congruent modulo the page size". The underlying reason is that you want to be able to mmap() the pages of the executable file directly into RAM and have them be at the right alignment and offset. thanks -- PMM