What is the -z option for in this gcc compiler command? What is the -z option for in this gcc compiler command? linux linux

What is the -z option for in this gcc compiler command?


In your case is -z execstack

-z is passed directly to the linker along with the keyword execstack.

Source: https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html#index-z

About the execstack

Linux has in the past allowed execution of instructions on the stack and there are lots of binaries and shared libraries assuming this behaviour. Furthermore, GCC trampoline code for e.g. nested functions requires executable stack on many architectures. To avoid breaking binaries and shared libraries which need executable stack, ELF binaries and shared libraries now can be marked as requiring executable stack or not requiring it. This marking is done through the p_flags field in the PT_GNU_STACK program header entry. If the marking is missing, kernel or dynamic linker need to assume it might need executable stack. The marking is done automatically by recent GCC versions (objects using trampolines on the stack are marked as requiring executable stack, all other newly built objects are marked as not requiring it) and linker collects these markings into marking of the whole binary or shared library. The user can override this at assembly time (through --execstack or --noexecstack assembler options), at link time (through -z execstack or -z noexecstack linker options) and using the execstack tool also on an already linker binary or shared library. This tool is especially useful for third party shared libraries where it is known that they don't need executable stack or testing proves it.

Source: http://linux.die.net/man/8/execstack

Hope this helps.


It's a linker option. That -z is passed straight to the linker is not mentioned in the man page, but it is mentioned here in the online documentation.

So the place to look for it is the ld manpage. From it:

 -z keyword     The recognized keywords are: (...)     execstack         Marks the object as requiring executable stack.