0

I am trying to learn function call grammar in arm architecture and i compiled same code for user mode app and loadable kernel module. in attached picture you can see disassembly result for same function in two different mode. i am curious about reason of this difference.enter image description here

  • 3
    Those cannot be equivalent instruction sequences; one has a call to a function (`__gnu_mcount_nc`) that the other does not. If they were compiled from the same code, that suggests the differences are due to conditional inclusion or other preprocessor effects, or possibly compile-time optimizations that depend on expressions that use preprocessor symbols. You should provide a [mcve], including the source code that was compiled, the name and version of the compiler, the exact compiler command lines used (with all switches), and the assembly output from the compiler (rather than disassembly). – Eric Postpischil Jul 24 '19 at 14:21

1 Answers1

7

You have compiled the code with wildly different options. The first is ARM (32bit only) and the 2nd is Thumb2 (mixed 16/32bit); see hex opcodes at the side. Thumb2 used the first 8 registers in a compact way (16bit encodings) so the call interface is different. Ie, fp is r7 versus r12. This is why you are seeing different call sequences for the same code.

Also, the first has profiling enabled (why __gnu_mcount_nc is inserted).

It really has nothing to do with 'kernel' versus 'user' code. It is possible to compile user code with similar option as the kernel uses. There are many gcc command line options which affect the 'call interface' (search AAPCS for more information and the gcc ARM options help).

Related: ARM Link and frame pointer

artless noise
  • 21,212
  • 6
  • 68
  • 105