compiling for my os

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
FlashBurn
Member
Member
Posts: 313
Joined: Fri Oct 20, 2006 10:14 am

compiling for my os

Post by FlashBurn »

Ok, I want to start writing all the programs I need to get my os running (usable. I came across some problems and don´t want to boring you with details how my os works.

I need executable (elf) files which can´t be linked dynamically to libraries. I can link statically or insert the needed files from the libraries (I think I will use the latter). This seems to be no problem at the moment, but I get problems when it comes to creating shared libraries and executable files which need those shared libraries.
I have to say that I´ve never written a program which used shared libraries and compiled it with gcc. So I don´t know how to do that and how it works in detail. I know that the needed libraries stand somewhere in the elf file and I need to load them. I think that I will get the whole linking stuff working (when I loaded the files). As I´ve read the wiki article on porting newlib and creating a tool-chain for my os I read something that it is important where (as of which path) the library is built. So why is that so?

I wanted it (and thought that it is) that way, that in the elf file stand some libraries that I load from somewhere and I then resolve all the needed symbols.
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Re: compiling for my os

Post by jal »

I'm a bit at loss what your exact question is, but are you already capable of running a statically linked ELF in your OS, and now you ar asking how to handle dynamically linked stuff? If so, check the ELF specification. Also, you may have to hack your ELF executable, as the ELF dynamic loading stuff is specifically geared towards POSIX systems (e.g. insisting that /usr/lib/libc.so.1 is the "one valid program interpreter" etc.).


JAL
FlashBurn
Member
Member
Posts: 313
Joined: Fri Oct 20, 2006 10:14 am

Re: compiling for my os

Post by FlashBurn »

I´m also asking how do I compile a shared library and how do I compile a program which uses a shared library.

As for the libc stuff, I´ve had a look at some code from a c library and saw that I maybe have to change some functions where I shouldn´t (like the printf functions). It´s been a while as I looked at the elf documentation. Do I find there information if the path of a shared library is saved in an elf file?

At the moment I´m working on creating a new task and then execute a statically linked elf file. So I hope that I will have this soon working, so that I can start doing the shared library thing.
jal wrote: Also, you may have to hack your ELF executable, as the ELF dynamic loading stuff is specifically geared towards POSIX systems (e.g. insisting that /usr/lib/libc.so.1 is the "one valid program interpreter" etc.).
I read something about that I need to have a ld.so which does the whole dynamic linking stuff, but as I planed it to work, the most of the work is done by the kernel.
computafreak
Member
Member
Posts: 76
Joined: Sun Dec 14, 2008 1:53 pm

Re: compiling for my os

Post by computafreak »

FlashBurn wrote:It´s been a while as I looked at the elf documentation. Do I find there information if the path of a shared library is saved in an elf file?
You can look for the DT_NEEDED elements in the DYNAMIC section. They've got a value which is relative from the start of a string table. You match that up against the DT_SONAME elements in the same section (same value).

I had an interesting challenge when I decided to implement dynamic linking in my previous kernel. If you want to see how I did things, I posted the steps on my user page (link.) There are probably a lot of assumptions in there, like assuming the string table used instead of reading the address from DT_STRTAB, but it worked for me.
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Re: compiling for my os

Post by jal »

FlashBurn wrote:I´m also asking how do I compile a shared library and how do I compile a program which uses a shared library.
If you Google you'll find the answer quickly. -fPIC and -shared are two flags you'll probably need when creating one. But really, Google.


JAL
Post Reply