login
Header Space

 
 

about Linker

June 4, 2008 - 2:26am
Submitted by Anonymous on June 4, 2008 - 2:26am.
Linux

How does the linker know that kernel is getting compiled or user application is getting compiled ?

They are just the same things to the linker

June 5, 2008 - 8:26am

AFAIK, for the linker they are just the same because all that the linker does is to resolve the compiler's unresolved symbols to addresses.

Anyway, why did you expect that compiling kernel should be different from compiling a user application? After all the compiler also does not differentiate between compiling a kernel and a user application.

about Linker

June 5, 2008 - 8:43am
Anonymous (not verified)

I thought becuase Liner and loader actually load the segment registers on x86.
if kerenl or user level application then they should load the segment selectors accordingly..
so there should be someway for linker to know that yeah I need to put a kernel code segment selector into the register while accessing kernel code segment.
that is why I raised the questions.

why linker

June 5, 2008 - 3:56pm

iirc the segment registers are set up by the kernel (which makes corresponding entries in the GDT/LDT before to bring the selector into existence before -- what do you think a kernel is doing) and never modified by user space like linker or loader. as i wrote last week there is no reason to set segment registers at all. you had to do segment arithmetics on 16 bit systems but these times are over. are you talking about relocation? of course loaders still relocate code and variables, but not by doing anything with segment registers. and there is a concept of a 'segment' which is just a bundle of variables or code with similar attributes. see documentation collected in http://en.wikipedia.org/wiki/Executable_and_Linkable_Format

linker/loader and segment register

June 8, 2008 - 2:16am
Anonymous (not verified)

I understand what you are saying....
I finally put it into my words and please let me know whether my understanding is correct.

=> segment registers are initially set by kernel itself may be during booting..
=> while writing user space programs when we make a system call or entering into kernel space or user space there is no need to set segment register again because it is always fixed.
=> while relocating the code linkers-loaders actually changes the addresses relatively. but it does not touch the segment register..
=> what we all talked about is protected flat model where we really do not use segmentation fully..
=> but still my doubt what happens if we use segmented (x86) model...
where I think definately linker and loader need to change the segment registers all the time for each processes...

please correct me if I am wrong somewhere...
thank you very much for you inputs, they were helpful to me.

segment registers

June 8, 2008 - 7:34pm
Juri (not verified)

from my experience, the segment registers are played with during the transition from user space to kernel space. this way the kernel can quickly tell what 'space' a pointer is from by checking its address real quickly.

it may help you to read http://linuxgazette.net/112/krishnakumar.html [Experiments with the Linux Kernel: Process Segments] .

aboue linker/loader and segment registers

June 8, 2008 - 11:51pm
Matt Kleviar (not verified)

I am not sure whether last comment made by juri, is completely correct. because the article does not talk about segment registers at all.
pleae see the fourth comments made by me.

=> I still believe that while compiling the program for flat address space model (x86) , linker and loader does not need to modify segment registers. because it is set by kernel initiallly and they are all fixed all the time indexing into the GDT.

=> only we need to think what would happen if linux kernel is port to the segmented model of x86 !! ?

clarification

June 9, 2008 - 3:46pm
Juri (not verified)

to clarify matters, i believe i may be describing the wrong system. too close to the code, i think. aparently, i don't understand these things as well as i think i do. i guess its time to re-read the o'reilly "understanding the linux kernel" book, for me.

you should grab a copy yourself. i'm betting it has the answer in it.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
speck-geostationary