Re: -ffreestanding option of GCC

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello Andi,
Please look at the following example and its output:
-----------------------------------------------------------
int func2(int a);
main(int r) {
	func2(4);
}

int func2(int a){
	return a*2;
}
-----------------------------------------------------------
/root/tmp3> gcc -v -ffreestanding -o prog1 prog1.c
Using built-in specs.
Target: i686-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info
--with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap
--enable-shared --enable-threads=posix --enable-checking=release
--with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-gnu-unique-object
--enable-languages=c,c++,objc,obj-c++,java,fortran,ada
--enable-java-awt=gtk --disable-dssi --enable-plugin
--with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre
--enable-libgcj-multifile --enable-java-maintainer-mode
--with-ecj-jar=/usr/share/java/eclipse-ecj.jar
--disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic
--with-arch=i686 --build=i686-redhat-linux
Thread model: posix
gcc version 4.4.2 20091222 (Red Hat 4.4.2-20) (GCC)
COLLECT_GCC_OPTIONS='-v' '-ffreestanding' '-o' 'prog1'
'-mtune=generic' '-march=i686'
 /usr/libexec/gcc/i686-redhat-linux/4.4.2/cc1 -quiet -v prog1.c -quiet
-dumpbase prog1.c -mtune=generic -march=i686 -auxbase prog1 -version
-ffreestanding -o /tmp/ccTthyep.s
ignoring nonexistent directory
"/usr/lib/gcc/i686-redhat-linux/4.4.2/include-fixed"
ignoring nonexistent directory
"/usr/lib/gcc/i686-redhat-linux/4.4.2/../../../../i686-redhat-linux/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /usr/lib/gcc/i686-redhat-linux/4.4.2/include
 /usr/include
End of search list.
GNU C (GCC) version 4.4.2 20091222 (Red Hat 4.4.2-20) (i686-redhat-linux)
	compiled by GNU C version 4.4.2 20091222 (Red Hat 4.4.2-20), GMP
version 4.3.1, MPFR version 2.4.1.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: ce871bdaf8715137a79dafbeccd13c96
COLLECT_GCC_OPTIONS='-v' '-ffreestanding' '-o' 'prog1'
'-mtune=generic' '-march=i686'
 as -V -Qy -o /tmp/ccYT96w6.o /tmp/ccTthyep.s
GNU assembler version 2.19.51.0.14 (i686-redhat-linux) using BFD
version version 2.19.51.0.14-34.fc12 20090722
COMPILER_PATH=/usr/libexec/gcc/i686-redhat-linux/4.4.2/:/usr/libexec/gcc/i686-redhat-linux/4.4.2/:/usr/libexec/gcc/i686-redhat-linux/:/usr/lib/gcc/i686-redhat-linux/4.4.2/:/usr/lib/gcc/i686-redhat-linux/:/usr/libexec/gcc/i686-redhat-linux/4.4.2/:/usr/libexec/gcc/i686-redhat-linux/:/usr/lib/gcc/i686-redhat-linux/4.4.2/:/usr/lib/gcc/i686-redhat-linux/
LIBRARY_PATH=/usr/lib/gcc/i686-redhat-linux/4.4.2/:/usr/lib/gcc/i686-redhat-linux/4.4.2/:/usr/lib/gcc/i686-redhat-linux/4.4.2/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-ffreestanding' '-o' 'prog1'
'-mtune=generic' '-march=i686'
 /usr/libexec/gcc/i686-redhat-linux/4.4.2/collect2 --eh-frame-hdr
--build-id -m elf_i386 --hash-style=gnu -dynamic-linker
/lib/ld-linux.so.2 -o prog1
/usr/lib/gcc/i686-redhat-linux/4.4.2/../../../crt1.o
/usr/lib/gcc/i686-redhat-linux/4.4.2/../../../crti.o
/usr/lib/gcc/i686-redhat-linux/4.4.2/crtbegin.o
-L/usr/lib/gcc/i686-redhat-linux/4.4.2
-L/usr/lib/gcc/i686-redhat-linux/4.4.2
-L/usr/lib/gcc/i686-redhat-linux/4.4.2/../../.. /tmp/ccYT96w6.o -lgcc
--as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s
--no-as-needed /usr/lib/gcc/i686-redhat-linux/4.4.2/crtend.o
/usr/lib/gcc/i686-redhat-linux/4.4.2/../../../crtn.o
-----------------------------------------------------------
Although i specified compiling in a free standing environment but
still libc.so, libgcc.so (-lc and -lgcc) and some other strange object
files are being linked with my program like ccYT96w6.o, crt1.o,
crtend.o...
Why?
Can i get rid of all of them some how?
My interpretation of free standing was a program which does not depend
on any external files, but why many files are here besides my file?


On Tue, Jan 4, 2011 at 12:23 PM, Andi Hellmund <mail@xxxxxxxxxxxxxxxx> wrote:
> On 01/04/2011 06:11 AM, ali hagigat wrote:
>>
>> What is the effect of -ffreestanding option? Is it like -fno-builtin
>> exactly?
>>
>>
>
> Hey Ali,
>
> here's a quote from the man page:
>
> "Assert that compilation takes place in a freestanding environment.  This
> implies -fno-builtin.  A freestanding environment is one in which the
> standard library may not exist, and program startup may not necessarily be
> at "main".  The most obvious example is an OS kernel.  This is equivalent to
> -fno-hosted."
>
> From the code-level, the -ffreestanding option just sets -fno-hosted and the
> -fno-bulitin option.
>
> Andi
>



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux