OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 8:11 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: ELF Loader question
PostPosted: Mon Sep 11, 2017 7:46 am 
Offline
Member
Member

Joined: Thu Mar 14, 2013 1:30 am
Posts: 78
Hi, I'm implementing ELF loader using program headers. I find something quiet strange. I have two program headers that are marked to be 0x1000 aligned.
However, the second program header is marked to be loaded to not 0x1000 aligned address.
Does it make sense ?

Here's the dump of the sections:
DEBUG: Header: 0 Type: 1 Offset: 0x0 V-addr: 0x8048000 P-addr: 0x8048000 FSize: 0x270c MSize: 0x270c Flags: 5 Align: 1000
DEBUG: Header: 1 Type: 1 Offset: 0x270c V-addr: 0x804b70c P-addr: 0x804b70c FSize: 0x2184 MSize: 0x21fc Flags: 6 Align: 1000

_________________
“Meaningless! Meaningless!”
says the Teacher.
“Utterly meaningless!
Everything is meaningless.” - Ecclesiastes 1, 2

Educational Purpose Operating System - EPOS


Top
 Profile  
 
 Post subject: Re: ELF Loader question
PostPosted: Mon Sep 11, 2017 10:11 am 
Offline
Member
Member

Joined: Fri Aug 19, 2016 10:28 pm
Posts: 360
Apparently, the requirement is that "p_vaddr should equal p_offset, modulo p_align", as per the man. The man also says that "This member holds the value to which the segments are aligned in memory and in the file", but that statement is it seems a dud. You may also want to check the related SO answer here, which I used for clarification to your question :). The static linker can however achieve actual page alignment of the data, by making sure that p_vaddr is on a page boundary. If not, the role of p_align is to guarantee that the elf segments can be loaded by memory mapping, not copying.

Note also that the virtual addresses are not consecutive with respect to the file offsets. There is a page gap 0x804a70c-0x804b70c in order to allow differential application of page access flags (which involves mapping the file block at 0x2000 from the same physical frame in memory twice in the process address space using different PTEs). Normally, that would be considered security exploit (and I am still not sure that it is not to some degree), but the first segment is usually header information and is hopefully non-impacting after the program loading have finished.

P.S. I hope that someone else will collaborate or contradict this. Although the evidence demonstrates that this is the case, I haven't programmed an actual elf loader, in order to be certain.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: DotBot [Bot] and 47 guests


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group