Page 1 of 1
Loader for statically linked ELF file
Posted: Fri May 10, 2013 1:02 pm
by papillon
I need to write loader for statically linked ELF file. Program should load and execute one ELF file, then another ELF, etc. ELF file have predefined loading address. How to free space on that address if it is allocated by another program? How to transfer control to loading program and how to get it back when program finishes? Which parts should be relocated? What about GOT, PLT, symbols, interp?
Well by this questions, you can see that i'm not very experienced in this. I'm learning, this project is for school.
Re: Loader for statically linked ELF file
Posted: Fri May 10, 2013 2:08 pm
by iansjack
I'm not sure that answering school homework is a very profitable use for this site. You might find that you learn more if you actually researched this for yourself. If you find that difficult you should probably discuss your problems with your teacher.
Re: Loader for statically linked ELF file
Posted: Fri May 10, 2013 2:38 pm
by papillon
Well, you can direct me to some things that i should read. I already have lots of material for reading but maybe you'll show me something that i don't have.
Re: Loader for statically linked ELF file
Posted: Fri May 10, 2013 5:41 pm
by Mikemk
papillon wrote:I already have lots of material for reading
Then read it.
Re: Loader for statically linked ELF file
Posted: Sat May 11, 2013 2:16 am
by iansjack
I already have lots of material for reading but maybe you'll show me something that i don't have.
I'm sure that you will appreciate that it is a bit difficult for me to show you something that you don't have when I don't know what you have.
To my mind, the main point of education is to teach you how to find out answers by yourself. Reading the Wiki here will help for starters.
Re: Loader for statically linked ELF file
Posted: Sat May 11, 2013 2:48 am
by papillon
You are right for learning.
And for ELF file, i'm gonna read segments it using Elf32_Ehdr and Elf32_Phdr, mmap it to memory or to image and then to memory(?).
My problem is "ELF file have predefined loading address. How to free space on that address if it is allocated by another program? How to transfer control to loading program and how to get it back when program finishes?"
Re: Loader for statically linked ELF file
Posted: Sat May 11, 2013 3:15 am
by iansjack
One way to solve the load address issue is to use the same address for all user programs. This is accomplished by using the paging mechanism built in to the processor. This has the added advantage that a program cannot access another program's memory.
Re: Loader for statically linked ELF file
Posted: Sat May 11, 2013 5:43 am
by sortie
Go learn about paging and how fully endlessly wonderful it is. If you are writing an operating system, be sure to implement paging before implementing a program loader.
Re: Loader for statically linked ELF file
Posted: Sat May 11, 2013 6:20 am
by Antti
I just checked the Wikipedia
article about paging. I think it emphasizes perhaps too much secondary storage extension of main memory. However, perhaps the article concentrates on that. It is true that it is an important aspect but I would not considered it the most important thing nowadays. The main thing is the virtual memory so that you can have unique memory space for different programs (with user/system privileges). Also, you are not so dependent on whether physical memory is contiguous or not.
Why I said this? I think there might be some beliefs among beginners that paging is only needed when starting to implement secondary storage extension of main memory. Besides, I strongly believe that this feature is not necessary anymore.