What's the hole in my ELF format file???

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
CodEFouR
Posts: 5
Joined: Wed Mar 07, 2007 10:37 am
Location: Beijing, China

What's the hole in my ELF format file???

Post by CodEFouR »

Hi, I'm starting to write a toy OS. Right now the boot program located at the first 512 bytes on the disk loads a file (ELF executable) and pass the control to it (using jmp). The ELF exe file is linked by the command "ld -emain -Ttext 0x0". Now it's working fine but curiously there is a huge gap between .text section and the program header -- the hole is filled with 0x0 in the ELF file. This annoying garbage takes nearly 4000 bytes, however the instructions, data of the loadable segment take about 400 bytes. I guess it's something about alignment. Can anyone explain this for me? Is there any workaround to prevent from generating this huge hole?
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re: What's the hole in my ELF format file???

Post by Candy »

CodEFouR wrote:Hi, I'm starting to write a toy OS. Right now the boot program located at the first 512 bytes on the disk loads a file (ELF executable) and pass the control to it (using jmp). The ELF exe file is linked by the command "ld -emain -Ttext 0x0". Now it's working fine but curiously there is a huge gap between .text section and the program header -- the hole is filled with 0x0 in the ELF file. This annoying garbage takes nearly 4000 bytes, however the instructions, data of the loadable segment take about 400 bytes. I guess it's something about alignment. Can anyone explain this for me? Is there any workaround to prevent from generating this huge hole?
Question 1: Page alignment.

Question 2:
--file-alignment
Specify the file alignment. Sections in the file will always begin
at file offsets which are multiples of this number. This defaults
to 512. [This option is specific to the i386 PE targeted port of
the linker]

--section-alignment
Sets the section alignment. Sections in memory will always begin
at addresses which are a multiple of this number. Defaults to
0x1000. [This option is specific to the i386 PE targeted port of
the linker]

--nmagic
Turn off page alignment of sections, and mark the output as
"NMAGIC" if possible.
CodEFouR
Posts: 5
Joined: Wed Mar 07, 2007 10:37 am
Location: Beijing, China

Post by CodEFouR »

Thank you very much for your update :lol: I'm gonna try to use the --file-alignment option to eliminate the gap. There are so many options of ld, have you guys read though the whole man page?
Post Reply