Linkers, Loaders & Executables

When recursion goes so deep that it exceeds the stack limit, what generally happens on Linux and similar systems?

  1. AIt touches a guard page beyond the stack where access is forbidden, and the program crashes
  2. BThe OS moves the stack to disk automatically, allowing unlimited depth
  3. COld stack frames are deleted automatically and the computation continues correctly
Show answer and explanation

Answer: A. It touches a guard page beyond the stack where access is forbidden, and the program crashes

The stack has a limit, and a guard page with access forbidden sits beyond it. When too-deep recursion pushes the stack into that page, a page fault occurs and the OS stops the program (a segmentation fault). The guard page's advantage is stopping the program before it corrupts other data. A large array as a local variable can cause the same thing, so large data is safer on the heap.

  • A. Correct. It is detected as a stack overflow.
  • B. The stack is not extended beyond its limit.
  • C. Silently deleting frames would make returning impossible.
Practice this topic Back to topic

More Linkers, Loaders & Executables questions

  1. In C, what is true of the starting values of a local variable and a global variable declared without initializers?
  2. After repeated malloc and free, a large block may become impossible to allocate even though total free memory is sufficient. What is this phenomenon called?
  3. When building a shared library, what is the advantage of exporting only the public functions and giving internal functions "hidden" symbol visibility?
  4. How does C++ run the constructors of global objects before main?
  5. Which statement is correct about the object file (.o) a compiler produces from one source file?