我有一个不支持浮点单元 (FPU) 的 x86 内核,我正在编写一个用于浮点计算的微内核,例如 add、div、mul、pow、log 等。根据需要,我必须使用静态库来做浮动计算。我发现使用具有数学库的 glibc(来自 GNU)。这意味着我必须使用“-msoft-float”编译器开关或“没有-fp”来编译 glibc。在 stackoverflow.com 中进行搜索后,我发现 glibc 可以通过如下给出的命令序列进行编译(来自链接 - How to compile glibc 32bit on an x86_64 machine):
注意-我有在 win7 桌面上运行 VMware 的 Ubuntu12.04 版本。
$Mkdir build-glib
$Cd build-glib
$../glibc-2.17/configure --prefix=$HOME/glibc-2.17 --host=i686-linux-gnu \
--build=i686-linux- gnu \
CC="gcc -m32" CXX="g++ -m32" CFLAGS="-O2 -march=i686" \
CXXFLAGS="-O2 -march=i686"
$make
$.....
以上构建成功。现在我尝试编译“with_fp='no'”配置选项,但出现以下错误。
$../glibc-2.17/configure --prefix=$HOME/glibc-2.17 --host=i686-linux-gnu \
--build=i686-linux-gnu \
CC="gcc -m32" CXX="g++ -m32" CFLAGS="-O2 -march=i686" \
CXXFLAGS="-O2 -march=i686" with_fp=”no”
$make
$.....
gcc -m32 ../sysdeps/ieee754/dbl-64/e_exp.c -c -std=gnu99 -fgnu89-inline -fno-stack-protector -
O2 -Wall -Winline -Wwrite-strings -fmerge-all-constants -frounding-math -march=i686 -Wstrict-
prototypes -mpreferred-stack-boundary=4 -Wa,-mtune=i686 -Wno-uninitialized -
U_FORTIFY_SOURCE -D__NO_MATH_INLINES -D__LIBC_INTERNAL_MATH_INLINES -I../include -
I/home/rajiv/Downloads/build-glib/math -I/home/rajiv/Downloads/build-glib -
I../nptl/sysdeps/unix/sysv/linux/i386/i686 -I../sysdeps/unix/sysv/linux/i386/i686 -
I../nptl/sysdeps/unix/sysv/linux/i386 -I../nptl/sysdeps/unix/sysv/linux/x86
-I../sysdeps/unix/sysv/linux/x86 -I../sysdeps/unix/sysv/linux/i386/nptl -
I../sysdeps/unix/sysv/linux/i386 -I../nptl/sysdeps/unix/sysv/linux -I../nptl/sysdeps/pthread -
I../sysdeps/pthread -I../ports/sysdeps/unix/sysv/linux -I../sysdeps/unix/sysv/linux -
I../sysdeps/gnu -I../sysdeps/unix/inet -I../nptl/sysdeps/unix/sysv -
I../ports/sysdeps/unix/sysv -I../sysdeps/unix/sysv -I../sysdeps/unix/i386 -
I../nptl/sysdeps/unix -I../ports/sysdeps/unix -I../sysdeps/unix -I../sysdeps/posix -
I../sysdeps/i386/i686/multiarch -I../nptl/sysdeps/i386/i686 -I../sysdeps/i386/i686 -
I../sysdeps/i386/i486 -I../nptl/sysdeps/i386/i486 -I../nptl/sysdeps/i386 -I../sysdeps/i386 -
I../sysdeps/x86 -I../sysdeps/wordsize-32 -I../sysdeps/ieee754/ldbl-96 -I../sysdeps/ieee754/dbl-
64 -I../sysdeps/ieee754/flt-32 -I../sysdeps/ieee754 -I../sysdeps/generic -I../nptl -I../ports -
I.. -I../libio -I. -D_LIBC_REENTRANT -include ../include/libc-symbols.h -DNOT_IN_libc=1 -
DIS_IN_libm=1 -DIN_LIB=libm -o /home/rajiv/Downloads/build-glib/math/e_exp.o -MD -MP -
MF /home/rajiv/Downloads/build-glib/math/e_exp.o.dt -MT /home/rajiv/Downloads/build-
glib/math/e_exp.o
../sysdeps/ieee754/dbl-64/e_exp.c: In function ‘__ieee754_exp’:
../sysdeps/ieee754/dbl-64/e_exp.c:64:3: error: ‘FE_TONEAREST’ undeclared (first use in this
function)
../sysdeps/ieee754/dbl-64/e_exp.c:64:3: note: each undeclared identifier is reported only once
for each function it appears in
make[2]: *** [/home/rajiv/Downloads/build-glib/math/e_exp.o] Error 1
make[2]: Leaving directory `/home/rajiv/Downloads/glibc-2.17/math'
make[1]: *** [math/others] Error 2
make[1]: Leaving directory `/home/rajiv/Downloads/glibc-2.17'
make: *** [all] Error 2
然后我尝试使用“-msoft-float”开关编译 glibc。我使用了以下命令,但再次出错。
$../glibc-2.17/configure --prefix=$HOME/glibc-2.17 --host=i686-linux-gnu \
--build=i686-linux-gnu \
CC="gcc -m32 –msoft-float" CXX="g++ -m32 –msoft-float" CFLAGS="-O2 -march=i686 –msoft-float" \
CXXFLAGS="-O2 -march=i686 –msoft-float"
$make
$.....
/home/rajiv/Downloads/build-glib/shlib.lds /home/rajiv/Downloads/build-glib/csu/abi-
note.o /home/rajiv/Downloads/build-glib/elf/soinit.os /home/rajiv/Downloads/build-
glib/libc_pic.os /home/rajiv/Downloads/build-glib/elf/sofini.os /home/rajiv/Downloads/build-
glib/elf/interp.os /home/rajiv/Downloads/build-glib/elf/ld.so -lgcc
/home/rajiv/Downloads/build-glib/libc_pic.os: In function `__modf':
(.text+0x144d0): undefined reference to `__subdf3'
/home/rajiv/Downloads/build-glib/libc_pic.os: In function `ldexp':
(.text+0x1463f): undefined reference to `__eqdf2'
(.text+0x14f34): undefined reference to `__eqxf2'
/home/rajiv/Downloads/build-glib/libc_pic.os: In function `__erand48_r':
(.text+0x1963b): undefined reference to `__subdf3'
/home/rajiv/Downloads/build-glib/libc_pic.os: In function `round_and_return':
strtof_l.c:(.text+0x1ba9d): undefined reference to `__mulsf3'
strtof_l.c:(.text+0x1bd43): undefined reference to `__mulsf3'
/home/rajiv/Downloads/build-glib/libc_pic.os:(.text+0x1c36b): more undefined references to
`__mulsf3' follow
/home/rajiv/Downloads/build-glib/libc_pic.os: In function `round_and_return':
strtod_l.c:(.text+0x1ef5e): undefined reference to `__muldf3'
strtod_l.c:(.text+0x1f12c): undefined reference to `__muldf3'
/home/rajiv/Downloads/build-glib/libc_pic.os: In function `__GI_____strtod_l_internal':
(.text+0x1f91c): undefined reference to `__muldf3'
/home/rajiv/Downloads/build-glib/libc_pic.os:(.text+0x1fc7f): more undefined references to
`__muldf3' follow
wcstod_l.c:(.text+0x84a28): undefined reference to `__muldf3'
wcstod_l.c:(.text+0x84a9e): undefined reference to `__muldf3'
wcstod_l.c:(.text+0x84c6c): undefined reference to `__muldf3'
/home/rajiv/Downloads/build-glib/libc_pic.os: In function `____wcstod_l_internal':
(.text+0x85285): undefined reference to `__muldf3'
/home/rajiv/Downloads/build-glib/libc_pic.os:(.text+0x8578d): more undefined references to
`__muldf3' follow
/home/rajiv/Downloads/build-glib/libc_pic.os: In function `round_and_return':
wcstold_l.c:(.text+0x87e48): undefined reference to `__mulxf3'
wcstold_l.c:(.text+0x880a9): undefined reference to `__mulxf3'
/home/rajiv/Downloads/build-glib/libc_pic.os:(.text+0x886e1): more undefined references to
`__mulxf3' follow
/home/rajiv/Downloads/build-glib/libc_pic.os: In function `round_and_return':
wcstof_l.c:(.text+0x8b278): undefined reference to `__mulsf3'
wcstof_l.c:(.text+0x8b3e3): undefined reference to `__mulsf3'
/home/rajiv/Downloads/build-glib/libc_pic.os:(.text+0x8b8f1): more undefined references to
`__mulsf3' follow
/home/rajiv/Downloads/build-glib/libc_pic.os: In function `difftime':
(.text+0x91e37): undefined reference to `__floatsidf'
/home/rajiv/Downloads/build-glib/libc_pic.os: In function `difftime':
/home/rajiv/Downloads/build-glib/libc_pic.os: In function `ecvt_r':
(.text+0xd64f6): undefined reference to `__muldf3'
/home/rajiv/Downloads/build-glib/libc_pic.os: In function `qfcvt_r':
(.text+0xd6934): undefined reference to `__mulxf3'
/home/rajiv/Downloads/build-glib/libc_pic.os: In function `__qecvt_r':
(.text+0xd6fd7): undefined reference to `__ltxf2'
/home/rajiv/Downloads/build-glib/libc_pic.os: In function `__qecvt_r':
(.text+0xd7007): undefined reference to `__mulxf3'
/home/rajiv/Downloads/build-glib/libc_pic.os: In function `__monstartup':
(.text+0xdd792): undefined reference to `__fixsfsi'
collect2: ld returned 1 exit status
make[2]: *** [/home/rajiv/Downloads/build-glib/libc.so] Error 1
make[2]: Leaving directory `/home/rajiv/Downloads/glibc-2.17/elf'
make[1]: *** [elf/subdir_lib] Error 2
make[1]: Leaving directory `/home/rajiv/Downloads/glibc-2.17'
make: *** [all] Error 2
请帮助并让我知道如何编译或构建 GNU glibc 以在非 FPU x86 内核上使用它。基本上我需要用 '-msoft-float' 或 'without-fp' 编译的 libm.a ,这样我就可以静态链接 libm 来创建内核 BIN。
正如你所看到的,我的试验都不起作用:(。我也尝试链接 gcc soft-fp lib,但做不到。