* link question
@ 2011-06-29 17:36 Littlefield, Tyler
2011-06-29 17:46 ` Mulyadi Santosa
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Littlefield, Tyler @ 2011-06-29 17:36 UTC (permalink / raw)
To: kernelnewbies
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!
^ permalink raw reply [flat|nested] 6+ messages in thread* link question
2011-06-29 17:36 link question Littlefield, Tyler
@ 2011-06-29 17:46 ` Mulyadi Santosa
2011-06-29 17:56 ` Littlefield, Tyler
2011-06-29 18:40 ` Greg KH
2011-06-29 21:10 ` Greg Freemyer
2 siblings, 1 reply; 6+ messages in thread
From: Mulyadi Santosa @ 2011-06-29 17:46 UTC (permalink / raw)
To: kernelnewbies
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* link question
2011-06-29 17:46 ` Mulyadi Santosa
@ 2011-06-29 17:56 ` Littlefield, Tyler
0 siblings, 0 replies; 6+ messages in thread
From: Littlefield, Tyler @ 2011-06-29 17:56 UTC (permalink / raw)
To: kernelnewbies
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!
^ permalink raw reply [flat|nested] 6+ messages in thread
* link question
2011-06-29 17:36 link question Littlefield, Tyler
2011-06-29 17:46 ` Mulyadi Santosa
@ 2011-06-29 18:40 ` Greg KH
2011-06-29 20:05 ` Guillaume Knispel
2011-06-29 21:10 ` Greg Freemyer
2 siblings, 1 reply; 6+ messages in thread
From: Greg KH @ 2011-06-29 18:40 UTC (permalink / raw)
To: kernelnewbies
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* link question
2011-06-29 18:40 ` Greg KH
@ 2011-06-29 20:05 ` Guillaume Knispel
0 siblings, 0 replies; 6+ messages in thread
From: Guillaume Knispel @ 2011-06-29 20:05 UTC (permalink / raw)
To: kernelnewbies
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* link question
2011-06-29 17:36 link question Littlefield, Tyler
2011-06-29 17:46 ` Mulyadi Santosa
2011-06-29 18:40 ` Greg KH
@ 2011-06-29 21:10 ` Greg Freemyer
2 siblings, 0 replies; 6+ messages in thread
From: Greg Freemyer @ 2011-06-29 21:10 UTC (permalink / raw)
To: kernelnewbies
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
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2011-06-29 21:10 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-29 17:36 link question Littlefield, Tyler
2011-06-29 17:46 ` Mulyadi Santosa
2011-06-29 17:56 ` Littlefield, Tyler
2011-06-29 18:40 ` Greg KH
2011-06-29 20:05 ` Guillaume Knispel
2011-06-29 21:10 ` Greg Freemyer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).