Showing posts with label explanation. Show all posts
Showing posts with label explanation. Show all posts

Monday, May 3, 2021

Linux: Why do we need an executable stack with nested functions in GCC

 

  • The stack needs to be writable because the trampoline code is written on the stack which needs to be executed (to jump to the nested function). 
A nested function has no linkage by itself. So the trampoline code actually ensures two things:
  1. The outer () functions stack frame is available in the nested function
  2. Jump and execute code from the nested function.
Some other notes:
  • Nested functions are not a part of ANSI C, however, they are part of Gnu C.
  • The only reason nested functions are possibly useful because they use common stack variables.

Sunday, April 25, 2021

Linux: Kernel makefile system in brief

 There are multiple components in the kernel build system as shown in the table below:



Components in the Linux kernel build system

The Top makefile builds kernel image and modules. It does this by visiting directories recursively based on the kernel .config. The top Makefile textually includes an arch Makefile with the name arch/$(ARCH)/Makefile. The arch Makefile supplies architecture-specific information to the top Makefile. Each directory has a kbuild makefile which builds built-in or modular targets based on commands passed from above and info n the .config. Makefiles in the kernel are also referred to as kbuild files.

Further reading: A detailed discussion on these is available in the kernel documentation.