GDT and Linker script

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
Nalleee
Posts: 1
Joined: Sun Sep 24, 2006 6:54 am

GDT and Linker script

Post by Nalleee »

Why do I need a linker script if I have set up GDT with code and data descriptors? Linker script's job is to define where data, code and bss segments start so if I have already defined where they start what's the point using linker script then? Am I totally lost?

And I have another problem too: I haven't received a request email from mega-tokyo although I registered there 4 days ago. What's wrong?
SpooK
Member
Member
Posts: 260
Joined: Sun Jun 18, 2006 7:21 pm

Post by SpooK »

You need to spend more time studying the architecture AND the compiler you are using.

You are comparing link-time options vs. run-time structures.

The main point of using a linker is to make sure all the memory addressing in your code correlates to what they will actually be when you load the program into memory. Hence the "starting address" stuff.

The GDT is required by the x86 architecture. In essence, by using LGDT, you are just loading a pointer to your existing data structures (which will probably be in the "data" section). This will only work if you loaded the code (kernel) to the same place you told the linker that it was going to be at.

In short, it is like giving someone the wrong directions to your house... they showed up at the address you gave them... but your house is actually somewhere else.
Post Reply