The command:
gcc -fno-stack-protector -z execstack -o ExitCode ExitCode.c
I know that I need to include-z execstack
for my code to work, and I basically have an idea what execstack
is for and what it allows me to do. But I don't know what the -z
option is doing here. I've looked and grep
'd at the gcc
and execstack
man pages and used --help
on both but without finding a straight answer. I am guessing it is enabling the addition of the execstack
functionality...?
When you invoke GCC, it normally does preprocessing, compilation, assembly and linking. The "overall options" allow you to stop this process at an intermediate stage. For example, the -c option says not to run the linker. Then the output consists of object files output by the assembler.
The compiler enables you to use multiple options even where these might conflict. This means that you can append new options to an existing command line, for example, in a makefile or a via file. Where options override previous options on the same command line, the last option specified always takes precedence.
The -c option tells g++ to compile the program to an object file only; without it, g++ will attempt to link the program to produce an executable. After you've typed this command, you'll have an object file called reciprocal.o. The -I option is used to tell GCC where to search for header files.
Add directory dir to the list of directories to be searched for -l . This option specifies where to find the executables, libraries, include files, and data files of the compiler itself. The compiler driver program runs one or more of the subprograms cpp , cc1 , as and ld .
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With