flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > ELF format problems

Thread Post new topic Reply to topic

Joined: 06 Jan 2005
Posts: 87
I´m writing an OS with fasm and now I wanted to change my fileformat from binary to ELF, but this isn´as easy as I thought Sad There are somethings that fasm does which I don´t understand. These are the things I want:

1. virtual entry address 0xc0100000
2. physical entry address 0x100000
3. virtual addresses of the sections are align on page boundary

If I write this "format ELF executable at 0xc0100000" the addresses are above 0xc0100000, but my entry symbol doesn´t start at 0xc0100000. I think this is because of the elf header.

I have to say that I don´t know how OSs load and execute files. Are they keeping the header of the file in memory or are they interpreting the header and loading only the code and data from a file? Because I don´t need the header after moving the code and data into the right place and so I want that my entry symbol is at 0xc0100000 (virtual and 0x100000 physical)!

I also don´t get the alignment I want and point 2 is also very important for me.
Post 06 Mar 2005, 09:12
View user's profile Send private message Reply with quote
Tomasz Grysztar

Joined: 16 Jun 2003
Posts: 7796
Location: Kraków, Poland
Tomasz Grysztar
This is because of the very specific alignment handling in case of ELF executables. The ELF specification states:
(...) loadable process segments must have
congruent values for p_vaddr and p_offset, modulo the page size.

This means that the address of given section (I mean here the entry in program header, they're also called segments to distinguish from the object sections) modulo page size must be the same as offset in file module page size. So if the size of ELF header is 74h and the first section starts in the file just after the header, offset in file is 74h and address in memory must be 74h module the page size, so fasm makes it be your base address + 74h. So each section doesn't really start at the beginning of its page, but somewhere inside, depending on the alignment in file.
Post 06 Mar 2005, 22:18
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum

Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.