Understanding What Causes SEGV in an Application Print


If a user-space application terminates with SEGV, this means, as it is always the case in Linux, that the application did something that triggered an exception to the Cortex-M processor core. The most likely causes are:

  • You built your application for a processor architecture other than Cortex-M, which causes an "Unsupported instruction" exception.
  • Your application makes an attempt to access an address outside of the Cortex-M address space.
  • Your application makes an attempt to access unaligned data.

To understand what is causing an exception, do the following:

  • Enable CONFIG_DEBUG_USER in the kernel configuration. From your project directory, bring up the kernel configuration interface by running make kmenuconfig. Go to Kernel hacking and enable Verbose user fault messages.
  • In U-boot, add user_debug=8 to bootargs.
  • Having done the above, rebuild your Linux project, bring it up on the target and re-run your application. When the application fails with SEGV, there should be some informational messages on the system console indicating the cause of the fault.