Page 1 of 1

binutils default script

Posted: Sat Mar 08, 2014 5:05 pm
by mariuszp
Hello.

I have recently built a cross-compiler from Llinux to my OS, with the canonical name i686-pc-glider.
It produces executables for my OS almost perfectly. The loading address is as it should be (0x00601000). However, there are 2 program headers, and the second one seems to not be aligned properly:

Code: Select all

Program Headers:
  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
  LOAD           0x000000 0x00601000 0x00601000 0x01138 0x01138 R E 0x1000
  LOAD           0x001138 0x00603138 0x00603138 0x00018 0x0003c RW  0x1000
The problem is, it sais in the "align" column that the alignment is 0x1000, however, VirtAddr is 0x00603138, which is not aligned on a page boundary - if that's not the case, then how am I supposed to map the pages with the right flags etc? Or am I just misunderstanding the ELF specification? Is it that VirtAddr-Offset is the actual start of the page?? I'm confused.

If I am actually loading the executable correctly, but the linker is produceing broken executables, how do I modify the source code of ld to make sure that the second program header's VirtAddr is aligned on a page boundary?

Thank you.

Re: binutils default script

Posted: Sat Mar 08, 2014 5:27 pm
by sortie
This is perfectly normal. The important part is that the position in the file and memory is equally unaligned, which means that you can still memory map the executable. You align downwards and then allocating pages until you cover the entire area.

Re: binutils default script

Posted: Sat Mar 08, 2014 5:35 pm
by mariuszp
OK, so basically I start mapping at (VirtAddr & 0xFFFFF000), right?
But do I also have to compute (offset & 0xFFFFF000) to get the position in the file, or is offset actually the position in the file?

Re: binutils default script

Posted: Sat Mar 08, 2014 5:57 pm
by mariuszp
1) Yes
2) No
It works now guys :)

Re: binutils default script

Posted: Sat Mar 08, 2014 6:15 pm
by sortie
Oh, that's good to hear. I was afraid my response was too short. :)