Discussion:
.o and .ko file
nidhi mittal
2008-10-27 09:13:33 UTC
Permalink
hi when i compiled a kernel module
i get two files a.o and a.ko file
now my ques is ..
what is difference between two files..
why two object files are created and

then i read smwhere that when we do insmod all symbols used in code are
linked with kernel symbol table....
then 2nd place i read is insmod does loading of module linking is already
done while making .ko file ...

then i was confused pl clarify what is actual purpose of insmod...


and last is i have learnt writing makefile for kernel module but dont
understand why do they reuire first

make -C <kernel makefile path> M = <my module makefile path> modules
i read abt it in LDD too but cd nt understand
as to why do we make it first reach to kernel make file then to our makefile
and what modules target specify...

u may provide me some good link too ...
--
Thanks & Regards
Nidhi
Mulyadi Santosa
2008-10-27 13:57:47 UTC
Permalink
Hi...

I could share something ... hopefully...
Post by nidhi mittal
hi when i compiled a kernel module
i get two files a.o and a.ko file
the .o file is individual object file, while the .ko is the result of
linking every .o files to form the final kernel modules.
Post by nidhi mittal
now my ques is ..
what is difference between two files..
why two object files are created and
actually makefile can be told to directly create the final .ko, but
that way if you change single .c file (the source code) you have to
repeat all the compilation process. That would slow down your
compilation into some degree.

But compiling each .c files into separate .o files, if you chance
single .c file, only one .o file needs to be recompiled while the
rest stay still.
Post by nidhi mittal
then i read smwhere that when we do insmod all symbols used in code are
linked with kernel symbol table....
correct....the external symbols.
Post by nidhi mittal
then 2nd place i read is insmod does loading of module linking is already
done while making .ko file ...
resolving and linking symbols happens during the loading of kernel
module . It's the same when you run a binary that relies on dynamic
shared libraries.
Post by nidhi mittal
and last is i have learnt writing makefile for kernel module but dont
understand why do they reuire first
make -C <kernel makefile path> M = <my module makefile path> modules
i read abt it in LDD too but cd nt understand
as to why do we make it first reach to kernel make file then to our makefile
and what modules target specify...
AFAIK, it is done that way so you don't have to specify things like
library path, CFLAGS and so on. Everything is already defined in main
kernel source's Makefile. So, you get advantage that your Makefile
looks cleaner and more portable.

regards,

Mulyadi.

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ***@nl.linux.org
Please read the FAQ at http://kernelnewbies.org/FAQ
Jagadeesh Bhaskar P
2008-10-27 14:31:58 UTC
Permalink
Oops. Forgot to do a 'reply all'.. :-(
Post by nidhi mittal
what is difference between two files..
why two object files are created and
"Before Linux 2.6, a user space program would interpret the ELF object
(.o) file and do all the work of linking it to the running kernel,
generating a finished binary image. The program would pass that image
to the kernel and the kernel would do little more than stick it in
memory. In Linux 2.6, the kernel does the linking. A user space
program passes the contents of the ELF object file directly to the
kernel. For this to work, the ELF object image must contain additional
information. To identify this particular kind of ELF object file, we
name the file with suffix ".ko" ("kernel object") instead of ".o" For
example, the serial device driver that in Linux 2.4 lived in the file
serial.o in Linux 2.6 lives in the file serial.ko."
Post by nidhi mittal
u may provide me some good link too ...
The paragraph above is taken from :
The Linux Kernel Module Programming Guide (available at TLDP), for 2.6
kernel.
(http://www.tldp.org/LDP/lkmpg/2.6/html/index.html)

Also of interest, would be:
Linux Loadable Kernel Module HOWTO (again from TLDP)
(http://www.tldp.org/LDP/lkmpg/2.6/html/index.html)

You may also try <kerneldir>/Documentation/kbuild/modules.txt

HTH.
Post by nidhi mittal
--
Thanks & Regards
Nidhi
--
With regards,

Jagadeesh Bhaskar P
--------------------
Bugs are by far the largest and most successful class of entity, with nearly
a million known species. In this respect they outnumber all the other known
creatures about four to one.
—Professor Snopes' Encyclopedia of Animal Life
-------
Erik Mouw
2008-10-27 14:03:54 UTC
Permalink
On Mon, 27 Oct 2008 14:43:33 +0530 "nidhi mittal"
<***@gmail.com> wrote:

[...questions...]

I'm not sure what you want to know. Could you rephrase your question
after you read http://www.catb.org/~esr/faqs/smart-questions.html ?


Erik
--
Erik Mouw -- ***@nl.linux.org
GPG key fingerprint: D6AC 7F15 A26E C5C4 62E0 4A58 FCF9 551C 9B48 B68D
Loading...