I have a quick question; this is something I haven't been able to figure out. By using the kernel headers you can call functions that are defined in the kernel, but you don't actually have to link to the kernel or any sort of library. How does this work? How does compiled code call the function if it doesn't link to it in some way or another?. -- Take care, Ty my website: http://tds-solutions.net my blog: http://tds-solutions.net/blog skype: st8amnd127 My programs don't have bugs; they're randomly added features!
Hi... On Thu, Jun 30, 2011 at 00:36, Littlefield, Tyler <tyler@tysdomain.com> wrote:
I have a quick question; this is something I haven't been able to figure out. By using the kernel headers you can call functions that are defined in the kernel, but you don't actually have to link to the kernel or any sort of library. How does this work? How does compiled code call the function if it doesn't link to it in some way or another?.
you need to look closer....for example include/linux/mm.h. There you will see definition of constants and functions used for memory management. So, what library here means IMHO are group of headers that contains the needed functions/definitions by themselves. Linking? I think it's better named as "including"...indeed there are linking process during kernel build, but that is just a way to build final image using several objects which originated from the practice of refactoring etc. kindly CMIIW people... -- regards, Mulyadi Santosa Freelance Linux trainer and consultant blog: the-hydra.blogspot.com training: mulyaditraining.blogspot.com
On 6/29/2011 11:46 AM, Mulyadi Santosa wrote:
Hi...
On Thu, Jun 30, 2011 at 00:36, Littlefield, Tyler<tyler@tysdomain.com> wrote:
I have a quick question; this is something I haven't been able to figure out. By using the kernel headers you can call functions that are defined in the kernel, but you don't actually have to link to the kernel or any sort of library. How does this work? How does compiled code call the function if it doesn't link to it in some way or another?. you need to look closer....for example include/linux/mm.h. There you will see definition of constants and functions used for memory management. Sure, the constants and functions are there. Some are externs, some are defined within the header itself, and some are prototypes. Now, in most applications when I want to use another API I include that header and link to the library. This tells the linker that it can pull the functions from that library that I use, and that were defined in the header and include them in the binary.
So, what library here means IMHO are group of headers that contains the needed functions/definitions by themselves. Linking? I think it's better named as "including"...indeed there are linking process during kernel build, but that is just a way to build final image using several objects which originated from the practice of refactoring etc.
Library means... Library here. There is a difference between a library and a header. If you have the prototypes defined in a header the compiler knows that you are going to call those functions (or that you can rather), but how does it know where the function is? How does the linker import the mm functions for example if you only include a header?
kindly CMIIW people...
-- Take care, Ty my website: http://tds-solutions.net my blog: http://tds-solutions.net/blog skype: st8amnd127 My programs don't have bugs; they're randomly added features!
On Wed, Jun 29, 2011 at 11:36:30AM -0600, Littlefield, Tyler wrote:
I have a quick question; this is something I haven't been able to figure out. By using the kernel headers you can call functions that are defined in the kernel,
From userspace? No you can't. You need to use glibc or something else.
The kernel is not a library, the only way to interact with it from userspace is by making system calls. You can use glibc or some libc to make those system calls for you through other functions, or you can call them "raw" if you really know what you are doing. Hope this helps, greg k-h
On Wed, 29 Jun 2011 11:40:40 -0700 Greg KH <greg@kroah.com> wrote:
On Wed, Jun 29, 2011 at 11:36:30AM -0600, Littlefield, Tyler wrote:
I have a quick question; this is something I haven't been able to figure out. By using the kernel headers you can call functions that are defined in the kernel,
From userspace? No you can't. You need to use glibc or something else.
The kernel is not a library, the only way to interact with it from userspace is by making system calls. You can use glibc or some libc to make those system calls for you through other functions, or you can call them "raw" if you really know what you are doing.
Hope this helps,
greg k-h
Or maybe he was actually talking about kernel modules and in this case the linking is done by the kernel itself, at runtime. -- Guillaume Knispel
On Wed, Jun 29, 2011 at 1:36 PM, Littlefield, Tyler <tyler@tysdomain.com> wrote:
I have a quick question; this is something I haven't been able to figure out. By using the kernel headers you can call functions that are defined in the kernel, but you don't actually have to link to the kernel or any sort of library. How does this work? How does compiled code call the function if it doesn't link to it in some way or another?.
Is this a question about userspace apps or kernel modules? Userspace apps link to glibc which in turn has assembly instructions embedded to call into the kernel. Kernel Modules get a different kind of magic, but I'm not sure of those details. Greg
participants (5)
-
Greg Freemyer -
Greg KH -
Guillaume Knispel -
Littlefield, Tyler -
Mulyadi Santosa