I am currently reading Linux Kernel Development by Robert Love.

In the chapter "15 The Process Address Space" he prints the memory map of a process.

user@machine:~$ pmap 1424
#all the processes mapped memory (skipped for readability)
bfffe000 (8KB)        rwxp (0:00 0)         [ stack ]

The last line shows the stack (as it grows down).
He now states:

The stack is, naturally, readable, writeable and executable - not of much use otherwise.

As far as I know we use the stack for data and code addresses (functions and their parameters/variable).

I do not understand why the stack must be executable?


That information is outdated, and the stack is typically not executable any more:

00007ffd884fa000    356K rw---   [ stack ]

GCC needs an executable stack if it generates trampolines for nested function calls. These trampolines are small pieces of code generated at runtime, and stored on the stack — so if they are used, the stack needs to be executable. The compiler keeps track of this requirement, and it outputs a flag in binaries (libraries and executables) to indicate whether they need an executable stack. You can see and manipulate the value of this flag using execstack(8).

  • Thanks for the answer. I did not have access to a linux machine since I read the chapter and it was really bugging me. – Altoyr Feb 23 '17 at 11:46
  • On the other hand, inner functions are being used more and more. It's better code. – Joshua Oct 16 '18 at 15:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.