Compiler flag to toggle NX (NonExec) bit

Hi all,

I’m trying to find Clang's option equivalent to GNU binutil’s “-z execstack or
-z noexecstack” which is to toggle NX bit of output binary. For instance,
something similar to the following.

$ gcc -z execstack -o main main.c
$ execstack -q main
X main

Thanks for your help in advance.


-Wl,-z,execstack as you should be using for GCC as well.


Should Clang recognize -z as a linker flag? I've also tripped on this

I’m not necessarily a fan of bug per bug compatibility with GCC here, but recognizing these cases and emitting a “did you mean X?” warning might be helpful. I’ve also been bitten by this recently. Philip