Kernel Newbies archive on lore.kernel.org
 help / color / Atom feed
* Kernel Module with multiple source files not initializing
@ 2019-10-25  9:14 Irfan Ullah (울라 이르판)
  2019-10-25 16:15 ` Abu Rasheda
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Irfan Ullah (울라 이르판) @ 2019-10-25  9:14 UTC (permalink / raw)
  To: kernelnewbies

[-- Attachment #1.1: Type: text/plain, Size: 3491 bytes --]

Dear All,
I have developed a kernel module consists of one source file that sends and
receives  message to the user space.  I have spitted the source code in two
files, and now I  am trying to develop kernel module from these source
files. After compiling and linking without any problems, I insmod the
module but I didn’t see any of the printk() I wrote, in fact, the module
can be inserted and removed, but it does nothing. Code is in the attached
file zipped file.
I tried many things , e.g.,  link <https://paguilar.org/?p=7>1, link2
<https://www.linuxquestions.org/questions/linux-kernel-70/kernel-module-with-multiple-source-files-not-initializing-886190/>,
and link3
<https://android.googlesource.com/kernel/msm/+/android-msm-dory-3.10-kitkat-wear/Documentation/kbuild/modules.txt>
etc.
but nothings worked out.
I also used *nm* to inspect the module, but, as expected, there was no
signs of "__init and __exit" functions can in the output.
                                 U __alloc_skb
00000000000001c0 T create_socket
0000000000000030 T data_update
                                 U __fentry__
                                 U fortify_panic
0000000000000000 r __func__.5058
                                 U init_net
0000000000000000 t kernel_space_receiver
0000000000000080 T kernel_space_sender
                                  U memcpy
0000000000000038 r __module_depends
0000000000000008 D msg_size
                                 U msleep
                                 U __netlink_kernel_create
                                 U netlink_kernel_release
                                 U netlink_unicast
0000000000000078 B nlh
                                 U __nlmsg_put
0000000000000080 B nl_sk
0000000000000000 r _note_6
0000000000000004 D pid
                                 U printk
0000000000000000 D res
0000000000000000 B s_data
0000000000000070 B skb_out
                                  U __stack_chk_fail
                                  U strlen
0000000000000000 D __this_module
0000000000000000 r __UNIQUE_ID_license381
000000000000004d r __UNIQUE_ID_name240
0000000000000041 r __UNIQUE_ID_retpoline241
0000000000000010 r __UNIQUE_ID_srcversion242
0000000000000068 r __UNIQUE_ID_vermagic239
--------------------
*Following is the output of some useful commands:*
-------------------------------------------------
*ssd@ssd:~/Desktop/Kernel_User_comm$ ls*
Makefile  netlink_kernel_module.c  netlink_kernel_space.c
 netlink_kernel_space.h  netlink_user_module.c
---------------------------------------------------
*ssd@ssd:~/Kernel_User_comm$ make --version*
GNU Make 4.1
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html
>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
-------------------------------------------------------
*ssd@ssd:~/Kernel_User_comm$ uname -r*
5.2.0-rc6
--------------------------------------------------------
Can you please help me: what's the problem/mistake I am doing?
Thank you very much.

-- 
*Best Regards,*


*Mr. Irfan Ullah*
PhD Candidate
Data and Knowledge Engineering(DKE) Lab
Department of Computer Science and Engineering
Kyung Hee University, South Korea.
 +82-010-591-51651 <+82%2010-3877-8867>
  sahibzada.iu@gmail.com
 sahibzada_irfanullah

[-- Attachment #1.2: Type: text/html, Size: 5970 bytes --]

<div dir="ltr">Dear All,<div>I have developed a kernel module consists of one source file that sends and receives  message to the user space.  I have spitted the source code in two files, and now I  am trying to develop kernel module from these source files. After compiling and linking without any problems, I insmod the module but I didn’t see any of the printk() I wrote, in fact, the module can be inserted and removed, but it does nothing. Code is in the attached file zipped file.</div><div>I tried many things , e.g.,  <a href="https://paguilar.org/?p=7" target="_blank">link</a>1, <a href="https://www.linuxquestions.org/questions/linux-kernel-70/kernel-module-with-multiple-source-files-not-initializing-886190/" target="_blank">link2</a>, and <a href="https://android.googlesource.com/kernel/msm/+/android-msm-dory-3.10-kitkat-wear/Documentation/kbuild/modules.txt" target="_blank">link3</a> etc.  but nothings worked out. </div><div>I also used <i>nm</i> to inspect the module, but, as expected, there was no signs of &quot;__init and __exit&quot; functions can in the output. </div><font color="#a64d79">                             </font><font color="#741b47">    U __alloc_skb<br>00000000000001c0 T create_socket<br>0000000000000030 T data_update<br>                                 U __fentry__<br>                                 U fortify_panic<br>0000000000000000 r __func__.5058<br>                                 U init_net<br>0000000000000000 t kernel_space_receiver<br>0000000000000080 T kernel_space_sender<br>                                  U memcpy<br>0000000000000038 r __module_depends<br>0000000000000008 D msg_size<br>                                 U msleep<br>                                 U __netlink_kernel_create<br>                                 U netlink_kernel_release<br>                                 U netlink_unicast<br>0000000000000078 B nlh<br>                                 U __nlmsg_put<br>0000000000000080 B nl_sk<br>0000000000000000 r _note_6<br>0000000000000004 D pid<br>                                 U printk<br>0000000000000000 D res<br>0000000000000000 B s_data<br>0000000000000070 B skb_out<br>                                  U __stack_chk_fail<br>                                  U strlen<br>0000000000000000 D __this_module<br>0000000000000000 r __UNIQUE_ID_license381<br>000000000000004d r __UNIQUE_ID_name240<br>0000000000000041 r __UNIQUE_ID_retpoline241<br>0000000000000010 r __UNIQUE_ID_srcversion242<br>0000000000000068 r __UNIQUE_ID_vermagic239</font><div>--------------------</div><div><b>Following is the output of some useful commands:</b></div><div>-------------------------------------------------</div><div><b>ssd@ssd:~/Desktop/Kernel_User_comm$ ls</b><br><font color="#741b47">Makefile  netlink_kernel_module.c  netlink_kernel_space.c  netlink_kernel_space.h  netlink_user_module.c</font><br></div><div>---------------------------------------------------</div><div><b>ssd@ssd:~/Kernel_User_comm$ make --version</b><br><font color="#741b47">GNU Make 4.1<br>Built for x86_64-pc-linux-gnu<br>Copyright (C) 1988-2014 Free Software Foundation, Inc.<br>License GPLv3+: GNU GPL version 3 or later &lt;<a href="http://gnu.org/licenses/gpl.html" target="_blank">http://gnu.org/licenses/gpl.html</a>&gt;<br>This is free software: you are free to change and redistribute it.<br>There is NO WARRANTY, to the extent permitted by law.</font><br></div><div>-------------------------------------------------------</div><div><b>ssd@ssd:~/Kernel_User_comm$ uname -r</b><br><font color="#741b47">5.2.0-rc6</font><br></div><div>--------------------------------------------------------</div><div>Can you please help me: what&#39;s the problem/mistake I am doing?</div><div>Thank you very much.</div><div><br></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><b style="color:rgb(39,78,19)">Best Regards,</b></div><div><b style="color:rgb(39,78,19)"><br></b></div><div><b style="color:rgb(39,78,19)"><br></b></div><div dir="ltr"><b style="color:rgb(39,78,19)">Mr. Irfan Ullah</b><br></div><div dir="ltr"><font color="#666666">PhD Candidate<br></font><div><font color="#666666">Data and Knowledge Engineering(DKE) Lab</font></div><div><font color="#666666">Department of Computer Science and Engineering</font></div><div><font color="#666666">Kyung Hee University, South Korea.</font></div><div><img src="http://teedayusa.com/media/wysiwyg/telephone_icon.gif" style="font-family:arial,sans-serif;font-size:12.8px"><span style="font-family:arial,sans-serif;font-size:12.8px"> </span><span style="font-family:arial,sans-serif;font-size:12.8px"><font color="#000000"><a href="tel:+82%2010-3877-8867" value="+821038778867" style="color:rgb(17,85,204)" target="_blank">+82-010-591-51651</a></font></span></div><div><div style="font-family:arial,sans-serif;font-size:12.8px"><img src="http://www.letsplaydodgeball.com/ndo/templates/dj-sport01/images/system/emailButton.png" style="font-size:12.8px"><span style="font-size:12.8px"><font color="#000000">  </font></span><span style="font-size:12.8px"><font color="#000000"><a href="mailto:sahibzada.iu@gmail.com" style="color:rgb(17,85,204)" target="_blank">sahibzada.iu@gmail.com</a></font></span></div><div><font face="arial, sans-serif"><span style="font-size:12.8px"><img src="https://docs.google.com/uc?export=download&amp;id=0B1-dY3m3XHQnOFBOM0NSODNoUUU&amp;revid=0B1-dY3m3XHQnUmp1c0ZWTGovR2pYbGZCenlOU29DY3ByQU5RPQ" style="font-size:12.8px"></span></font><span style="font-family:arial,sans-serif;font-size:12.8px"> </span><font face="arial, sans-serif"><span style="font-size:12.8px">sahibzada_irfanullah</span></font></div></div></div></div></div></div>

[-- Attachment #2: Kernel_User_comm.zip --]
[-- Type: application/zip, Size: 4284 bytes --]

[-- Attachment #3: Type: text/plain, Size: 170 bytes --]

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Kernel Module with multiple source files not initializing
  2019-10-25  9:14 Kernel Module with multiple source files not initializing Irfan Ullah (울라 이르판)
@ 2019-10-25 16:15 ` Abu Rasheda
  2019-10-27  7:11   ` Irfan Ullah (울라 이르판)
  2019-10-27  8:43 ` Bernd Petrovitsch
  2019-11-05 16:52 ` Aruna Hewapathirane
  2 siblings, 1 reply; 9+ messages in thread
From: Abu Rasheda @ 2019-10-25 16:15 UTC (permalink / raw)
  To: Irfan Ullah (울라 이르판); +Cc: Linux Kernel List

[-- Attachment #1.1: Type: text/plain, Size: 1247 bytes --]

On Fri, Oct 25, 2019 at 2:16 AM Irfan Ullah (울라 이르판) <irfan@dke.khu.ac.kr>
wrote:

> Dear All,
> I have developed a kernel module consists of one source file that sends
> and receives  message to the user space.  I have spitted the source code in
> two files, and now I  am trying to develop kernel module from these source
> files. After compiling and linking without any problems, I insmod the
> module but I didn’t see any of the printk() I wrote, in fact, the module
> can be inserted and removed, but it does nothing. Code is in the attached
> file zipped file.
> I tried many things , e.g.,  link <https://paguilar.org/?p=7>1, link2
> <https://www.linuxquestions.org/questions/linux-kernel-70/kernel-module-with-multiple-source-files-not-initializing-886190/>,
> and link3
> <https://android.googlesource.com/kernel/msm/+/android-msm-dory-3.10-kitkat-wear/Documentation/kbuild/modules.txt> etc.
> but nothings worked out.
> I also used *nm* to inspect the module, but, as expected, there was no
> signs of "__init and __exit" functions can in the output.
>

I assume you have verified that your module is loaded by something like

lsmod | grep your_module_name

and log level allows KERN_ALERT printing.

[-- Attachment #1.2: Type: text/html, Size: 1686 bytes --]

<div dir="ltr"><div dir="ltr">On Fri, Oct 25, 2019 at 2:16 AM Irfan Ullah (울라 이르판) &lt;<a href="mailto:irfan@dke.khu.ac.kr">irfan@dke.khu.ac.kr</a>&gt; wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Dear All,<div>I have developed a kernel module consists of one source file that sends and receives  message to the user space.  I have spitted the source code in two files, and now I  am trying to develop kernel module from these source files. After compiling and linking without any problems, I insmod the module but I didn’t see any of the printk() I wrote, in fact, the module can be inserted and removed, but it does nothing. Code is in the attached file zipped file.</div><div>I tried many things , e.g.,  <a href="https://paguilar.org/?p=7" target="_blank">link</a>1, <a href="https://www.linuxquestions.org/questions/linux-kernel-70/kernel-module-with-multiple-source-files-not-initializing-886190/" target="_blank">link2</a>, and <a href="https://android.googlesource.com/kernel/msm/+/android-msm-dory-3.10-kitkat-wear/Documentation/kbuild/modules.txt" target="_blank">link3</a> etc.  but nothings worked out. </div><div>I also used <i>nm</i> to inspect the module, but, as expected, there was no signs of &quot;__init and __exit&quot; functions can in the output. </div></div></blockquote><div><br></div><div>I assume you have verified that your module is loaded by something like</div><div><br></div><div>lsmod | grep your_module_name</div><div><br></div><div>and log level allows KERN_ALERT printing.</div></div></div>

[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Kernel Module with multiple source files not initializing
  2019-10-25 16:15 ` Abu Rasheda
@ 2019-10-27  7:11   ` Irfan Ullah (울라 이르판)
  0 siblings, 0 replies; 9+ messages in thread
From: Irfan Ullah (울라 이르판) @ 2019-10-27  7:11 UTC (permalink / raw)
  To: Abu Rasheda; +Cc: Linux Kernel List

[-- Attachment #1.1: Type: text/plain, Size: 2015 bytes --]

Thanks you.
Yes, I have tested it. " smod | grep your_module_name" command shows that
the module is loaded but the "dmesg" shows nothing.
Following is the output of the commands.
*ssd@ssd:~/Desktop/Kernel_User_comm$ lsmod | grep netlink_kernel_module*
netlink_kernel_module    16384  0

*ssd@ssd:~/Desktop/Kernel_User_comm$
dmesgssd@ssd:~/Desktop/Kernel_User_comm$ *

On Sat, Oct 26, 2019 at 1:16 AM Abu Rasheda <rcpilot2010@gmail.com> wrote:

> On Fri, Oct 25, 2019 at 2:16 AM Irfan Ullah (울라 이르판) <irfan@dke.khu.ac.kr>
> wrote:
>
>> Dear All,
>> I have developed a kernel module consists of one source file that sends
>> and receives  message to the user space.  I have spitted the source code in
>> two files, and now I  am trying to develop kernel module from these source
>> files. After compiling and linking without any problems, I insmod the
>> module but I didn’t see any of the printk() I wrote, in fact, the module
>> can be inserted and removed, but it does nothing. Code is in the attached
>> file zipped file.
>> I tried many things , e.g.,  link <https://paguilar.org/?p=7>1, link2
>> <https://www.linuxquestions.org/questions/linux-kernel-70/kernel-module-with-multiple-source-files-not-initializing-886190/>,
>> and link3
>> <https://android.googlesource.com/kernel/msm/+/android-msm-dory-3.10-kitkat-wear/Documentation/kbuild/modules.txt> etc.
>> but nothings worked out.
>> I also used *nm* to inspect the module, but, as expected, there was no
>> signs of "__init and __exit" functions can in the output.
>>
>
> I assume you have verified that your module is loaded by something like
>
> lsmod | grep your_module_name
>
> and log level allows KERN_ALERT printing.
>


-- 
*Best Regards,*


*Mr. Irfan Ullah*
PhD Candidate
Data and Knowledge Engineering(DKE) Lab
Department of Computer Science and Engineering
Kyung Hee University, South Korea.
 +82-010-591-51651 <+82%2010-3877-8867>
  sahibzada.iu@gmail.com
 sahibzada_irfanullah

[-- Attachment #1.2: Type: text/html, Size: 4509 bytes --]

<div dir="ltr">Thanks you. <div>Yes, I have tested it. &quot;

smod | grep your_module_name&quot; command shows that the module is loaded but the &quot;dmesg&quot; shows nothing. <div>Following is the output of the commands.<div><b>ssd@ssd:~/Desktop/Kernel_User_comm$ lsmod | grep netlink_kernel_module</b><br></div><div><font color="#741b47">netlink_kernel_module    16384  0</font><br></div><div><b>ssd@ssd:~/Desktop/Kernel_User_comm$ dmesg<br>ssd@ssd:~/Desktop/Kernel_User_comm$ </b><br></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Oct 26, 2019 at 1:16 AM Abu Rasheda &lt;<a href="mailto:rcpilot2010@gmail.com">rcpilot2010@gmail.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr">On Fri, Oct 25, 2019 at 2:16 AM Irfan Ullah (울라 이르판) &lt;<a href="mailto:irfan@dke.khu.ac.kr" target="_blank">irfan@dke.khu.ac.kr</a>&gt; wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Dear All,<div>I have developed a kernel module consists of one source file that sends and receives  message to the user space.  I have spitted the source code in two files, and now I  am trying to develop kernel module from these source files. After compiling and linking without any problems, I insmod the module but I didn’t see any of the printk() I wrote, in fact, the module can be inserted and removed, but it does nothing. Code is in the attached file zipped file.</div><div>I tried many things , e.g.,  <a href="https://paguilar.org/?p=7" target="_blank">link</a>1, <a href="https://www.linuxquestions.org/questions/linux-kernel-70/kernel-module-with-multiple-source-files-not-initializing-886190/" target="_blank">link2</a>, and <a href="https://android.googlesource.com/kernel/msm/+/android-msm-dory-3.10-kitkat-wear/Documentation/kbuild/modules.txt" target="_blank">link3</a> etc.  but nothings worked out. </div><div>I also used <i>nm</i> to inspect the module, but, as expected, there was no signs of &quot;__init and __exit&quot; functions can in the output. </div></div></blockquote><div><br></div><div>I assume you have verified that your module is loaded by something like</div><div><br></div><div>lsmod | grep your_module_name</div><div><br></div><div>and log level allows KERN_ALERT printing.</div></div></div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><b style="color:rgb(39,78,19)">Best Regards,</b></div><div><b style="color:rgb(39,78,19)"><br></b></div><div><b style="color:rgb(39,78,19)"><br></b></div><div dir="ltr"><b style="color:rgb(39,78,19)">Mr. Irfan Ullah</b><br></div><div dir="ltr"><font color="#666666">PhD Candidate<br></font><div><font color="#666666">Data and Knowledge Engineering(DKE) Lab</font></div><div><font color="#666666">Department of Computer Science and Engineering</font></div><div><font color="#666666">Kyung Hee University, South Korea.</font></div><div><img src="http://teedayusa.com/media/wysiwyg/telephone_icon.gif" style="font-family: arial, sans-serif; font-size: 12.8px;"><span style="font-family:arial,sans-serif;font-size:12.8px"> </span><span style="font-family:arial,sans-serif;font-size:12.8px"><font color="#000000"><a href="tel:+82%2010-3877-8867" value="+821038778867" style="color:rgb(17,85,204)" target="_blank">+82-010-591-51651</a></font></span></div><div><div style="font-family:arial,sans-serif;font-size:12.8px"><img src="http://www.letsplaydodgeball.com/ndo/templates/dj-sport01/images/system/emailButton.png" style="font-size: 12.8px;"><span style="font-size:12.8px"><font color="#000000">  </font></span><span style="font-size:12.8px"><font color="#000000"><a href="mailto:sahibzada.iu@gmail.com" style="color:rgb(17,85,204)" target="_blank">sahibzada.iu@gmail.com</a></font></span></div><div><font face="arial, sans-serif"><span style="font-size:12.8px"><img src="https://docs.google.com/uc?export=download&amp;id=0B1-dY3m3XHQnOFBOM0NSODNoUUU&amp;revid=0B1-dY3m3XHQnUmp1c0ZWTGovR2pYbGZCenlOU29DY3ByQU5RPQ" style="font-size: 12.8px;"></span></font><span style="font-family:arial,sans-serif;font-size:12.8px"> </span><font face="arial, sans-serif"><span style="font-size:12.8px">sahibzada_irfanullah</span></font></div></div></div></div></div>

[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Kernel Module with multiple source files not initializing
  2019-10-25  9:14 Kernel Module with multiple source files not initializing Irfan Ullah (울라 이르판)
  2019-10-25 16:15 ` Abu Rasheda
@ 2019-10-27  8:43 ` Bernd Petrovitsch
  2019-10-28  9:43   ` Irfan Ullah (울라 이르판)
  2019-11-05 16:52 ` Aruna Hewapathirane
  2 siblings, 1 reply; 9+ messages in thread
From: Bernd Petrovitsch @ 2019-10-27  8:43 UTC (permalink / raw)
  To: Irfan Ullah (울라 이르판), kernelnewbies

Hi all!

On 25/10/2019 11:14, Irfan Ullah (울라 이르판) wrote:
> Dear All,
> I have developed a kernel module consists of one source file that sends
> and receives  message to the user space.  I have spitted the source code
> in two files, and now I  am trying to develop kernel module from these
> source files. After compiling and linking without any problems, I insmod
> the module but I didn’t see any of the printk() I wrote, in fact, the
> module can be inserted and removed, but it does nothing. Code is in the
> attached file zipped file.
> I tried many things , e.g.,  link <https://paguilar.org/?p=7>1, link2
> <https://www.linuxquestions.org/questions/linux-kernel-70/kernel-module-with-multiple-source-files-not-initializing-886190/>;,
> and link3
> <https://android.googlesource.com/kernel/msm/+/android-msm-dory-3.10-kitkat-wear/Documentation/kbuild/modules.txt> etc. 
> but nothings worked out. 
> I also used /nm/ to inspect the module, but, as expected, there was no> signs of "__init and __exit" functions can in the output.

To be exact, you are looking for the hello_init function.
Since "nm" doesn't show it, it's either not there or
"static".

[ for the nm-output see in the OPs mail ]
> Can you please help me: what's the problem/mistake I am doing?
> Thank you very much.

Get rid of the "static" for the hello_init and hello_exit function.

MfG,
	Bernd
-- 
Bernd Petrovitsch                  Email : bernd@petrovitsch.priv.at
                     LUGA : http://www.luga.at


_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Kernel Module with multiple source files not initializing
  2019-10-27  8:43 ` Bernd Petrovitsch
@ 2019-10-28  9:43   ` Irfan Ullah (울라 이르판)
  2019-10-28 10:04     ` Bernd Petrovitsch
  0 siblings, 1 reply; 9+ messages in thread
From: Irfan Ullah (울라 이르판) @ 2019-10-28  9:43 UTC (permalink / raw)
  To: Bernd Petrovitsch; +Cc: Linux Kernel List

[-- Attachment #1.1: Type: text/plain, Size: 2163 bytes --]

Thanks for the help. I have removed the "static" from the hello_init,
hello_exti but nothing worked. I am not sure, but I think the problem is
with the make file.


On Sun, Oct 27, 2019 at 5:44 PM Bernd Petrovitsch <bernd@petrovitsch.priv.at>
wrote:

> Hi all!
>
> On 25/10/2019 11:14, Irfan Ullah (울라 이르판) wrote:
> > Dear All,
> > I have developed a kernel module consists of one source file that sends
> > and receives  message to the user space.  I have spitted the source code
> > in two files, and now I  am trying to develop kernel module from these
> > source files. After compiling and linking without any problems, I insmod
> > the module but I didn’t see any of the printk() I wrote, in fact, the
> > module can be inserted and removed, but it does nothing. Code is in the
> > attached file zipped file.
> > I tried many things , e.g.,  link <https://paguilar.org/?p=7>1, link2
> > <
> https://www.linuxquestions.org/questions/linux-kernel-70/kernel-module-with-multiple-source-files-not-initializing-886190/
> >;,
> > and link3
> > <
> https://android.googlesource.com/kernel/msm/+/android-msm-dory-3.10-kitkat-wear/Documentation/kbuild/modules.txt> etc.
>
> > but nothings worked out.
> > I also used /nm/ to inspect the module, but, as expected, there was no>
> signs of "__init and __exit" functions can in the output.
>
> To be exact, you are looking for the hello_init function.
> Since "nm" doesn't show it, it's either not there or
> "static".
>
> [ for the nm-output see in the OPs mail ]
> > Can you please help me: what's the problem/mistake I am doing?
> > Thank you very much.
>
> Get rid of the "static" for the hello_init and hello_exit function.
>
> MfG,
>         Bernd
> --
> Bernd Petrovitsch                  Email : bernd@petrovitsch.priv.at
>                      LUGA : http://www.luga.at
>
>

-- 
*Best Regards,*


*Mr. Irfan Ullah*
PhD Candidate
Data and Knowledge Engineering(DKE) Lab
Department of Computer Science and Engineering
Kyung Hee University, South Korea.
 +82-010-591-51651 <+82%2010-3877-8867>
  sahibzada.iu@gmail.com
 sahibzada_irfanullah

[-- Attachment #1.2: Type: text/html, Size: 4873 bytes --]

<div dir="ltr">Thanks for the help. I have removed the &quot;static&quot; from the hello_init, hello_exti but nothing worked. I am not sure, but I think the problem is with the make file.<div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Oct 27, 2019 at 5:44 PM Bernd Petrovitsch &lt;<a href="mailto:bernd@petrovitsch.priv.at">bernd@petrovitsch.priv.at</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi all!<br>
<br>
On 25/10/2019 11:14, Irfan Ullah (울라 이르판) wrote:<br>
&gt; Dear All,<br>
&gt; I have developed a kernel module consists of one source file that sends<br>
&gt; and receives  message to the user space.  I have spitted the source code<br>
&gt; in two files, and now I  am trying to develop kernel module from these<br>
&gt; source files. After compiling and linking without any problems, I insmod<br>
&gt; the module but I didn’t see any of the printk() I wrote, in fact, the<br>
&gt; module can be inserted and removed, but it does nothing. Code is in the<br>
&gt; attached file zipped file.<br>
&gt; I tried many things , e.g.,  link &lt;<a href="https://paguilar.org/?p=7" rel="noreferrer" target="_blank">https://paguilar.org/?p=7</a>&gt;1, link2<br>
&gt; &lt;<a href="https://www.linuxquestions.org/questions/linux-kernel-70/kernel-module-with-multiple-source-files-not-initializing-886190/" rel="noreferrer" target="_blank">https://www.linuxquestions.org/questions/linux-kernel-70/kernel-module-with-multiple-source-files-not-initializing-886190/</a>&gt;;,<br>
&gt; and link3<br>
&gt; &lt;<a href="https://android.googlesource.com/kernel/msm/+/android-msm-dory-3.10-kitkat-wear/Documentation/kbuild/modules.txt" rel="noreferrer" target="_blank">https://android.googlesource.com/kernel/msm/+/android-msm-dory-3.10-kitkat-wear/Documentation/kbuild/modules.txt</a>&gt; etc. <br>
&gt; but nothings worked out. <br>
&gt; I also used /nm/ to inspect the module, but, as expected, there was no&gt; signs of &quot;__init and __exit&quot; functions can in the output.<br>
<br>
To be exact, you are looking for the hello_init function.<br>
Since &quot;nm&quot; doesn&#39;t show it, it&#39;s either not there or<br>
&quot;static&quot;.<br>
<br>
[ for the nm-output see in the OPs mail ]<br>
&gt; Can you please help me: what&#39;s the problem/mistake I am doing?<br>
&gt; Thank you very much.<br>
<br>
Get rid of the &quot;static&quot; for the hello_init and hello_exit function.<br>
<br>
MfG,<br>
        Bernd<br>
-- <br>
Bernd Petrovitsch                  Email : <a href="mailto:bernd@petrovitsch.priv.at" target="_blank">bernd@petrovitsch.priv.at</a><br>
                     LUGA : <a href="http://www.luga.at" rel="noreferrer" target="_blank">http://www.luga.at</a><br>
<br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><b style="color:rgb(39,78,19)">Best Regards,</b></div><div><b style="color:rgb(39,78,19)"><br></b></div><div><b style="color:rgb(39,78,19)"><br></b></div><div dir="ltr"><b style="color:rgb(39,78,19)">Mr. Irfan Ullah</b><br></div><div dir="ltr"><font color="#666666">PhD Candidate<br></font><div><font color="#666666">Data and Knowledge Engineering(DKE) Lab</font></div><div><font color="#666666">Department of Computer Science and Engineering</font></div><div><font color="#666666">Kyung Hee University, South Korea.</font></div><div><img src="http://teedayusa.com/media/wysiwyg/telephone_icon.gif" style="font-family: arial, sans-serif; font-size: 12.8px;"><span style="font-family:arial,sans-serif;font-size:12.8px"> </span><span style="font-family:arial,sans-serif;font-size:12.8px"><font color="#000000"><a href="tel:+82%2010-3877-8867" value="+821038778867" style="color:rgb(17,85,204)" target="_blank">+82-010-591-51651</a></font></span></div><div><div style="font-family:arial,sans-serif;font-size:12.8px"><img src="http://www.letsplaydodgeball.com/ndo/templates/dj-sport01/images/system/emailButton.png" style="font-size: 12.8px;"><span style="font-size:12.8px"><font color="#000000">  </font></span><span style="font-size:12.8px"><font color="#000000"><a href="mailto:sahibzada.iu@gmail.com" style="color:rgb(17,85,204)" target="_blank">sahibzada.iu@gmail.com</a></font></span></div><div><font face="arial, sans-serif"><span style="font-size:12.8px"><img src="https://docs.google.com/uc?export=download&amp;id=0B1-dY3m3XHQnOFBOM0NSODNoUUU&amp;revid=0B1-dY3m3XHQnUmp1c0ZWTGovR2pYbGZCenlOU29DY3ByQU5RPQ" style="font-size: 12.8px;"></span></font><span style="font-family:arial,sans-serif;font-size:12.8px"> </span><font face="arial, sans-serif"><span style="font-size:12.8px">sahibzada_irfanullah</span></font></div></div></div></div></div>

[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Kernel Module with multiple source files not initializing
  2019-10-28  9:43   ` Irfan Ullah (울라 이르판)
@ 2019-10-28 10:04     ` Bernd Petrovitsch
  2019-10-29  8:30       ` Irfan Ullah (울라 이르판)
  0 siblings, 1 reply; 9+ messages in thread
From: Bernd Petrovitsch @ 2019-10-28 10:04 UTC (permalink / raw)
  To: Irfan Ullah (울라 이르판); +Cc: Linux Kernel List

[-- Attachment #1: Type: text/plain, Size: 635 bytes --]

On 28/10/2019 10:43, Irfan Ullah (울라 이르판) wrote:
> Thanks for the help. I have removed the "static" from the hello_init,
> hello_exti but nothing worked. I am not sure, but I think the problem is
> with the make file.

OK, when I add "static" to my driver, it works too. Sry for the confusion.

I have also __init with the init function and __exit with the
exit function.

MfG,
	Bernd
-- 
"I dislike type abstraction if it has no real reason. And saving
on typing is not a good reason - if your typing speed is the main
issue when you're coding, you're doing something seriously wrong."
    - Linus Torvalds

[-- Attachment #2: pEpkey.asc --]
[-- Type: application/pgp-keys, Size: 2513 bytes --]

[-- Attachment #3: Type: text/plain, Size: 170 bytes --]

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Kernel Module with multiple source files not initializing
  2019-10-28 10:04     ` Bernd Petrovitsch
@ 2019-10-29  8:30       ` Irfan Ullah (울라 이르판)
  0 siblings, 0 replies; 9+ messages in thread
From: Irfan Ullah (울라 이르판) @ 2019-10-29  8:30 UTC (permalink / raw)
  To: Bernd Petrovitsch; +Cc: Linux Kernel List

[-- Attachment #1.1: Type: text/plain, Size: 1097 bytes --]

my problem still not solved. Thanks for your help.

On Mon, Oct 28, 2019 at 7:04 PM Bernd Petrovitsch <bernd@petrovitsch.priv.at>
wrote:

> On 28/10/2019 10:43, Irfan Ullah (울라 이르판) wrote:
> > Thanks for the help. I have removed the "static" from the hello_init,
> > hello_exti but nothing worked. I am not sure, but I think the problem is
> > with the make file.
>
> OK, when I add "static" to my driver, it works too. Sry for the confusion.
>
> I have also __init with the init function and __exit with the
> exit function.
>
> MfG,
>         Bernd
> --
> "I dislike type abstraction if it has no real reason. And saving
> on typing is not a good reason - if your typing speed is the main
> issue when you're coding, you're doing something seriously wrong."
>     - Linus Torvalds
>


-- 
*Best Regards,*


*Mr. Irfan Ullah*
PhD Candidate
Data and Knowledge Engineering(DKE) Lab
Department of Computer Science and Engineering
Kyung Hee University, South Korea.
 +82-010-591-51651 <+82%2010-3877-8867>
  sahibzada.iu@gmail.com
 sahibzada_irfanullah

[-- Attachment #1.2: Type: text/html, Size: 3133 bytes --]

<div dir="ltr">my problem still not solved. Thanks for your help.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Oct 28, 2019 at 7:04 PM Bernd Petrovitsch &lt;<a href="mailto:bernd@petrovitsch.priv.at">bernd@petrovitsch.priv.at</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 28/10/2019 10:43, Irfan Ullah (울라 이르판) wrote:<br>
&gt; Thanks for the help. I have removed the &quot;static&quot; from the hello_init,<br>
&gt; hello_exti but nothing worked. I am not sure, but I think the problem is<br>
&gt; with the make file.<br>
<br>
OK, when I add &quot;static&quot; to my driver, it works too. Sry for the confusion.<br>
<br>
I have also __init with the init function and __exit with the<br>
exit function.<br>
<br>
MfG,<br>
        Bernd<br>
-- <br>
&quot;I dislike type abstraction if it has no real reason. And saving<br>
on typing is not a good reason - if your typing speed is the main<br>
issue when you&#39;re coding, you&#39;re doing something seriously wrong.&quot;<br>
    - Linus Torvalds<br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><b style="color:rgb(39,78,19)">Best Regards,</b></div><div><b style="color:rgb(39,78,19)"><br></b></div><div><b style="color:rgb(39,78,19)"><br></b></div><div dir="ltr"><b style="color:rgb(39,78,19)">Mr. Irfan Ullah</b><br></div><div dir="ltr"><font color="#666666">PhD Candidate<br></font><div><font color="#666666">Data and Knowledge Engineering(DKE) Lab</font></div><div><font color="#666666">Department of Computer Science and Engineering</font></div><div><font color="#666666">Kyung Hee University, South Korea.</font></div><div><img src="http://teedayusa.com/media/wysiwyg/telephone_icon.gif" style="font-family: arial, sans-serif; font-size: 12.8px;"><span style="font-family:arial,sans-serif;font-size:12.8px"> </span><span style="font-family:arial,sans-serif;font-size:12.8px"><font color="#000000"><a href="tel:+82%2010-3877-8867" value="+821038778867" style="color:rgb(17,85,204)" target="_blank">+82-010-591-51651</a></font></span></div><div><div style="font-family:arial,sans-serif;font-size:12.8px"><img src="http://www.letsplaydodgeball.com/ndo/templates/dj-sport01/images/system/emailButton.png" style="font-size: 12.8px;"><span style="font-size:12.8px"><font color="#000000">  </font></span><span style="font-size:12.8px"><font color="#000000"><a href="mailto:sahibzada.iu@gmail.com" style="color:rgb(17,85,204)" target="_blank">sahibzada.iu@gmail.com</a></font></span></div><div><font face="arial, sans-serif"><span style="font-size:12.8px"><img src="https://docs.google.com/uc?export=download&amp;id=0B1-dY3m3XHQnOFBOM0NSODNoUUU&amp;revid=0B1-dY3m3XHQnUmp1c0ZWTGovR2pYbGZCenlOU29DY3ByQU5RPQ" style="font-size: 12.8px;"></span></font><span style="font-family:arial,sans-serif;font-size:12.8px"> </span><font face="arial, sans-serif"><span style="font-size:12.8px">sahibzada_irfanullah</span></font></div></div></div></div></div>

[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Kernel Module with multiple source files not initializing
  2019-10-25  9:14 Kernel Module with multiple source files not initializing Irfan Ullah (울라 이르판)
  2019-10-25 16:15 ` Abu Rasheda
  2019-10-27  8:43 ` Bernd Petrovitsch
@ 2019-11-05 16:52 ` Aruna Hewapathirane
  2019-11-07  1:50   ` Irfan Ullah (울라 이르판)
  2 siblings, 1 reply; 9+ messages in thread
From: Aruna Hewapathirane @ 2019-11-05 16:52 UTC (permalink / raw)
  To: Irfan Ullah (울라 이르판); +Cc: kernelnewbies

[-- Attachment #1.1: Type: text/plain, Size: 5189 bytes --]

>> On Fri, Oct 25, 2019 at 5:16 AM Irfan Ullah (울라 이르판) <irfan@dke.khu.ac.kr>
wrote:
>> Dear All,
>> I have developed a kernel module consists of one source file that sends
and receives  message to the user space.  I have spitted the source code in
two files, and now I  am trying to develop kernel module from these source
files. After compiling >> and linking without any problems, I insmod the
module but I didn’t see any of the printk() I wrote, in fact, the module
can be inserted and removed, but it does nothing. Code is in the attached
file zipped file.
>> I tried many things , e.g.,  link <https://paguilar.org/?p=7>1, link2
<https://www.linuxquestions.org/questions/linux-kernel-70/kernel-module-with-multiple-source-files-not-initializing-886190/>,
and link3
<https://android.googlesource.com/kernel/msm/+/android-msm-dory-3.10-kitkat-wear/Documentation/kbuild/modules.txt>
etc.
but nothings worked out.
>> I also used *nm* to inspect the module, but, as expected, there was no
signs of "__init and __exit" functions can in the output.

When you take a careful look at make's output we see that
netlink_kernel_module.c
is not being compiled. See below:

aruna@debian:~/Downloads/kmod6$ make
make -C /lib/modules/3.16.0-4-amd64/build M=/home/aruna/Downloads/kmod6
modules
make[1]: Entering directory '/usr/src/linux-headers-3.16.0-4-amd64'
make[1]: Entering directory `/usr/src/linux-headers-3.16.0-4-amd64'
  CC [M]  /home/aruna/Downloads/kmod6/netlink_kernel_space.o
  LD [M]  /home/aruna/Downloads/kmod6/netlink_kernel_module.o
  Building modules, stage 2.
  MODPOST 1 modules
  CC      /home/aruna/Downloads/kmod6/netlink_kernel_module.mod.o
  LD [M]  /home/aruna/Downloads/kmod6/netlink_kernel_module.ko
make[1]: Leaving directory '/usr/src/linux-headers-3.16.0-4-amd64'

This is why nm does not show hello_init or hello_exit.

>> Can you please help me: what's the problem/mistake I am doing?

Change your Makefile so the module name is not the same as the C source
file. Let's say
we want the module to be named aruna.ko ( make up any name different to the
C source file)

obj-m := aruna.o
aruna-objs := netlink_kernel_module.o netlink_kernel_space.o

and now make shows:

make -C /lib/modules/3.16.0-4-amd64/build
M=/home/aruna/kmod6/Kernel_User_comm modules
make[1]: Entering directory '/usr/src/linux-headers-3.16.0-4-amd64'
make[1]: Entering directory `/usr/src/linux-headers-3.16.0-4-amd64'
  CC [M]  /home/aruna/kmod6/Kernel_User_comm/netlink_kernel_module.o  //
<-- THIS TIME IT COMPILES !
  CC [M]  /home/aruna/kmod6/Kernel_User_comm/netlink_kernel_space.o
  LD [M]  /home/aruna/kmod6/Kernel_User_comm/aruna.o
  Building modules, stage 2.
  MODPOST 1 modules
  CC      /home/aruna/kmod6/Kernel_User_comm/aruna.mod.o
  LD [M]  /home/aruna/kmod6/Kernel_User_comm/aruna.ko
make[1]: Leaving directory '/usr/src/linux-headers-3.16.0-4-amd64'

and now nm aruna.ko shows:
aruna@debian:~/kmod6/Kernel_User_comm$ nm aruna.ko
0000000000000020 T cleanup_module
0000000000000080 T create_socket
0000000000000040 T data_update
                 U __fentry__
0000000000000020 t hello_exit               // WE HAVE hello_exit
0000000000000000 t hello_init                // WE HAVE hello_init
0000000000000000 T init_module
0000000000000070 T kernel_space_receiver
0000000000000050 T kernel_space_sender
0000000000000053 r __module_depends
0000000000000004 D pid
                 U printk
0000000000000000 D res
0000000000000000 D __this_module
0000000000000000 r __UNIQUE_ID_author2
0000000000000013 r __UNIQUE_ID_description1
0000000000000047 r __UNIQUE_ID_license0
000000000000005c r __UNIQUE_ID_vermagic0
0000000000000000 r ____versions

To get make to do this smoothly you will have to fix the multiple
definition and
other errors I encountered along the way. And something's in your header
file really should belong in a C file :) heed Valdis's advice.

As a learning experience try this Makefile:
------------------------------------------------------------------------------------------------------
obj-m := aruna.o
aruna-objs := netlink_kernel_module.o netlink_kernel_space.o

SHELL += -x

all:
         make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
------------------------------------------------------------------------------------------------------

One simple way to enhance the output of GNU Make is to redefine SHELL.
SHELL is a GNU Make built-in variable that contains the name of the shell
to use when
GNU Make executes commands.

Reference:
https://www.cmcrossroads.com/article/tracing-rule-execution-gnu-make

Since most shells have a -x option that causes them to print out each
command they
are about to execute modifying SHELL in a Makefile by appendin -x causes
every command
to be printed (usually preceded by +) as the Makefile is run.

Try:
make clean the make and go through the output can be an enlightening
experience.

Ah the joys of building a kernel module that has more than one source file
:-)--

Good luck - Aruna

[-- Attachment #1.2: Type: text/html, Size: 6284 bytes --]

<div dir="ltr"><div dir="ltr" class="gmail_attr">&gt;&gt; On Fri, Oct 25, 2019 at 5:16 AM Irfan Ullah (울라 이르판) &lt;<a href="mailto:irfan@dke.khu.ac.kr">irfan@dke.khu.ac.kr</a>&gt; wrote:</div><div dir="ltr">&gt;&gt; Dear All,<div>&gt;&gt; I have developed a kernel module consists of one source file that sends and receives  message to the user space.  I have spitted the source code in two files, and now I  am trying to develop kernel module from these source files. After compiling &gt;&gt; and linking without any problems, I insmod the module but I didn’t see any of the printk() I wrote, in fact, the module can be inserted and removed, but it does nothing. Code is in the attached file zipped file.</div><div>&gt;&gt; I tried many things , e.g.,  <a href="https://paguilar.org/?p=7" target="_blank">link</a>1, <a href="https://www.linuxquestions.org/questions/linux-kernel-70/kernel-module-with-multiple-source-files-not-initializing-886190/" target="_blank">link2</a>, and <a href="https://android.googlesource.com/kernel/msm/+/android-msm-dory-3.10-kitkat-wear/Documentation/kbuild/modules.txt" target="_blank">link3</a> etc.  but nothings worked out. </div><div>&gt;&gt; I also used <i>nm</i> to inspect the module, but, as expected, there was no signs of &quot;__init and __exit&quot; functions can in the output. <br></div><div><br></div><div>When you take a careful look at make&#39;s output we see that netlink_kernel_module.c <br>is not being compiled. See below:<br></div><div><br>aruna@debian:~/Downloads/kmod6$ make<br>make -C /lib/modules/3.16.0-4-amd64/build M=/home/aruna/Downloads/kmod6 modules<br>make[1]: Entering directory &#39;/usr/src/linux-headers-3.16.0-4-amd64&#39;<br>make[1]: Entering directory `/usr/src/linux-headers-3.16.0-4-amd64&#39;<br>  CC [M]  /home/aruna/Downloads/kmod6/netlink_kernel_space.o <br>  LD [M]  /home/aruna/Downloads/kmod6/netlink_kernel_module.o<br>  Building modules, stage 2.<br>  MODPOST 1 modules<br>  CC      /home/aruna/Downloads/kmod6/netlink_kernel_module.mod.o<br>  LD [M]  /home/aruna/Downloads/kmod6/netlink_kernel_module.ko<br>make[1]: Leaving directory &#39;/usr/src/linux-headers-3.16.0-4-amd64&#39;</div><div><br></div><div>This is why nm does not show hello_init or hello_exit.</div><br><div>&gt;&gt; Can you please help me: what&#39;s the problem/mistake I am doing?</div><div><br></div><div>Change your Makefile so the module name is not the same as the C source file. Let&#39;s say</div><div>we want the module to be named aruna.ko ( make up any name different to the C source file)<br></div><div><br>obj-m := aruna.o<br>aruna-objs := netlink_kernel_module.o netlink_kernel_space.o <br></div><div><br></div><div>and now make shows:<br><br></div><div>make -C /lib/modules/3.16.0-4-amd64/build M=/home/aruna/kmod6/Kernel_User_comm modules<br>make[1]: Entering directory &#39;/usr/src/linux-headers-3.16.0-4-amd64&#39;<br>make[1]: Entering directory `/usr/src/linux-headers-3.16.0-4-amd64&#39;<br>  CC [M]  /home/aruna/kmod6/Kernel_User_comm/netlink_kernel_module.o  //   &lt;-- THIS TIME IT COMPILES !<br>  CC [M]  /home/aruna/kmod6/Kernel_User_comm/netlink_kernel_space.o<br>  LD [M]  /home/aruna/kmod6/Kernel_User_comm/aruna.o<br>  Building modules, stage 2.<br>  MODPOST 1 modules<br>  CC      /home/aruna/kmod6/Kernel_User_comm/aruna.mod.o<br>  LD [M]  /home/aruna/kmod6/Kernel_User_comm/aruna.ko<br>make[1]: Leaving directory &#39;/usr/src/linux-headers-3.16.0-4-amd64&#39;<br></div><div><br></div><div>and now nm aruna.ko shows:</div>aruna@debian:~/kmod6/Kernel_User_comm$ nm aruna.ko<br>0000000000000020 T cleanup_module<br>0000000000000080 T create_socket<br>0000000000000040 T data_update<br>                 U __fentry__<br>0000000000000020 t hello_exit               // WE HAVE hello_exit<br>0000000000000000 t hello_init                // WE HAVE hello_init<br>0000000000000000 T init_module<br>0000000000000070 T kernel_space_receiver<br>0000000000000050 T kernel_space_sender<br>0000000000000053 r __module_depends<br>0000000000000004 D pid<br>                 U printk<br>0000000000000000 D res<br>0000000000000000 D __this_module<br>0000000000000000 r __UNIQUE_ID_author2<br>0000000000000013 r __UNIQUE_ID_description1<br>0000000000000047 r __UNIQUE_ID_license0<br>000000000000005c r __UNIQUE_ID_vermagic0<br>0000000000000000 r ____versions<br><div><br></div><div>To get make to do this smoothly you will have to fix the multiple definition and</div><div>other errors I encountered along the way. And something&#39;s in your header<br></div><div>file really should belong in a C file :) heed Valdis&#39;s advice.<br></div><br><div>As a learning experience try this Makefile:</div><div>------------------------------------------------------------------------------------------------------<br>obj-m := aruna.o<br>aruna-objs := netlink_kernel_module.o netlink_kernel_space.o <br><br>SHELL += -x<br><br>all:<br>        	make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules<br>clean:<br>        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean<br></div><div>------------------------------------------------------------------------------------------------------</div><div><br></div><div>One simple way to enhance the output of GNU Make is to redefine SHELL. 
<br>SHELL is a GNU Make built-in variable that contains the name of the 
shell to use when <br></div><div>GNU Make executes commands.<br></div><div><br></div><div>Reference: <a href="https://www.cmcrossroads.com/article/tracing-rule-execution-gnu-make">https://www.cmcrossroads.com/article/tracing-rule-execution-gnu-make</a><br><br></div><div>Since most shells 
have a -x option that causes them to print out each command they <br></div><div>are 
about to execute modifying SHELL in a Makefile by appendin -x causes 
every command <br></div><div>to be printed (usually preceded by +) as the Makefile is 
run.</div><div><br></div><div>Try:</div><div>make clean the make and go through the output can be an enlightening experience.<br><br></div><div>Ah the joys of building a kernel module that has more than one source file :-)-- <br></div></div><div dir="ltr"><br></div><div>Good luck - Aruna</div><br></div>

[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Kernel Module with multiple source files not initializing
  2019-11-05 16:52 ` Aruna Hewapathirane
@ 2019-11-07  1:50   ` Irfan Ullah (울라 이르판)
  0 siblings, 0 replies; 9+ messages in thread
From: Irfan Ullah (울라 이르판) @ 2019-11-07  1:50 UTC (permalink / raw)
  To: Aruna Hewapathirane; +Cc: kernelnewbies

[-- Attachment #1.1: Type: text/plain, Size: 5840 bytes --]

Thanks a lot. it is working now.

On Wed, Nov 6, 2019 at 1:52 AM Aruna Hewapathirane <
aruna.hewapathirane@gmail.com> wrote:

> >> On Fri, Oct 25, 2019 at 5:16 AM Irfan Ullah (울라 이르판) <
> irfan@dke.khu.ac.kr> wrote:
> >> Dear All,
> >> I have developed a kernel module consists of one source file that sends
> and receives  message to the user space.  I have spitted the source code in
> two files, and now I  am trying to develop kernel module from these source
> files. After compiling >> and linking without any problems, I insmod the
> module but I didn’t see any of the printk() I wrote, in fact, the module
> can be inserted and removed, but it does nothing. Code is in the attached
> file zipped file.
> >> I tried many things , e.g.,  link <https://paguilar.org/?p=7>1, link2
> <https://www.linuxquestions.org/questions/linux-kernel-70/kernel-module-with-multiple-source-files-not-initializing-886190/>,
> and link3
> <https://android.googlesource.com/kernel/msm/+/android-msm-dory-3.10-kitkat-wear/Documentation/kbuild/modules.txt> etc.
> but nothings worked out.
> >> I also used *nm* to inspect the module, but, as expected, there was no
> signs of "__init and __exit" functions can in the output.
>
> When you take a careful look at make's output we see that
> netlink_kernel_module.c
> is not being compiled. See below:
>
> aruna@debian:~/Downloads/kmod6$ make
> make -C /lib/modules/3.16.0-4-amd64/build M=/home/aruna/Downloads/kmod6
> modules
> make[1]: Entering directory '/usr/src/linux-headers-3.16.0-4-amd64'
> make[1]: Entering directory `/usr/src/linux-headers-3.16.0-4-amd64'
>   CC [M]  /home/aruna/Downloads/kmod6/netlink_kernel_space.o
>   LD [M]  /home/aruna/Downloads/kmod6/netlink_kernel_module.o
>   Building modules, stage 2.
>   MODPOST 1 modules
>   CC      /home/aruna/Downloads/kmod6/netlink_kernel_module.mod.o
>   LD [M]  /home/aruna/Downloads/kmod6/netlink_kernel_module.ko
> make[1]: Leaving directory '/usr/src/linux-headers-3.16.0-4-amd64'
>
> This is why nm does not show hello_init or hello_exit.
>
> >> Can you please help me: what's the problem/mistake I am doing?
>
> Change your Makefile so the module name is not the same as the C source
> file. Let's say
> we want the module to be named aruna.ko ( make up any name different to
> the C source file)
>
> obj-m := aruna.o
> aruna-objs := netlink_kernel_module.o netlink_kernel_space.o
>
> and now make shows:
>
> make -C /lib/modules/3.16.0-4-amd64/build
> M=/home/aruna/kmod6/Kernel_User_comm modules
> make[1]: Entering directory '/usr/src/linux-headers-3.16.0-4-amd64'
> make[1]: Entering directory `/usr/src/linux-headers-3.16.0-4-amd64'
>   CC [M]  /home/aruna/kmod6/Kernel_User_comm/netlink_kernel_module.o  //
> <-- THIS TIME IT COMPILES !
>   CC [M]  /home/aruna/kmod6/Kernel_User_comm/netlink_kernel_space.o
>   LD [M]  /home/aruna/kmod6/Kernel_User_comm/aruna.o
>   Building modules, stage 2.
>   MODPOST 1 modules
>   CC      /home/aruna/kmod6/Kernel_User_comm/aruna.mod.o
>   LD [M]  /home/aruna/kmod6/Kernel_User_comm/aruna.ko
> make[1]: Leaving directory '/usr/src/linux-headers-3.16.0-4-amd64'
>
> and now nm aruna.ko shows:
> aruna@debian:~/kmod6/Kernel_User_comm$ nm aruna.ko
> 0000000000000020 T cleanup_module
> 0000000000000080 T create_socket
> 0000000000000040 T data_update
>                  U __fentry__
> 0000000000000020 t hello_exit               // WE HAVE hello_exit
> 0000000000000000 t hello_init                // WE HAVE hello_init
> 0000000000000000 T init_module
> 0000000000000070 T kernel_space_receiver
> 0000000000000050 T kernel_space_sender
> 0000000000000053 r __module_depends
> 0000000000000004 D pid
>                  U printk
> 0000000000000000 D res
> 0000000000000000 D __this_module
> 0000000000000000 r __UNIQUE_ID_author2
> 0000000000000013 r __UNIQUE_ID_description1
> 0000000000000047 r __UNIQUE_ID_license0
> 000000000000005c r __UNIQUE_ID_vermagic0
> 0000000000000000 r ____versions
>
> To get make to do this smoothly you will have to fix the multiple
> definition and
> other errors I encountered along the way. And something's in your header
> file really should belong in a C file :) heed Valdis's advice.
>
> As a learning experience try this Makefile:
>
> ------------------------------------------------------------------------------------------------------
> obj-m := aruna.o
> aruna-objs := netlink_kernel_module.o netlink_kernel_space.o
>
> SHELL += -x
>
> all:
>          make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
> clean:
>         make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
>
> ------------------------------------------------------------------------------------------------------
>
> One simple way to enhance the output of GNU Make is to redefine SHELL.
> SHELL is a GNU Make built-in variable that contains the name of the shell
> to use when
> GNU Make executes commands.
>
> Reference:
> https://www.cmcrossroads.com/article/tracing-rule-execution-gnu-make
>
> Since most shells have a -x option that causes them to print out each
> command they
> are about to execute modifying SHELL in a Makefile by appendin -x causes
> every command
> to be printed (usually preceded by +) as the Makefile is run.
>
> Try:
> make clean the make and go through the output can be an enlightening
> experience.
>
> Ah the joys of building a kernel module that has more than one source file
> :-)--
>
> Good luck - Aruna
>
>

-- 
*Best Regards,*


*Mr. Irfan Ullah*
PhD Candidate
Data and Knowledge Engineering(DKE) Lab
Department of Computer Science and Engineering
Kyung Hee University, South Korea.
 +82-010-591-51651 <+82%2010-3877-8867>
  sahibzada.iu@gmail.com
 sahibzada_irfanullah

[-- Attachment #1.2: Type: text/html, Size: 8681 bytes --]

<div dir="ltr">Thanks a lot. it is working now.<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Nov 6, 2019 at 1:52 AM Aruna Hewapathirane &lt;<a href="mailto:aruna.hewapathirane@gmail.com">aruna.hewapathirane@gmail.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr" class="gmail_attr">&gt;&gt; On Fri, Oct 25, 2019 at 5:16 AM Irfan Ullah (울라 이르판) &lt;<a href="mailto:irfan@dke.khu.ac.kr" target="_blank">irfan@dke.khu.ac.kr</a>&gt; wrote:</div><div dir="ltr">&gt;&gt; Dear All,<div>&gt;&gt; I have developed a kernel module consists of one source file that sends and receives  message to the user space.  I have spitted the source code in two files, and now I  am trying to develop kernel module from these source files. After compiling &gt;&gt; and linking without any problems, I insmod the module but I didn’t see any of the printk() I wrote, in fact, the module can be inserted and removed, but it does nothing. Code is in the attached file zipped file.</div><div>&gt;&gt; I tried many things , e.g.,  <a href="https://paguilar.org/?p=7" target="_blank">link</a>1, <a href="https://www.linuxquestions.org/questions/linux-kernel-70/kernel-module-with-multiple-source-files-not-initializing-886190/" target="_blank">link2</a>, and <a href="https://android.googlesource.com/kernel/msm/+/android-msm-dory-3.10-kitkat-wear/Documentation/kbuild/modules.txt" target="_blank">link3</a> etc.  but nothings worked out. </div><div>&gt;&gt; I also used <i>nm</i> to inspect the module, but, as expected, there was no signs of &quot;__init and __exit&quot; functions can in the output. <br></div><div><br></div><div>When you take a careful look at make&#39;s output we see that netlink_kernel_module.c <br>is not being compiled. See below:<br></div><div><br>aruna@debian:~/Downloads/kmod6$ make<br>make -C /lib/modules/3.16.0-4-amd64/build M=/home/aruna/Downloads/kmod6 modules<br>make[1]: Entering directory &#39;/usr/src/linux-headers-3.16.0-4-amd64&#39;<br>make[1]: Entering directory `/usr/src/linux-headers-3.16.0-4-amd64&#39;<br>  CC [M]  /home/aruna/Downloads/kmod6/netlink_kernel_space.o <br>  LD [M]  /home/aruna/Downloads/kmod6/netlink_kernel_module.o<br>  Building modules, stage 2.<br>  MODPOST 1 modules<br>  CC      /home/aruna/Downloads/kmod6/netlink_kernel_module.mod.o<br>  LD [M]  /home/aruna/Downloads/kmod6/netlink_kernel_module.ko<br>make[1]: Leaving directory &#39;/usr/src/linux-headers-3.16.0-4-amd64&#39;</div><div><br></div><div>This is why nm does not show hello_init or hello_exit.</div><br><div>&gt;&gt; Can you please help me: what&#39;s the problem/mistake I am doing?</div><div><br></div><div>Change your Makefile so the module name is not the same as the C source file. Let&#39;s say</div><div>we want the module to be named aruna.ko ( make up any name different to the C source file)<br></div><div><br>obj-m := aruna.o<br>aruna-objs := netlink_kernel_module.o netlink_kernel_space.o <br></div><div><br></div><div>and now make shows:<br><br></div><div>make -C /lib/modules/3.16.0-4-amd64/build M=/home/aruna/kmod6/Kernel_User_comm modules<br>make[1]: Entering directory &#39;/usr/src/linux-headers-3.16.0-4-amd64&#39;<br>make[1]: Entering directory `/usr/src/linux-headers-3.16.0-4-amd64&#39;<br>  CC [M]  /home/aruna/kmod6/Kernel_User_comm/netlink_kernel_module.o  //   &lt;-- THIS TIME IT COMPILES !<br>  CC [M]  /home/aruna/kmod6/Kernel_User_comm/netlink_kernel_space.o<br>  LD [M]  /home/aruna/kmod6/Kernel_User_comm/aruna.o<br>  Building modules, stage 2.<br>  MODPOST 1 modules<br>  CC      /home/aruna/kmod6/Kernel_User_comm/aruna.mod.o<br>  LD [M]  /home/aruna/kmod6/Kernel_User_comm/aruna.ko<br>make[1]: Leaving directory &#39;/usr/src/linux-headers-3.16.0-4-amd64&#39;<br></div><div><br></div><div>and now nm aruna.ko shows:</div>aruna@debian:~/kmod6/Kernel_User_comm$ nm aruna.ko<br>0000000000000020 T cleanup_module<br>0000000000000080 T create_socket<br>0000000000000040 T data_update<br>                 U __fentry__<br>0000000000000020 t hello_exit               // WE HAVE hello_exit<br>0000000000000000 t hello_init                // WE HAVE hello_init<br>0000000000000000 T init_module<br>0000000000000070 T kernel_space_receiver<br>0000000000000050 T kernel_space_sender<br>0000000000000053 r __module_depends<br>0000000000000004 D pid<br>                 U printk<br>0000000000000000 D res<br>0000000000000000 D __this_module<br>0000000000000000 r __UNIQUE_ID_author2<br>0000000000000013 r __UNIQUE_ID_description1<br>0000000000000047 r __UNIQUE_ID_license0<br>000000000000005c r __UNIQUE_ID_vermagic0<br>0000000000000000 r ____versions<br><div><br></div><div>To get make to do this smoothly you will have to fix the multiple definition and</div><div>other errors I encountered along the way. And something&#39;s in your header<br></div><div>file really should belong in a C file :) heed Valdis&#39;s advice.<br></div><br><div>As a learning experience try this Makefile:</div><div>------------------------------------------------------------------------------------------------------<br>obj-m := aruna.o<br>aruna-objs := netlink_kernel_module.o netlink_kernel_space.o <br><br>SHELL += -x<br><br>all:<br>        	make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules<br>clean:<br>        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean<br></div><div>------------------------------------------------------------------------------------------------------</div><div><br></div><div>One simple way to enhance the output of GNU Make is to redefine SHELL. 
<br>SHELL is a GNU Make built-in variable that contains the name of the 
shell to use when <br></div><div>GNU Make executes commands.<br></div><div><br></div><div>Reference: <a href="https://www.cmcrossroads.com/article/tracing-rule-execution-gnu-make" target="_blank">https://www.cmcrossroads.com/article/tracing-rule-execution-gnu-make</a><br><br></div><div>Since most shells 
have a -x option that causes them to print out each command they <br></div><div>are 
about to execute modifying SHELL in a Makefile by appendin -x causes 
every command <br></div><div>to be printed (usually preceded by +) as the Makefile is 
run.</div><div><br></div><div>Try:</div><div>make clean the make and go through the output can be an enlightening experience.<br><br></div><div>Ah the joys of building a kernel module that has more than one source file :-)-- <br></div></div><div dir="ltr"><br></div><div>Good luck - Aruna</div><br></div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><b style="color:rgb(39,78,19)">Best Regards,</b></div><div><b style="color:rgb(39,78,19)"><br></b></div><div><b style="color:rgb(39,78,19)"><br></b></div><div dir="ltr"><b style="color:rgb(39,78,19)">Mr. Irfan Ullah</b><br></div><div dir="ltr"><font color="#666666">PhD Candidate<br></font><div><font color="#666666">Data and Knowledge Engineering(DKE) Lab</font></div><div><font color="#666666">Department of Computer Science and Engineering</font></div><div><font color="#666666">Kyung Hee University, South Korea.</font></div><div><img src="http://teedayusa.com/media/wysiwyg/telephone_icon.gif" style="font-family: arial, sans-serif; font-size: 12.8px;"><span style="font-family:arial,sans-serif;font-size:12.8px"> </span><span style="font-family:arial,sans-serif;font-size:12.8px"><font color="#000000"><a href="tel:+82%2010-3877-8867" value="+821038778867" style="color:rgb(17,85,204)" target="_blank">+82-010-591-51651</a></font></span></div><div><div style="font-family:arial,sans-serif;font-size:12.8px"><img src="http://www.letsplaydodgeball.com/ndo/templates/dj-sport01/images/system/emailButton.png" style="font-size: 12.8px;"><span style="font-size:12.8px"><font color="#000000">  </font></span><span style="font-size:12.8px"><font color="#000000"><a href="mailto:sahibzada.iu@gmail.com" style="color:rgb(17,85,204)" target="_blank">sahibzada.iu@gmail.com</a></font></span></div><div><font face="arial, sans-serif"><span style="font-size:12.8px"><img src="https://docs.google.com/uc?export=download&amp;id=0B1-dY3m3XHQnOFBOM0NSODNoUUU&amp;revid=0B1-dY3m3XHQnUmp1c0ZWTGovR2pYbGZCenlOU29DY3ByQU5RPQ" style="font-size: 12.8px;"></span></font><span style="font-family:arial,sans-serif;font-size:12.8px"> </span><font face="arial, sans-serif"><span style="font-size:12.8px">sahibzada_irfanullah</span></font></div></div></div></div></div>

[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, back to index

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-25  9:14 Kernel Module with multiple source files not initializing Irfan Ullah (울라 이르판)
2019-10-25 16:15 ` Abu Rasheda
2019-10-27  7:11   ` Irfan Ullah (울라 이르판)
2019-10-27  8:43 ` Bernd Petrovitsch
2019-10-28  9:43   ` Irfan Ullah (울라 이르판)
2019-10-28 10:04     ` Bernd Petrovitsch
2019-10-29  8:30       ` Irfan Ullah (울라 이르판)
2019-11-05 16:52 ` Aruna Hewapathirane
2019-11-07  1:50   ` Irfan Ullah (울라 이르판)

Kernel Newbies archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/kernelnewbies/0 kernelnewbies/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 kernelnewbies kernelnewbies/ https://lore.kernel.org/kernelnewbies \
		kernelnewbies@kernelnewbies.org
	public-inbox-index kernelnewbies

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernelnewbies.kernelnewbies


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git