Well, my set of flags is more or less:
Code: Select all
CODEGEN = -pipe -march=i486 -O3 -fno-omit-frame-pointer \
-mpreferred-stack-boundary=2 -fno-strict-aliasing
NOLIBS = -nostdinc -nostdlib -fno-builtin -ffreestanding -fno-common
Both variables are given to compiler. They are separated mainly make the Makefile more manageable.
-pipe just makes gcc use pipes instead of temporary files
-march=i486 says it's ok to use 486-only stuff (this could probably be higher.. but)
-O3 is maximum optimization level (4-6 don't add anything)
-fno-omit-frame-pointer tells gcc to leave frame pointers alone, so I can dump stack on panic. Could be omitted for production compiles. This is explicitly there because -O3 turns enables the optimization otherwise.
-mpreferred-stack-boundary=2 aligns stack boundaries to 2^2 = 4 bytes. That's minimum correct alignment for ia-32. The default would be 4 (=2^4=16 bytes), but I prefer not to waste stack space (so I can have smaller kernel stacks) and don't need bigger alignment for anything.
-fno-strict-aliasing is needed because I do some fancy stuff with pointers and integers, and generally violate all kinds of aliasing rules.
-nostdinc disable standard includes
-nostdlib disables standard libraries (libC etc.)
-fno-builtin tells gcc not to expect it's "builtins" to work
-ffreestanding isn't really needed on Linux I believe, but..
-fno-common is really just there as a sanity check, so I don't accidentally share a variable unintentionally between to units
I also use:
Code: Select all
INCLUDES = -I. -Iinclude
WARNINGS = -Werror -Wall -Wstrict-prototypes -Wpointer-arith -Wcast-align -Wcast-qual
First one gives us a new include path (the standard was disabled), and the second causes tons of warnings to be emitted, and made fatal, mainly to sanitycheck that everything is really what it looks like.
Btw: -fvolatile* might not be good idea. This can cause quite a dramatic speed hit in places where it's not really needed. Personally I prefer to declare any volatile stuff explicitly as volatile. I find the flag useful mainly when a bug looks like it might be caused by a missing 'volatile'-qualifier (if it's fixed by the flag, then something isn't declared properly).