Discussion:
KBUILD_MODNAME issue
Ajith Adapa
2013-02-21 12:15:15 UTC
Permalink
Hi,

I am again hit with KBUILD issue which says as shown below

/home/tmp/linux-26/include/net/inet_connection_sock.h: In function
=C3=A2=E2=82=AC=CB=9Cinet_csk_clear_xmit_timer=C3=A2=E2=82=AC=E2=84=A2:
/home/tmp/linux-26/include/net/inet_connection_sock.h:203:3: error:
=C3=A2=E2=82=AC=CB=9CKBUILD_MODNAME=C3=A2=E2=82=AC=E2=84=A2 undeclared =
(first use in this function)
/home/tmp/linux-26/include/net/inet_connection_sock.h:203:3: note:
each undeclared identifier is reported only once for each function it
appears in
/home/tmp/linux-26/include/net/inet_connection_sock.h: In function
=C3=A2=E2=82=AC=CB=9Cinet_csk_reset_xmit_timer=C3=A2=E2=82=AC=E2=84=A2:
/home/tmp/linux-26/include/net/inet_connection_sock.h:219:3: error:
=C3=A2=E2=82=AC=CB=9CKBUILD_MODNAME=C3=A2=E2=82=AC=E2=84=A2 undeclared =
(first use in this function)

Ideally my understanding is When a module is build KBUILD_MODNAME is
automatically updated.

But I even tried options like -D"KBUILD_MODNAME=3DKBUILD_STR(l2_module)=
"

/usr/bin/gcc -M -g -O2 -DMODULE
-D"KBUILD_MODNAME=3DKBUILD_STR(l2_module)" -D__KERNEL__ -DLINUX
-fno-strict-aliasing -fno-common -ffreestanding -O2 -m32
-fomit-frame-pointer -g -pipe -msoft-float
-mpreferred-stack-boundary=3D2 -fno-unit-at-a-time -march=3Di686
-mtune=3Dpentium4 -mregparm=3D3 -I/lib/modules/3.7.6.1.i686/source
/include -I/lib/modules/3.7.6.1.i686/source/arch/x86/include
-I/lib/modules/3.7.6.1.i686/source/include
-I/lib/modules/3.7.6.1.i686/source/include2
-I/lib/modules/3.7.6.1.i686/source/include/asm/mach-default
-I/lib/modules/3.7.6.1.i686/source/include2/asm/mach-default
-I/lib/modules/3.7.6.1.i686/source/include/uapi
-I/lib/modules/3.7.6.1.i686/source/include/linux/kconfig.h
-I/lib/modules/3.7.6.1.i686/source/include/generated/uapi
-I/lib/modules/3.7.6.1.i686/source/arch/x86/include/generated/uapi
-m32 tmp/l2.c

/lib/modules/3.7.6.1.i686/source/include/net/inet_connection_sock.h:203=
:3:
error: =C3=A2=E2=82=AC=CB=9Cl2_module=C3=A2=E2=82=AC=E2=84=A2 undeclare=
d (first use in this function)

It says it is undeclared.

Anybody have any clue what I messed up this time ? Thanks for the last =
reply

Regards,
Ajith
--------------------------------------------
codingfreak.blogspot.com
That really fixed it .. thanks randy
But Last time when I tried in 2.6.32 kernel I am not including kconf=
ig.h.
Is there any major change by latest 3.7 kernel where we need to add
kconfig.h in code ? Just knowing
Obviously Yes. :)
Any source file (or header file) that uses #IS_ENABLED() or any of it=
s cousins
as defined in <linux/kconfig.h> needs to #include <linux/kconfig.h>.
Regards,
Ajith
--------------------------------------------
codingfreak.in
Hi,
I am not sure if this is the right place to ask the doubt or not b=
ut
since I got this issue building LKM i am dropping a maile down her=
e
sorry for inconvenience caused.
I am trying to build private LKM on latest 3.7 kernel using GCC 4.=
7.2.
/usr/bin/gcc -M -g -O2 -DMODULE -D__KERNEL__ -DLINUX
-fno-strict-aliasing -fno-common -ffreestanding -O2 -m32
-fomit-frame-pointer -g -pipe -msoft-float
-mpreferred-stack-boundary=3D2 -fno-unit-at-a-time -march=3Di686
-mtune=3Dpentium4 -mregparm=3D3 -I/lib/modules/3.7.6.1.i686/source=
/include
-I/lib/modules/3.7.6.1.i686/source/arch/x86/include
-I/lib/modules/3.7.6.1.i686/source/include
-I/lib/modules/3.7.6.1.i686/source/include2
-I/lib/modules/3.7.6.1.i686/source/include/asm/mach-default
-I/lib/modules/3.7.6.1.i686/source/include2/asm/mach-default
-I/lib/modules/3.7.6.1.i686/source/include/uapi
-I/lib/modules/3.7.6.1.i686/source/include/linux/kconfig.h
-I/lib/modules/3.7.6.1.i686/source/include/generated/uapi
-I/lib/modules/3.7.6.1.i686/source/arch/x86/include/generated/uapi
-m32 tmp/l2.c
I get the following error as shown below
In file included from /home/linux-26/include/net/net_namespace.h:1=
3:0,
from /home/linux-26/include/linux/netdevice.h:43,
/home/linux-26/include/net/netns/mib.h:15:15: error: missing binar=
y
operator before token "("
In file included from /home/linux-26/include/net/net_namespace.h:1=
7:0,
from /home/linux-26/include/linux/netdevice.h:43,
/home/linux-26/include/net/netns/ipv6.h:75:15: error: missing bina=
ry
operator before token "("
Any idea about the issue ?? Even I include uapi directory properly=
in
the command.
Does your module source file
#include <linux/kconfig.h>
?
It probably needs to #include that file.
--
~Randy
Randy Dunlap
2013-02-21 16:52:34 UTC
Permalink
Post by Ajith Adapa
Hi,
=20
I am again hit with KBUILD issue which says as shown below
=20
/home/tmp/linux-26/include/net/inet_connection_sock.h: In function
=E2=80=98KBUILD_MODNAME=E2=80=99 undeclared (first use in this functi=
on)
Post by Ajith Adapa
each undeclared identifier is reported only once for each function it
appears in
/home/tmp/linux-26/include/net/inet_connection_sock.h: In function
=E2=80=98KBUILD_MODNAME=E2=80=99 undeclared (first use in this functi=
on)
Post by Ajith Adapa
=20
Ideally my understanding is When a module is build KBUILD_MODNAME is
automatically updated.
=20
But I even tried options like -D"KBUILD_MODNAME=3DKBUILD_STR(l2_modul=
e)"
Post by Ajith Adapa
=20
/usr/bin/gcc -M -g -O2 -DMODULE
-D"KBUILD_MODNAME=3DKBUILD_STR(l2_module)" -D__KERNEL__ -DLINUX
-fno-strict-aliasing -fno-common -ffreestanding -O2 -m32
-fomit-frame-pointer -g -pipe -msoft-float
-mpreferred-stack-boundary=3D2 -fno-unit-at-a-time -march=3Di686
-mtune=3Dpentium4 -mregparm=3D3 -I/lib/modules/3.7.6.1.i686/source
/include -I/lib/modules/3.7.6.1.i686/source/arch/x86/include
-I/lib/modules/3.7.6.1.i686/source/include
-I/lib/modules/3.7.6.1.i686/source/include2
-I/lib/modules/3.7.6.1.i686/source/include/asm/mach-default
-I/lib/modules/3.7.6.1.i686/source/include2/asm/mach-default
-I/lib/modules/3.7.6.1.i686/source/include/uapi
-I/lib/modules/3.7.6.1.i686/source/include/linux/kconfig.h
-I/lib/modules/3.7.6.1.i686/source/include/generated/uapi
-I/lib/modules/3.7.6.1.i686/source/arch/x86/include/generated/uapi
-m32 tmp/l2.c
=20
/lib/modules/3.7.6.1.i686/source/include/net/inet_connection_sock.h:2=
error: =E2=80=98l2_module=E2=80=99 undeclared (first use in this func=
tion)
Post by Ajith Adapa
=20
It says it is undeclared.
=20
Anybody have any clue what I messed up this time ? Thanks for the las=
t reply


The official, expected way to build any (external) kernel module is to =
use a Makefile
for the module and run 'make', e.g.:

$ make -C /path/to/kernel/source M=3D/path/to/module/source [O=3D/path/=
to/kernel/build] modules

That should work. If not, let us know.


--=20
~Randy
Ajith Adapa
2013-02-21 17:55:15 UTC
Permalink
Yeah I agree .. But seems our client is using a customized Make
script. So I disabled CONFIG_DYNAMIC_DEBUG option which is a kind of
temporary hack to my previous issue.

But the Make script follows following steps

1. Create .o for all .c files

2. Create final module.o with all the above .o files

3. Using modpost create Module.markers

/lib/modules/2.6.32.58/source/scripts/mod/modpost -i
/lib/modules/2.6.32.58/source/Module.symvers -S -K
/lib/modules/2.6.32.58/source/Module.markers -M ../l2/Module.markers
=2E./l2/l2_module.o

I guess this step creates modulename.mod.c file

4. Now create modulename.mod.o file

5. Finally link up everything creating .ko file.

Above steps works great with 2.6.32 kernel but When I am trying on 3.7
kernel Step-3 doesn't return anything other than Error 1 at the end.

Seems Modpost is one tough nut to crack as it has doesnt have any
options or debug logs to display its output status.
I thought I will create modpost with -g option enabled to run the GDB
over it to see why it fails.

Is there any doc or wiki page where we can understand different steps
involved in the creation of a .ko file right from step 1 ?

Regards,
Ajith
--------------------------------------------
codingfreak.blogspot.com
Post by Ajith Adapa
Hi,
I am again hit with KBUILD issue which says as shown below
/home/tmp/linux-26/include/net/inet_connection_sock.h: In function
=C3=A2=E2=82=AC=CB=9Cinet_csk_clear_xmit_timer=C3=A2=E2=82=AC=E2=84=A2=
=C3=A2=E2=82=AC=CB=9CKBUILD_MODNAME=C3=A2=E2=82=AC=E2=84=A2 undeclar=
ed (first use in this function)
Post by Ajith Adapa
each undeclared identifier is reported only once for each function i=
t
Post by Ajith Adapa
appears in
/home/tmp/linux-26/include/net/inet_connection_sock.h: In function
=C3=A2=E2=82=AC=CB=9Cinet_csk_reset_xmit_timer=C3=A2=E2=82=AC=E2=84=A2=
=C3=A2=E2=82=AC=CB=9CKBUILD_MODNAME=C3=A2=E2=82=AC=E2=84=A2 undeclar=
ed (first use in this function)
Post by Ajith Adapa
Ideally my understanding is When a module is build KBUILD_MODNAME is
automatically updated.
But I even tried options like -D"KBUILD_MODNAME=3DKBUILD_STR(l2_modu=
le)"
Post by Ajith Adapa
/usr/bin/gcc -M -g -O2 -DMODULE
-D"KBUILD_MODNAME=3DKBUILD_STR(l2_module)" -D__KERNEL__ -DLINUX
-fno-strict-aliasing -fno-common -ffreestanding -O2 -m32
-fomit-frame-pointer -g -pipe -msoft-float
-mpreferred-stack-boundary=3D2 -fno-unit-at-a-time -march=3Di686
-mtune=3Dpentium4 -mregparm=3D3 -I/lib/modules/3.7.6.1.i686/source
/include -I/lib/modules/3.7.6.1.i686/source/arch/x86/include
-I/lib/modules/3.7.6.1.i686/source/include
-I/lib/modules/3.7.6.1.i686/source/include2
-I/lib/modules/3.7.6.1.i686/source/include/asm/mach-default
-I/lib/modules/3.7.6.1.i686/source/include2/asm/mach-default
-I/lib/modules/3.7.6.1.i686/source/include/uapi
-I/lib/modules/3.7.6.1.i686/source/include/linux/kconfig.h
-I/lib/modules/3.7.6.1.i686/source/include/generated/uapi
-I/lib/modules/3.7.6.1.i686/source/arch/x86/include/generated/uapi
-m32 tmp/l2.c
/lib/modules/3.7.6.1.i686/source/include/net/inet_connection_sock.h:=
error: =C3=A2=E2=82=AC=CB=9Cl2_module=C3=A2=E2=82=AC=E2=84=A2 undecl=
ared (first use in this function)
Post by Ajith Adapa
It says it is undeclared.
Anybody have any clue what I messed up this time ? Thanks for the la=
st reply
The official, expected way to build any (external) kernel module is t=
o use a Makefile
$ make -C /path/to/kernel/source M=3D/path/to/module/source [O=3D/pat=
h/to/kernel/build] modules
That should work. If not, let us know.
--
~Randy
Mike Frysinger
2013-02-21 19:03:44 UTC
Permalink
Post by Ajith Adapa
Yeah I agree .. But seems our client is using a customized Make
script.
then tell them they get to pick up the pieces. idiocy should be highlighted &
fixed, not supported.

you can see everything the kernel does if you use the V=1 flag when compiling a
specific module, so you can see what you need to copy. that said, this stuff
semi-frequently changes between releases, so not doing it the right way means
your already fragile build is only going to get worse between kernel versions.
-mike
Ajith Adapa
2013-02-21 19:35:20 UTC
Permalink
Yeah I agree ...

Regards,
Ajith
Post by Mike Frysinger
Post by Ajith Adapa
Yeah I agree .. But seems our client is using a customized Make
script.
then tell them they get to pick up the pieces. idiocy should be highlighted &
fixed, not supported.
you can see everything the kernel does if you use the V=1 flag when compiling a
specific module, so you can see what you need to copy. that said, this stuff
semi-frequently changes between releases, so not doing it the right way means
your already fragile build is only going to get worse between kernel versions.
-mike
Randy Dunlap
2013-02-21 19:42:57 UTC
Permalink
Post by Ajith Adapa
Yeah I agree .. But seems our client is using a customized Make
script. So I disabled CONFIG_DYNAMIC_DEBUG option which is a kind of
temporary hack to my previous issue.
But the Make script follows following steps
1. Create .o for all .c files
2. Create final module.o with all the above .o files
A correct, normal Makefile for external modules does the above
2 steps and then the kernel build handles the rest of it.
Post by Ajith Adapa
3. Using modpost create Module.markers
/lib/modules/2.6.32.58/source/scripts/mod/modpost -i
/lib/modules/2.6.32.58/source/Module.symvers -S -K
/lib/modules/2.6.32.58/source/Module.markers -M ../l2/Module.markers
../l2/l2_module.o
I guess this step creates modulename.mod.c file
4. Now create modulename.mod.o file
5. Finally link up everything creating .ko file.
Above steps works great with 2.6.32 kernel but When I am trying on 3.=
7
Post by Ajith Adapa
kernel Step-3 doesn't return anything other than Error 1 at the end.
Seems Modpost is one tough nut to crack as it has doesnt have any
options or debug logs to display its output status.
I thought I will create modpost with -g option enabled to run the GDB
over it to see why it fails.
Is there any doc or wiki page where we can understand different steps
involved in the creation of a .ko file right from step 1 ?
Regards,
Ajith
--------------------------------------------
codingfreak.blogspot.com
Post by Ajith Adapa
Hi,
I am again hit with KBUILD issue which says as shown below
/home/tmp/linux-26/include/net/inet_connection_sock.h: In function
=C3=A2=E2=82=AC=CB=9Cinet_csk_clear_xmit_timer=C3=A2=E2=82=AC=E2=84=
=C3=A2=E2=82=AC=CB=9CKBUILD_MODNAME=C3=A2=E2=82=AC=E2=84=A2 undecla=
red (first use in this function)
Post by Ajith Adapa
Post by Ajith Adapa
each undeclared identifier is reported only once for each function =
it
Post by Ajith Adapa
Post by Ajith Adapa
appears in
/home/tmp/linux-26/include/net/inet_connection_sock.h: In function
=C3=A2=E2=82=AC=CB=9Cinet_csk_reset_xmit_timer=C3=A2=E2=82=AC=E2=84=
=C3=A2=E2=82=AC=CB=9CKBUILD_MODNAME=C3=A2=E2=82=AC=E2=84=A2 undecla=
red (first use in this function)
Post by Ajith Adapa
Post by Ajith Adapa
Ideally my understanding is When a module is build KBUILD_MODNAME i=
s
Post by Ajith Adapa
Post by Ajith Adapa
automatically updated.
But I even tried options like -D"KBUILD_MODNAME=3DKBUILD_STR(l2_mod=
ule)"
Post by Ajith Adapa
Post by Ajith Adapa
/usr/bin/gcc -M -g -O2 -DMODULE
-D"KBUILD_MODNAME=3DKBUILD_STR(l2_module)" -D__KERNEL__ -DLINUX
-fno-strict-aliasing -fno-common -ffreestanding -O2 -m32
-fomit-frame-pointer -g -pipe -msoft-float
-mpreferred-stack-boundary=3D2 -fno-unit-at-a-time -march=3Di686
-mtune=3Dpentium4 -mregparm=3D3 -I/lib/modules/3.7.6.1.i686/source
/include -I/lib/modules/3.7.6.1.i686/source/arch/x86/include
-I/lib/modules/3.7.6.1.i686/source/include
-I/lib/modules/3.7.6.1.i686/source/include2
-I/lib/modules/3.7.6.1.i686/source/include/asm/mach-default
-I/lib/modules/3.7.6.1.i686/source/include2/asm/mach-default
-I/lib/modules/3.7.6.1.i686/source/include/uapi
-I/lib/modules/3.7.6.1.i686/source/include/linux/kconfig.h
-I/lib/modules/3.7.6.1.i686/source/include/generated/uapi
-I/lib/modules/3.7.6.1.i686/source/arch/x86/include/generated/uapi
-m32 tmp/l2.c
/lib/modules/3.7.6.1.i686/source/include/net/inet_connection_sock.h=
error: =C3=A2=E2=82=AC=CB=9Cl2_module=C3=A2=E2=82=AC=E2=84=A2 undec=
lared (first use in this function)
Post by Ajith Adapa
Post by Ajith Adapa
It says it is undeclared.
Anybody have any clue what I messed up this time ? Thanks for the l=
ast reply
Post by Ajith Adapa
The official, expected way to build any (external) kernel module is =
to use a Makefile
Post by Ajith Adapa
$ make -C /path/to/kernel/source M=3D/path/to/module/source [O=3D/pa=
th/to/kernel/build] modules
Post by Ajith Adapa
That should work. If not, let us know.
--
~Randy
--=20
~Randy
Ajith Adapa
2013-02-21 20:29:39 UTC
Permalink
Yeah currently First 2 steps are successful.

But once moved to third step it fails as it is not generating mod.c fil=
e.

I tried modpost with gdb and found that it is calling read_symbols
with file name as "/lib/modules/2.6.32.58/source/Module.symvers" which
in turn is calling read_elf which is failing.

Cant get much info other than that as optimizations enabled wont let
me know more than that.

Regards,
Ajith
--------------------------------------------
codingfreak.blogspot.com
Post by Randy Dunlap
Post by Ajith Adapa
Yeah I agree .. But seems our client is using a customized Make
script. So I disabled CONFIG_DYNAMIC_DEBUG option which is a kind of
temporary hack to my previous issue.
But the Make script follows following steps
1. Create .o for all .c files
2. Create final module.o with all the above .o files
A correct, normal Makefile for external modules does the above
2 steps and then the kernel build handles the rest of it.
Post by Ajith Adapa
3. Using modpost create Module.markers
/lib/modules/2.6.32.58/source/scripts/mod/modpost -i
/lib/modules/2.6.32.58/source/Module.symvers -S -K
/lib/modules/2.6.32.58/source/Module.markers -M ../l2/Module.marker=
s
Post by Randy Dunlap
Post by Ajith Adapa
../l2/l2_module.o
I guess this step creates modulename.mod.c file
4. Now create modulename.mod.o file
5. Finally link up everything creating .ko file.
Above steps works great with 2.6.32 kernel but When I am trying on 3=
=2E7
Post by Randy Dunlap
Post by Ajith Adapa
kernel Step-3 doesn't return anything other than Error 1 at the end.
Seems Modpost is one tough nut to crack as it has doesnt have any
options or debug logs to display its output status.
I thought I will create modpost with -g option enabled to run the GD=
B
Post by Randy Dunlap
Post by Ajith Adapa
over it to see why it fails.
Is there any doc or wiki page where we can understand different step=
s
Post by Randy Dunlap
Post by Ajith Adapa
involved in the creation of a .ko file right from step 1 ?
Regards,
Ajith
--------------------------------------------
codingfreak.blogspot.com
g>
Post by Randy Dunlap
Post by Ajith Adapa
Post by Ajith Adapa
Hi,
I am again hit with KBUILD issue which says as shown below
/home/tmp/linux-26/include/net/inet_connection_sock.h: In function
=C3=A2=E2=82=AC=CB=9Cinet_csk_clear_xmit_timer=C3=A2=E2=82=AC=E2=84=
/home/tmp/linux-26/include/net/inet_connection_sock.h:203:3: error=
=C3=A2=E2=82=AC=CB=9CKBUILD_MODNAME=C3=A2=E2=82=AC=E2=84=A2 undecl=
ared (first use in this function)
Post by Randy Dunlap
Post by Ajith Adapa
Post by Ajith Adapa
each undeclared identifier is reported only once for each function=
it
Post by Randy Dunlap
Post by Ajith Adapa
Post by Ajith Adapa
appears in
/home/tmp/linux-26/include/net/inet_connection_sock.h: In function
=C3=A2=E2=82=AC=CB=9Cinet_csk_reset_xmit_timer=C3=A2=E2=82=AC=E2=84=
/home/tmp/linux-26/include/net/inet_connection_sock.h:219:3: error=
=C3=A2=E2=82=AC=CB=9CKBUILD_MODNAME=C3=A2=E2=82=AC=E2=84=A2 undecl=
ared (first use in this function)
Post by Randy Dunlap
Post by Ajith Adapa
Post by Ajith Adapa
Ideally my understanding is When a module is build KBUILD_MODNAME =
is
Post by Randy Dunlap
Post by Ajith Adapa
Post by Ajith Adapa
automatically updated.
But I even tried options like -D"KBUILD_MODNAME=3DKBUILD_STR(l2_mo=
dule)"
Post by Randy Dunlap
Post by Ajith Adapa
Post by Ajith Adapa
/usr/bin/gcc -M -g -O2 -DMODULE
-D"KBUILD_MODNAME=3DKBUILD_STR(l2_module)" -D__KERNEL__ -DLINUX
-fno-strict-aliasing -fno-common -ffreestanding -O2 -m32
-fomit-frame-pointer -g -pipe -msoft-float
-mpreferred-stack-boundary=3D2 -fno-unit-at-a-time -march=3Di686
-mtune=3Dpentium4 -mregparm=3D3 -I/lib/modules/3.7.6.1.i686/source
/include -I/lib/modules/3.7.6.1.i686/source/arch/x86/include
-I/lib/modules/3.7.6.1.i686/source/include
-I/lib/modules/3.7.6.1.i686/source/include2
-I/lib/modules/3.7.6.1.i686/source/include/asm/mach-default
-I/lib/modules/3.7.6.1.i686/source/include2/asm/mach-default
-I/lib/modules/3.7.6.1.i686/source/include/uapi
-I/lib/modules/3.7.6.1.i686/source/include/linux/kconfig.h
-I/lib/modules/3.7.6.1.i686/source/include/generated/uapi
-I/lib/modules/3.7.6.1.i686/source/arch/x86/include/generated/uapi
-m32 tmp/l2.c
/lib/modules/3.7.6.1.i686/source/include/net/inet_connection_sock.=
error: =C3=A2=E2=82=AC=CB=9Cl2_module=C3=A2=E2=82=AC=E2=84=A2 unde=
clared (first use in this function)
Post by Randy Dunlap
Post by Ajith Adapa
Post by Ajith Adapa
It says it is undeclared.
Anybody have any clue what I messed up this time ? Thanks for the =
last
Post by Randy Dunlap
Post by Ajith Adapa
Post by Ajith Adapa
reply
The official, expected way to build any (external) kernel module is=
to
Post by Randy Dunlap
Post by Ajith Adapa
use a Makefile
$ make -C /path/to/kernel/source M=3D/path/to/module/source
[O=3D/path/to/kernel/build] modules
That should work. If not, let us know.
--
~Randy
--
~Randy
Loading...