I can't seem to figure out the purpose of the flag -nostartfiles
. It prevents main()
from being called immediately, and typically you'd also specify the program entry point. However, why would I want to do that? I have written a kernel that required it, since everything was up to me to get started, but other than that, is there a non-OS reason to specify a different program entry point?
Turning on optimization flags makes the compiler attempt to improve the performance and/or code size at the expense of compilation time and possibly the ability to debug the program. The compiler performs optimization based on the knowledge it has of the program.
It is a compiler system for the various programming languages. It is mainly used to compile the C and C++ programs. It takes the name of the source program as a necessary argument; rest arguments are optional such as debugging, warning, object file, and linking libraries. GCC is a core component of the GNU toolchain.
GCC and Clang have several warning flags which will enable a collection of useful checks which we will explore in more detail below.
gcc -Wall enables all compiler's warning messages. This option should always be used, in order to generate better code.
You'd use -nostartfiles
(and -nostdlib
) when you do not want any standard libraries (like libc and libgcc) to be linked in and standard initialization actions, like calling C++ constructors, to be run. Typical use-cases are writing system software like kernels or firmwares.
I think that with -nostartfiles
command line arguments will not be passed to main()
and environment variables will not be available to the executable, among other things. Docker uses -nostartfiles
in an example where a single binary is run within a simple container, i.e., where the container is run like a single binary: https://docs.docker.com/develop/develop-images/baseimages/, so that is another use case.
Slightly related is Source for 'startup files' in gcc/mingw, which lists functions that are linked into to the code if -nostartfiles
option is not used.
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