Page 1 of 1
GDT and Linker script
Posted: Sun Sep 24, 2006 7:12 am
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?
Posted: Sun Sep 24, 2006 1:58 pm
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.