How does ELF file format defines the stack?

半城伤御伤魂 提交于 2019-11-30 23:52:48

The following figure describes the memory map of a typical C ELF executable on x86.

  • The process loads the .text and .data sections at the base address.

  • The main-stack is located just below and grows downwards.

  • Each thread and function-call will have its own-stack.
    This is located located below the main-stack.

  • Each stack is separated by a guard page to detect Stack-Overflow.

Hence one does NOT need a dedicated stack section in the ELF file.


However within the man pages for ELF, one does find a couple of things in an ELF file that control the stack attributes. Mainly the executable permissions to the stack in memory.

  1. PT_GNU_STACK
    GNU extension which is used by the Linux kernel to control the state of the stack via the flags set in the p_flags member.

  2. .note.GNU-stack
    This section is used in Linux object files for declaring stack attributes. This section is of type SHT_PROGBITS. The only attribute used is SHF_EXECINSTR. This indicates to the GNU linker that the object file requires an executable stack.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!