What's the hole in my ELF format file???
What's the hole in my ELF format file???
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?
Re: What's the hole in my ELF format file???
Question 1: Page alignment.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 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.