I am writing a simple C program that I’m supposed to attack with a buffer overflow. So, I don’t want any flags used when compiling. How do I eliminate the default flags from being used?
# readelf -p .GCC.command.line stack
String dump of section '.GCC.command.line':
[ 0] stack.c
[ 8] -D_FORTIFY_SOURCE=2
[ 1c] -mtune=generic
[ 2b] -march=i486
[ 37] -frecord-gcc-switches
[ 4d] -fstack-protector
The only two options there that make any sense to override are
-D_FORTIFY_SOURCEand-fstack-protector, so just include-U_FORTIFY_SOURCEand-fnostack-protector, and they’re effectively “gone”.You can’t compile for “no architecture” (
march), and getting rid ofmtuneis similarly meaningless. GCC has to build code for something. You’re already about as generic as you can get there.-frecord-gcc-switches, well, without that, you wouldn’t know what switches were included in the first place, but if you really want to get rid of it, just use-fnorecord-gcc-switches.-f*options are mostly boolean flags, so you can almost always turn them off by addingnoat the front as I’ve done above.