binutils default script

Programming, for all ages and all languages.
Post Reply
mariuszp
Member
Member
Posts: 587
Joined: Sat Oct 16, 2010 3:38 pm

binutils default script

Post 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.
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Re: binutils default script

Post 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.
mariuszp
Member
Member
Posts: 587
Joined: Sat Oct 16, 2010 3:38 pm

Re: binutils default script

Post 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?
mariuszp
Member
Member
Posts: 587
Joined: Sat Oct 16, 2010 3:38 pm

Re: binutils default script

Post by mariuszp »

1) Yes
2) No
It works now guys :)
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Re: binutils default script

Post by sortie »

Oh, that's good to hear. I was afraid my response was too short. :)
Post Reply