title: "Segmentation fault" when `rmmod` or `modprobe -r`
body: <p>Trying the simplest kernel module from <a href="https://lwn.net/Kernel/LDD3/" rel="nofollow">LDD3</a> without any modification on custom built kernel v4.1.0-rc6 for Beagle Bone board with BusyBox v1.23.0. The code for the module is as follows:</p>
  
  <pre><code>#include &lt;linux/init.h&gt;
  #include &lt;linux/module.h&gt;
  MODULE_LICENSE("Dual BSD/GPL");
  static int hello_init(void)
  {
      printk(KERN_ALERT "Hello, world\n");
      return 0;
  }
  static void hello_exit(void)
  {
      printk(KERN_ALERT "Goodbye, cruel world\n");
  }
  module_init(hello_init);
  module_exit(hello_exit);
  </code></pre>
  
  <p>The Makefile is:</p>
  
  <pre><code>ARCH := arm
  CROSS_COMPILE := arm-cortex_a8-linux-gnueabi-
  obj-m := hello.o
  all:
          make ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) -C /path/to/linux/source/tree M=$(PWD) modules
  clean:
          make ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) -C /path/to/linux/source/tree M=$(PWD) clean
  </code></pre>
  
  <p>The module is compiling and installing on the rootfs just fine. also it is loading:</p>
  
  <pre><code>$ insmod hello.ko 
  [   30.692404] Hello, world
  </code></pre>
  
  <p>But when trying to remove it, I am getting:</p>
  
  <pre><code>$ rmmod hello.ko 
  Segmentation fault
  $modprobe -r hello.ko 
  Segmentation fault
  $ lsmod
  hello 813 0 - Live 0xbf000000 (O)
  </code></pre>
  
  <p>The kernel is compiled with module unloading (both regular and forced) support enabled. </p>
  
  <p>What can be the possible cause of this issue? What is the way to approach the investigation of it?</p>
  
  <p><strong>Update:</strong></p>
  
  <p>As suggested in the comments I have tried including <code>linux/kernel.h</code>, defining the <code>MODULE</code>,<code>LINUX</code> and <code>__KERNEL__</code> symbols. Added the<code>__init</code> and <code>__exit</code> prefixes to the functions. Removed the <code>static</code> modifiers. Removed the <code>printk</code> lines. The result the same. <code>dmesg</code> shows only the initial greeting. Loading and unloading of the kernel's modules such a <code>gpio_keys</code> or <code>crypto/ccm</code> <strong>is</strong> working, surprisingly. So the only thing remaining to suspect is the way the module is compiled..</p>
  
  <p><strong>Update 2</strong><br>
  Updating the kernel to the freshest snapshot didn't help. Compiled the module with different optimization settings didn't help. Next step, I guess, I am going to modify the BusyBox's rmmod to have some indication of the problem location..</p>