title: Unkonwn Symbol error in installing kernel module
body: <p>I am doing my OS assignments. The assignment requires us to write and compile a linux kernel module. I am required to use _do_fork in kernel/fork.c to fork a process. However, when I was trying to install my module into kernel space, the installation failed with the following error message:</p>
  <p><code>ERROR: could not insert module program2.ko: Unknown symbol in module</code></p>
  <p>and the message in kernel space is:</p>
  <p><code>program2: Unknown symbol _do_fork (err 0)</code></p>
  <p>Here comes my attempts to solve the problem:
  I have exported the symbol '_do_fork' in the source code of fork.c:</p>
  <pre><code>//fork.c
  long _do_fork(unsigned long clone_flags,
            unsigned long stack_start,
            unsigned long stack_size,
            int __user *parent_tidptr,
            int __user *child_tidptr,
            unsigned long tls)
  {
      (body of _do_fork function);
  }
  EXPORT_SYMBOL_GPL(_do_fork);//I also tried EXPORT_SYMBOL()
  </code></pre>
  <p>and recompile the kernel:</p>
  <p><code>/my_linux_source_path/$me make bzImage</code></p>
  <p>and reboot the system, and found the exported symbol within Module.symvers:</p>
  <p><code>0x00000000 _do_fork    vmlinux EXPORT_SYMBOL_GPL</code></p>
  <p>and use extern to declare it in my own source file:</p>
  <pre><code>//program2.c
  MODULE_LICENSE(&quot;GPL&quot;);
  extern long _do_fork (unsigned long clone_flags,
      unsigned long stack_start,  
      unsigned long stack_size,
      int __user *parent_tidptr,
      int __user *child_tidptr,
      unsigned long tls);
  
  int my_exec(void){
      printk(&quot;iamhere&quot;);
      return 0;
  }
  int my_fork(void *argc){
  
      //set default sigaction for current process
      int i;
      struct k_sigaction *k_action = &amp;current-&gt;sighand-&gt;action[0];
      for(i=0;i&lt;_NSIG;i++){
          k_action-&gt;sa.sa_handler = SIG_DFL;
          k_action-&gt;sa.sa_flags = 0;
          k_action-&gt;sa.sa_restorer = NULL;
          sigemptyset(&amp;k_action-&gt;sa.sa_mask);
          k_action++;
      }
      
      /* fork a process using do_fork */
      int pid;
      
      pid=_do_fork(SIGCHLD,(unsigned long)&amp;my_exec,0,NULL,NULL,0);
      printk(&quot;%d&quot;,pid);
      /* execute a test program in child process */
      
      /* wait until child process terminates */
      
      return 0;
  }
  //program init and exit; module init and exit;
  ...
  
  
  
  </code></pre>
  <p>But the same error still exist and I have no idea about the causes. Could anyone help me?
  The kernel I am using is Linux-4.10.14, gcc version is (Ubuntu 5.4.0-6ubuntu1~16.04.10) 5.4.0 20160609</p>