Skip to contentSkip to conversation

The kernel is _always_ compiled with -msoft-float

2.6.8.1/x86 Denis Zaitsev 8 participants 9 messages Sep 14, 2004 – Sep 15, 2004

lore
Share & tools
lore
#0 lore raw

Why this kernel is always compiled with the FP emulation for x86? This is the line from the beginning of arch/i386/Makefile:

CFLAGS += -pipe -msoft-float

And it's hardcoded, it does not depend on CONFIG_MATH_EMULATION. So, is this just a typo or not?

#1 lore raw
Quoted 2 lines · Denis Zaitsev

Why this kernel is always compiled with the FP emulation for x86? This is the line from the beginning of arch/i386/Makefile:

To catch incorrect use of FPU code in the kernel

#2 lore raw
In reply to Denis Zaitsev
Quoted 7 lines · Denis Zaitsev

Why this kernel is always compiled with the FP emulation for x86? This is the line from the beginning of arch/i386/Makefile:

CFLAGS += -pipe -msoft-float

And it's hardcoded, it does not depend on CONFIG_MATH_EMULATION. So, is this just a typo or not?

To trap use of floating point in the kernel (not allowed). FPU emulation is only for userspace.

--
Brian Gerst

#3 lore raw
In reply to Denis Zaitsev
Quoted 7 lines · Denis Zaitsev

Why this kernel is always compiled with the FP emulation for x86? This is the line from the beginning of arch/i386/Makefile:

CFLAGS += -pipe -msoft-float

And it's hardcoded, it does not depend on CONFIG_MATH_EMULATION. So, is this just a typo or not?

this is on purpose; this way we get an error if someone uses floating point in the kernel.... which is BAD

#4 lore raw
In reply to Denis Zaitsev
Quoted 7 lines · Denis Zaitsev

Why this kernel is always compiled with the FP emulation for x86? This is the line from the beginning of arch/i386/Makefile:

CFLAGS += -pipe -msoft-float

And it's hardcoded, it does not depend on CONFIG_MATH_EMULATION. So, is this just a typo or not?

It deliberatly causes build failures if folks use fp math in their code.

Dave

#5 lore raw
In reply to Denis Zaitsev
Quoted 7 lines · Denis Zaitsev

Why this kernel is always compiled with the FP emulation for x86? This is the line from the beginning of arch/i386/Makefile:

CFLAGS += -pipe -msoft-float

And it's hardcoded, it does not depend on CONFIG_MATH_EMULATION. So, is this just a typo or not?

It catches bogus attempts to use floating point in the kernel by making them error at link-time.

Signature · 1 line
Mathematics is the supreme nostalgia of our time.
#6 lore raw
In reply to Denis Zaitsev

Thank everybody.

Whould it be better to document the trick? At least, this will prevent the others from suspicions.

i386/Makefile renamed from i386/Makefile.orig +2 -0
@@ -20,6 +20,8 @@ OBJCOPYFLAGS	:= -O binary -R .note -R .c
 LDFLAGS_vmlinux :=
 CHECK		:= $(CHECK) -D__i386__=1
 
+# The FP must not be used in the kernel code.  So, the bogus compiler
+# flag is here to catch such an attempts at the link stage.
 CFLAGS += -pipe -msoft-float
 
 # prevent gcc from keeping the stack 16 byte aligned
#7 lore raw
In reply to Denis Zaitsev

Salut,

Quoted 7 lines · Denis Zaitsev

Why this kernel is always compiled with the FP emulation for x86? This is the line from the beginning of arch/i386/Makefile:

CFLAGS += -pipe -msoft-float

And it's hardcoded, it does not depend on CONFIG_MATH_EMULATION. So, is this just a typo or not?

The problem is that the kernel can't use the FPU. I think this is because its context is not saved on context switch (userland ->

kernel),  so  we'd end  up  messing up  the  FPU  state, and  userland
applications  would get  silly results  for calculations  with context

switches in between.

Thus we force gcc to use the library functions for floating point arith, and since we don't link against gcc's lib, FPU users get a fancy linker error.

If you want to use floating point arith inside the kernel, you're probably wrong wanting it. If you really need it, you can

a) emulate it using fixed-point math on unsigned long or
b) manually save the FPU state, load your operations into it, operate, get the results and restore the FPU state.

I have yet to see someone who really needs to do floating point maths inside the kernel.

Tonnerre

#8 lore raw
Quoted 8 lines · Tonnerre
Quoted 7 lines · Denis Zaitsev

Why this kernel is always compiled with the FP emulation for x86? This is the line from the beginning of arch/i386/Makefile:

CFLAGS += -pipe -msoft-float

And it's hardcoded, it does not depend on CONFIG_MATH_EMULATION. So, is this just a typo or not?

[snip]

Quoted 3 lines

Thus we force gcc to use the library functions for floating point arith, and since we don't link against gcc's lib, FPU users get a fancy linker error.

It's a shame that gcc doesn't have -mno-float which could disable floating point completely and produce a more useful error message than a missing symbol at link time

I searched for ages just yesterday for the "float" in some kernel code I acquired recently... To be fair I was grepping for float and it was a double that was being used so if I'd had my brain turned on I would have found it quite quickly, but you get the point.

Has anyone ever suggested such a flag to the gcc folks?

Ian.

Signature · 4 lines
Ian Campbell
Current Noise: Megadeth - Pyschotron

Mind your own business, Spock.  I'm sick of your halfbreed interference.