Robert Millan <r...@gnu.org> writes: > I'm not familiar with PT_GNU_STACK. Does a working > _dl_make_stack_executable() in glibc [1] indicate it's supported? > > [1] > http://svn.debian.org/viewsvn/glibc-bsd/trunk/glibc-ports/kfreebsd/dl-execstack.c?revision=1685&view=markup
PT_GNU_STACK is a program header recognized by the Linux kernel when loading an ELF executable or shared library. If any executable or shared library has a PT_GNU_STACK segment for which the PF_X bit is set in the p_flags field, then the kernel will mark the stack as permitting execution (i.e., will mmap it with PROT_EXEC as well as PROT_READ and PROT_WRITE). _dl_make_stack_executable is a related but distinct mechanism which is used by the dynamic linker to make the stack executable when 1) the stack was loaded as non-executable; 2) there is now some reason to make the stack executable, e.g., a dlopen of a shared library which has a PT_GNU_STACK header indicating that an executable stack is required. As Joseph said, for the specific (and common) case of dynamically linked binaries it's possible to make this work without kernel support, under the assumption that the kernel runs the dynamic linker without an executable stack. However, for statically linked binaries, PT_GNU_STACK is only useful if the kernel supports it. All that said, I see little harm in using a PT_GNU_STACK header on binaries even if the kernel does not fully support them. Except for the small amount of wasted space in every .o file and every executable, but I lost that argument years ago. Ian