<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 <<a href="mailto:aruna.hewapathirane@gmail.com">aruna.hewapathirane@gmail.com</a>> 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">>> On Fri, Oct 25, 2019 at 5:16 AM Irfan Ullah (울라 이르판) <<a href="mailto:irfan@dke.khu.ac.kr" target="_blank">irfan@dke.khu.ac.kr</a>> wrote:</div><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 "__init and __exit" functions can in the output. <br></div><div><br></div><div>When you take a careful look at make'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 '/usr/src/linux-headers-3.16.0-4-amd64'<br>make[1]: Entering directory `/usr/src/linux-headers-3.16.0-4-amd64'<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 '/usr/src/linux-headers-3.16.0-4-amd64'</div><div><br></div><div>This is why nm does not show hello_init or hello_exit.</div><br><div>>> Can you please help me: what'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'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 '/usr/src/linux-headers-3.16.0-4-amd64'<br>make[1]: Entering directory `/usr/src/linux-headers-3.16.0-4-amd64'<br> CC [M] /home/aruna/kmod6/Kernel_User_comm/netlink_kernel_module.o // <-- 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 '/usr/src/linux-headers-3.16.0-4-amd64'<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's in your header<br></div><div>file really should belong in a C file :) heed Valdis'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&id=0B1-dY3m3XHQnOFBOM0NSODNoUUU&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>