This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: -ffreestanding option of GCC
ali hagigat <hagigatali@gmail.com> writes:
> Thank you Ian for the reply. If -ffreestanding is not specified ,
> compiler may optimize the code based on considerations? without making
> sure if a function is built-in or it has been defined by a standard
> library?
> What are these modifications exactly?
The optimizations which gcc implements in the default hosted environment
are fairly extensive. In general, in a hosted environment, gcc can
assume that there is a complete library available that meets the
conditions of the language standard being used (the default for C is
gnu90, the GNU extension to the ISO C90 standard). That means, for
example, it can optimize printf("hi\n") into puts("hi"). There are many
such optimizations. When -ffreestanding is used, gcc does not assume
that you are using a standard library environment.
> -ffreestanding
> A freestanding environment is one in which the standard
> library may not exist, and program startup may not necessarily be at main.
> --------------------------------------------------------------------------------
> I have copied part of gcc manual. The fact that program startup may
> not necessarily be at main, is not a special feature which is created
> by -ffreestanding option! If we do not specify any option or use
> -fhosted, program startup may not necessarily be at main too!!
> Why the manual mentions the issue?
Your statement is incorrect. The C90 standard specifies that a program
starts at main, and on some (but not most) targets gcc does take
advantage of that fact to run certain initialization code at that time.
If you use -ffreestanding, gcc does not assume that the program starts
at main.
Ian