4 ms·
The title is slightly misleading. Inline assembly code in asm statements has no effect on the stack. If you have your own .S files, and those do not contain th
by fefe23 10y ago
The title is slightly misleading.
Inline assembly code in asm statements has no effect on the stack.
If you have your own .S files, and those do not contain the magic handshake, then the stack will stay executable, and this is indeed a programmer trap.
The reason for this is that historically the stack was always executable, so it could not be make non-executable by default, it had to be opt in. In fact, gcc will generate code that requires the stack to be executable if you use a certain gcc extension (related to nested functions).
The other way to opt-in into non-executable stack is passing --noexecstack to as(1) (or when via gcc, use -Wa,--noexecstack)
This ought to be better documented, but it's not. The rationaly is probably that you should not be writing assembly code if you don't know this kind of detail? I can only guess about this.
- tbirdz 10y agoI just checked and it's mentioned in the elf and ld manpages. It should probably be called out more, but there is at least some documentation for it. from man elf: .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.
- kazinator 10y agoThe text you quoted doesn't inform anyone that if you don't have that section at all, an executable stack is also required. I can't find any such explanation in the elf man page. Nobody is going to read "man elf" or "man ld", if they already know how to write assembly code and link it to their C, and whatever they know appears to be working fine.
- djcapelis 10y agoPeople who know how to write assembly code and link it into their C programs are probably one of the most likely folks to read man elf and man ld, but I definitely agree the documentation should be better. Submit a patch?
- kazinator 10y agoI edited the title quite a few times to reduce verbiage, and did mention in the body that inline code isn't affected. Earlier revisions of the title had wording to the effect of assembly language modules, or source files, etc. I left it a little click-baity, but I figured this is likely of use to people doing inline assembly (what is inline today could bust out into its own module tomorrow), and the navigation says within HN anyway.
- bogomipz 10y agoWhat is the "magic handshake"? Also are the gcc extensions related to nested functions that will generate an executable stack documented? What would I search for in the documentation?
- ThisIs_MyName 10y agoThe magic handshake is: .section .note.GNU-stack,"",@progbits