Skip to contentSkip to conversation

Use -ffreestanding? (fwd)

PATCH In review Adrian Bunk 3 participants 5 messages Nov 22, 2004 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Use -ffreestanding? (fwd)

Hi Andrew,

for the kernel, it would be logical to use -ffreestanding. The kernel is not a hosted environment with a standard C library.

Linus agreed that it would make sense.

The gcc option -ffreestanding is supported by both gcc 2.95 and 3.4, which covers the whole range of currently supported compilers.

Could you add the patch below to the next -mm to see whether there are any problems I didn't find?

TIA
Adrian

Makefile renamed from Makefile.old +2 -1
@@ -349,7 +349,8 @@
 CPPFLAGS        := -D__KERNEL__ $(LINUXINCLUDE)
 
 CFLAGS 		:= -Wall -Wstrict-prototypes -Wno-trigraphs \
-	  	   -fno-strict-aliasing -fno-common
+	  	   -fno-strict-aliasing -fno-common \
+		   -ffreestanding
 AFLAGS		:= -D__ASSEMBLY__
 
 export	VERSION PATCHLEVEL SUBLEVEL EXTRAVERSION LOCALVERSION KERNELRELEASE \
#1 lore raw
Quoted 5 lines · Adrian Bunk

for the kernel, it would be logical to use -ffreestanding. The kernel is not a hosted environment with a standard C library.

Linus agreed that it would make sense.

Note that while I agree that it sounds sensible, it would be good to have somebody specify exactly what changes from the use of "-ffreestanding".

I _assume_ that all the things that gcc takes for granted are things that Linux already has its own definitions for, and that -ffreestanding doesn't actually change anything for at least the regular architectures. But if there is any object code changes, can you check those out and explain them?

Linus

#2 lore raw
Quoted 9 lines · Linus Torvalds
Quoted 5 lines · Adrian Bunk

for the kernel, it would be logical to use -ffreestanding. The kernel is not a hosted environment with a standard C library.

Linus agreed that it would make sense.

Quoted 8 lines

Note that while I agree that it sounds sensible, it would be good to have somebody specify exactly what changes from the use of "-ffreestanding".

I _assume_ that all the things that gcc takes for granted are things that Linux already has its own definitions for, and that -ffreestanding doesn't actually change anything for at least the regular architectures. But if there is any object code changes, can you check those out and explain them?

Andi Kleen reported:
Newer gcc rewrites sprintf(buf,"%s",str) to strcpy(buf,str) transparently.

This is only true with unit-at-a-time (disabled on i386 but enabled on x86_64). The Linux kernel doesn't offer a standard C library, and such transparent replacements of kernel functions with builtins are quite fragile.

Even with -ffreestanding, it's still possilble to explicitely use a gcc builtin if desired.

Quoted 1 line

Linus

cu
Adrian

Signature · 4 lines
       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed
#3 lore raw
In reply to Adrian Bunk
Quoted 4 lines

Hi Andrew,

for the kernel, it would be logical to use -ffreestanding. The kernel is not a hosted environment with a standard C library.

Note the GCC docs:

Assert that compilation takes place in a freestanding environment. This implies -fno-builtin. [...]

This will break a lot of code, since there are many thing that depend upon GCC builtin magic AFAICS.

(BTW, seems to be supported by GCC 3.3.0 too, because that manpage is packaged together with gcc-3.3.rpm (suse 9.x))

Jan Engelhardt

Signature · 2 lines
Gesellschaft für Wissenschaftliche Datenverarbeitung
Am Fassberg, 37077 Göttingen, www.gwdg.de
#4 lore raw
Quoted 5 lines · Jan Engelhardt
Quoted 4 lines

Hi Andrew,

for the kernel, it would be logical to use -ffreestanding. The kernel is not a hosted environment with a standard C library.

Quoted 8 lines

Note the GCC docs:

Assert that compilation takes place in a freestanding environment. This implies -fno-builtin. [...]

This will break a lot of code, since there are many thing that depend upon GCC builtin magic AFAICS.
...

Which code in the kernel is broken by this change?

Note that explicitely using a gcc builtin is still possible.

Quoted 1 line

Jan Engelhardt

cu
Adrian

Signature · 4 lines
       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed