2007-11-28 08:16:41

by murtuja bharmal

[permalink] [raw]
Subject: Linux 2.6 kernel module compilation without using KBUILD

Hello All,

I want to compile external linux kernel module without
using KBUILD.
I tried to find out whole process of kernel module
compilation using KBUILD after enabling flag
KBUILD_VERBOSE=1.

If we look at 2.6 kernel module building process.

1. gcc is making ".hello.o.d" and ".tmp_hello.o"
from "hello.c" file.
2. Creating "hello.o" file using ".hello.o.d"
and ".tmp_hello.o".
3. Running Script "scripts/mod/modpost" to
create "hello.mod.c" using ?hello.o?.
4. gcc is making "hello.mod.o" after compiling
"hello-mod.c" file.
5. finally "ld" is linking "hello.o"
and "hello.mod.o" and making "hello.ko".

Step 2 of above process is not very much cleared, how
it is making hello-2.o from ".hello.o.d" and
".tmp_hello.o".

What is ".tmp_hello.o?.

Do we have any document which describe how to make
kernel module without using KBUILD.

Any pointer of information is very helpful for me.

Thanks
Murtuja Bharmal



____________________________________________________________________________________
Never miss a thing. Make Yahoo your home page.
http://www.yahoo.com/r/hs


2007-11-28 09:02:35

by Sam Ravnborg

[permalink] [raw]
Subject: Re: Linux 2.6 kernel module compilation without using KBUILD

On Wed, Nov 28, 2007 at 12:09:51AM -0800, murtuja bharmal wrote:
> Hello All,
>
> I want to compile external linux kernel module without
> using KBUILD.
...
> Do we have any document which describe how to make
> kernel module without using KBUILD.

No.
Becasue building kernel modules without using kbuild is highly
discouraged and vulnerable for all sort of config related issues.
As a simple example the module may become unuseable if just one
change is made to the configuration because this changes
the parameters passed to gcc which again affects the code
being built.

Can you try to enlighting why you want to avoid kbuild.
If you have a specific problem then maybe kbuild already can
do what you need.

Sam

2007-11-28 09:53:42

by murtuja bharmal

[permalink] [raw]
Subject: Re: Linux 2.6 kernel module compilation without using KBUILD


--- Sam Ravnborg <[email protected]> wrote:

> On Wed, Nov 28, 2007 at 12:09:51AM -0800, murtuja
> bharmal wrote:
> > Hello All,
> >
> > I want to compile external linux kernel module
> without
> > using KBUILD.
> ...
> > Do we have any document which describe how to make
> > kernel module without using KBUILD.
>
> No.
> Becasue building kernel modules without using kbuild
> is highly
> discouraged and vulnerable for all sort of config
> related issues.
> As a simple example the module may become unuseable
> if just one
> change is made to the configuration because this
> changes
> the parameters passed to gcc which again affects the
> code
> being built.
>
> Can you try to enlighting why you want to avoid
> kbuild.
> If you have a specific problem then maybe kbuild
> already can
> do what you need.
>
> Sam
> -
> To unsubscribe from this list: send the line
> "unsubscribe linux-kernel" in
> the body of a message to [email protected]
> More majordomo info at
> http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>
Hello Sam,

My intention is to just understand whole
process of making kernel module.
Actually I am working on one project in which I have
to port lots of 2.4 kernel module in 2.6 kernel.
So I thought lets first try to understand, what is
going behind KBUILD.
I also gone through linux/Documentation/kbuild/ but
didn't get very much information.
Even after running it on Verbose Mode, I am not very
much clear.

Thanks
Murtuja Bharmal



____________________________________________________________________________________
Get easy, one-click access to your favorites.
Make Yahoo! your homepage.
http://www.yahoo.com/r/hs

2007-11-28 09:58:53

by Robert P. J. Day

[permalink] [raw]
Subject: Re: Linux 2.6 kernel module compilation without using KBUILD

On Wed, 28 Nov 2007, murtuja bharmal wrote:

> Hello Sam,
>
> My intention is to just understand whole process of making kernel
> module. Actually I am working on one project in which I have to port
> lots of 2.4 kernel module in 2.6 kernel. So I thought lets first try
> to understand, what is going behind KBUILD. I also gone through
> linux/Documentation/kbuild/ but didn't get very much information.
> Even after running it on Verbose Mode, I am not very much clear.
>
> Thanks
> Murtuja Bharmal

you'd probably be better off asking this on the kernel newbies list
rather than the main kernel list. and, as an intro to porting 2.4 to
2.6 modules, you might want to start here:

http://lwn.net/Articles/driver-porting/

and, as others have suggested, you're probably better off just
figuring out the 2.6 kbuild structure. trying to do this manually
without kbuild is just making this way more difficult than it has to
be.

rday

========================================================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry
Waterloo, Ontario, CANADA

http://crashcourse.ca
========================================================================

2007-11-28 10:40:44

by murtuja bharmal

[permalink] [raw]
Subject: Re: Linux 2.6 kernel module compilation without using KBUILD

--- "Robert P. J. Day" <[email protected]> wrote:

> On Wed, 28 Nov 2007, murtuja bharmal wrote:
>
> > Hello Sam,
> >
> > My intention is to just understand whole process
> of making kernel
> > module. Actually I am working on one project in
> which I have to port
> > lots of 2.4 kernel module in 2.6 kernel. So I
> thought lets first try
> > to understand, what is going behind KBUILD. I also
> gone through
> > linux/Documentation/kbuild/ but didn't get very
> much information.
> > Even after running it on Verbose Mode, I am not
> very much clear.
> >
> > Thanks
> > Murtuja Bharmal
>
> you'd probably be better off asking this on the
> kernel newbies list
> rather than the main kernel list. and, as an intro
> to porting 2.4 to
> 2.6 modules, you might want to start here:
>
> http://lwn.net/Articles/driver-porting/
>
> and, as others have suggested, you're probably
> better off just
> figuring out the 2.6 kbuild structure. trying to do
> this manually
> without kbuild is just making this way more
> difficult than it has to
> be.
>
> rday
>
>
========================================================================
> Robert P. J. Day
> Linux Consulting, Training and Annoying Kernel
> Pedantry
> Waterloo, Ontario, CANADA
>
> http://crashcourse.ca
>
========================================================================
>
Hello Robert,

I think I am not very much clear. Let me try to
clarify more.
My intention is not build or port kernel driver
without using KBUILD.
I know about driver porting and Writing makefile using
KBUILD.
I don't have any issue about that.

I just want understand the whole process for clearity
thats it.
unfortunately I didn't get any answer from linux-doc
and linux-admin about this issue.
Let me try to understand KBUILD internal architecture
more by self.

Any Way.
Thanks for your view.
Murtuja Bharmal



____________________________________________________________________________________
Be a better pen pal.
Text or chat with friends inside Yahoo! Mail. See how. http://overview.mail.yahoo.com/

2007-11-28 10:57:25

by Sam Ravnborg

[permalink] [raw]
Subject: Re: Linux 2.6 kernel module compilation without using KBUILD

>
> My intention is to just understand whole
> process of making kernel module.

The short story....
kbuild knows that .o files listed with obj-m are modules.
So if you have:
obj-m := foo.o

the kbuild will know that it has to build a module named foo.o.
If foo.o consist of composite objects then kbuild
is told so using:
foo-y := bar.o baz.o

So in this case kbuild will build bar.o and baz.o and
use these for the resulting module named foo.

When building baz.o kbuild uses make to search for the source file.
First it look for baz.c - if it fails it look for baz.s
Does both fail kbuild give up (there are some corner cases but ignore that).

When foo.o is ready is uses some linker magic to link in version information
and the end result is foo.ko.

foo.ko has a number of unresolved symbols that are:
1) during build time checked if kernel or other modules define them
2) during load time they are resolved

The above is general stuff - if you need more details please be specific.

Sam