-ffreestanding 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. $ cat switch64.c #include "/usr/src/linux/include/linux/types.h" __u64 test(__u64 val) { switch (val) { case 0: return 0; break; case 1: return 1; break; default: return -1; } } $ gcc switch64.c -c -ffreestanding $ objdump -t switch64.o switch64.o: file format elf32-sparc SYMBOL TABLE: 00000000 l df *ABS* 00000000 switch64.c 00000000 l d .text 00000000 00000000 l d .data 00000000 00000000 l d .bss 00000000 00000000 l d .note.GNU-stack 00000000 00000000 l d .comment 00000000 00000000 *UND* 00000000 __ucmpdi2 ^^^^^^^^^ 00000000 g F .text 0000009c test $ objdump -T /lib/libgcc_s.so|grep __uc 0000181c g DF .text 00000038 GCC_3.0 __ucmpdi2 $ ldd /lib/libgcc_s.so libc.so.6 => /lib/libc.so.6 (0x70028000) /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x08000000) In the kernel sources such situations happen very often. In the case of __ucmpdi2, it appears to be a combination of kernel and compiler stupidity - there's no reason why __ucmpdi2 should not be done inline by the compiler, but at the same time there is probably also little reason to use a slow "long long" comparison in the kernel. Of course I can force a static linking with libgcc.a but in the above case gcc should report an error or do inline and warn user.
While I confirm that the undefined symbol __ucmpdi2 is emitted by the compiler, I'm a bit skeptical about your interpretation of '-ffreestanding': __ucmpdi2 is provided by libgcc.a, not by the standard library. So it is possible to build a standalone executable containing the chunk of code with the compiler only.
(In reply to comment #1) > While I confirm that the undefined symbol __ucmpdi2 is emitted by the compiler, > I'm a bit skeptical about your interpretation of '-ffreestanding': __ucmpdi2 is > provided by libgcc.a, not by the standard library. by libgcc_s.so (which is linked with standard library) too. > So it is possible to build a standalone executable (...) with libgcc.a - yes. with libgcc_s.so - no.
A freestanding implementation won't have a shared libgcc. Mind you that GNU/Linux is _not_ a freestanding implementation.
Sorry but no these are not a violation of `-ffreestanding' at all, since otherwise there is no way to support 64bit in 32bit targets at all or some other builtins which are done like __builtin_ctlz and such. So this is invalid.
Note you can use -static-libgcc to get the static libgcc.
*** Bug 32501 has been marked as a duplicate of this bug. ***