我正在尝试在x86_64上编译glibc(作为次要的,不是系统的替代品)2.6,并试图使其生成32位对象。当我给它一个标准配置时,它可以很好地编译,生成通常的64位库对象。一些信息:
$ uname -a Linux localhost.localdomain 2.6.18-164.11.1.el5 #1 SMP Wed Jan 20 07:32:21 \ EST 2010 x86_64 x86_64 x86_64 GNU/Linux $ cat /etc/redhat-release CentOS release 5.4 (Final)
$ uname -a Linux localhost.localdomain 2.6.18-164.11.1.el5 #1 SMP Wed Jan 20
07:32:21 \ EST 2010 x86_64 x86_64 x86_64 GNU/Linux
$ cat /etc/redhat-release CentOS release 5.4 (Final)
除其他外,我尝试了以下方法:
尝试1:
$ # [in build/glibc-2.6] $ ../../src/glibc-2.6/configure --prefix=$HOME/glibc32-2.6 \ --with-cpu=i386-pc-linux-gnu ... checking sysdep dirs... configure: error: The i386-pc-linux-gnu subspecies of x86_64 is not supported."
尝试2:
$ ../../src/glibc-2.6/configure --prefix=$HOME/glibc32-2.6 \ --host=i386-pc-linux-gnu ... $ make
配置成功,但是make会导致一系列编译错误,如下所示:
make
nptl/sysdeps/i386/tls.h:65:3: error: #error "TLS support is required." In file included from include/tls.h:6, from sysdeps/unix/sysv/linux/i386/sysdep.h:30, from <stdin>:1:
如果添加–with-tls和/或–target = i386-pc-linux-gnu,我会得到相同的结果。
[编辑:看来我对–build的–target感到困惑。我尝试添加–build = i386-pc-linux-gnu,也尝试添加其他所有尝试使用– target的尝试。在所有情况下,我得到的结果都与以前完全一样。]
尝试3:
$ CFLAGS=-m32 \ ../../src/glibc-2.6/configure --prefix=$HOME/glibc32-2.6 \ --host=i386-pc-linux-gnu \ ... In file included from ./../include/libc-symbols.h:55, from <command line>:1: /home/USER/build/glibc32-2.6/config.h:3:3: error: #error "glibc cannot be \ compiled without optimization”
$ CFLAGS=-m32 \ ../../src/glibc-2.6/configure --prefix=$HOME/glibc32-2.6 \ --host=i386-pc-linux-gnu \ ... In file included from ./../include/libc-symbols.h:55, from <command line>:1: /home/USER/build/glibc32-2.6/config.h:3:3: error: #error "glibc cannot
be \ compiled without optimization”
同样,–with-tls也会发生相同的情况
尝试4:
$ CFLAGS="-m32 -O2" \ ../../src/glibc-2.6/configure --prefix=$HOME/glibc32-2.6 \ --host=i386-pc-linux-gnu \ ... gcc ../sysdeps/unix/sysv/linux/i386/sysdep.S -c -I../include \ -I/home/USER/build/glibc32-2.6/csu \ -I/home/USER/build/glibc32-2.6 -I../sysdeps/i386/elf \ -I../nptl/sysdeps/unix/sysv/linux/i386 \ -I../sysdeps/unix/sysv/linux/i386 \ -I../nptl/sysdeps/unix/sysv/linux \ -I../nptl/sysdeps/pthread -I../sysdeps/pthread \ -I../sysdeps/unix/sysv/linux -I../sysdeps/gnu \ -I../sysdeps/unix/common -I../sysdeps/unix/mman \ -I../sysdeps/unix/inet -I../sysdeps/unix/sysv/i386 \ -I../nptl/sysdeps/unix/sysv -I../sysdeps/unix/sysv \ -I../sysdeps/unix/i386 -I../nptl/sysdeps/unix \ -I../sysdeps/unix -I../sysdeps/posix \ -I../sysdeps/i386/fpu -I../nptl/sysdeps/i386 \ -I../sysdeps/i386 -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/elf -I../sysdeps/generic \ -I../nptl -I.. -I../libio -I. \ -D_LIBC_REENTRANT -include ../include/libc-symbols.h \ -DHAVE_INITFINI -DASSEMBLER \ -I/home/USER/build/glibc32-2.6/csu/. -DGAS_SYNTAX \ -Wa,--noexecstack \ -o /home/USER/build/glibc32-2.6/csu/sysdep.o \ -MD -MP \ -MF /home/USER/build/glibc32-2.6/csu/sysdep.o.dt \ -MT /home/USER/build/glibc32-2.6/csu/sysdep.o ../sysdeps/unix/i386/sysdep.S: Assembler messages: ../sysdeps/unix/i386/sysdep.S:51: Error: @NTPOFF reloc is not supported \ with 64-bit output format ../sysdeps/unix/i386/sysdep.S:51: Error: junk `@NTPOFF’ after expression
$ CFLAGS="-m32 -O2" \ ../../src/glibc-2.6/configure --prefix=$HOME/glibc32-2.6 \ --host=i386-pc-linux-gnu \ ... gcc ../sysdeps/unix/sysv/linux/i386/sysdep.S -c -I../include \ -I/home/USER/build/glibc32-2.6/csu \ -I/home/USER/build/glibc32-2.6 -I../sysdeps/i386/elf \ -I../nptl/sysdeps/unix/sysv/linux/i386 \ -I../sysdeps/unix/sysv/linux/i386 \ -I../nptl/sysdeps/unix/sysv/linux \ -I../nptl/sysdeps/pthread -I../sysdeps/pthread \ -I../sysdeps/unix/sysv/linux -I../sysdeps/gnu \ -I../sysdeps/unix/common -I../sysdeps/unix/mman \ -I../sysdeps/unix/inet -I../sysdeps/unix/sysv/i386 \ -I../nptl/sysdeps/unix/sysv -I../sysdeps/unix/sysv \ -I../sysdeps/unix/i386 -I../nptl/sysdeps/unix \ -I../sysdeps/unix -I../sysdeps/posix \ -I../sysdeps/i386/fpu -I../nptl/sysdeps/i386 \ -I../sysdeps/i386 -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/elf -I../sysdeps/generic \ -I../nptl -I.. -I../libio -I. \ -D_LIBC_REENTRANT -include ../include/libc-symbols.h \ -DHAVE_INITFINI -DASSEMBLER \ -I/home/USER/build/glibc32-2.6/csu/. -DGAS_SYNTAX \ -Wa,--noexecstack \ -o /home/USER/build/glibc32-2.6/csu/sysdep.o \ -MD -MP \ -MF /home/USER/build/glibc32-2.6/csu/sysdep.o.dt \ -MT /home/USER/build/glibc32-2.6/csu/sysdep.o ../sysdeps/unix/i386/sysdep.S: Assembler messages: ../sysdeps/unix/i386/sysdep.S:51: Error: @NTPOFF reloc is not supported
\ with 64-bit output format ../sysdeps/unix/i386/sysdep.S:51: Error: junk `@NTPOFF’ after expression
我觉得这样应该更容易。我想念什么吗?
如果您需要更多信息,请告诉我,我会提供。
[编辑]
尝试5(由EmployedRussian建议)
$ ../../src/glibc-2.6/configure --prefix=$HOME/glibc32-2.6 \ CC="gcc -m32" CXX="g++ -m32" i686-linux-gnu ... gcc -m32 -nostdlib -nostartfiles -shared \ -o /home/USER/build/glibc32-2.6/elf/ld.so -Wl,-z,combreloc -Wl,-z,relro -Wl,--hash-style=both -Wl,-z,defs /home/USER/build/glibc32-2.6/elf/librtld.os \ -Wl,--version-script=/home/USER/build/glibc32-2.6/ld.map \ -Wl,-soname=ld-linux.so.2 \ -T /home/USER/build/glibc32-2.6/elf/ld.so.lds /home/USER/build/glibc32-2.6/elf/librtld.os: In function add_dependency': /home/USER/src/glibc-2.6/elf/dl-lookup.c:106: undefined reference to__sync_fetch_and_add_4’ /home/USER/src/glibc-2.6/elf/dl-lookup.c:110: undefined reference to __sync_val_compare_and_swap_4' /home/USER/build/glibc32-2.6/elf/librtld.os: In function_dl_profile_fixup’: /home/USER/src/glibc-2.6/elf/dl-runtime.c:196: undefined reference to __sync_val_compare_and_swap_4' /home/USER/src/glibc-2.6/elf/dl-runtime.c:205: undefined reference to__sync_fetch_and_add_4’ /home/USER/build/glibc32-2.6/elf/librtld.os: In function _dl_fixup': /home/USER/src/glibc-2.6/elf/dl-runtime.c:102: undefined reference to__sync_val_compare_and_swap_4’ /home/USER/src/glibc-2.6/elf/dl-runtime.c:110: undefined reference to __sync_fetch_and_add_4' /home/USER/build/glibc32-2.6/elf/librtld.os: In functiondl_open_worker’: /home/USER/src/glibc-2.6/elf/dl-open.c:425: undefined reference to __sync_val_compare_and_swap_4' /home/USER/src/glibc-2.6/elf/dl-open.c:427: undefined reference to__sync_fetch_and_add_4’ /home/USER/build/glibc32-2.6/elf/librtld.os: In function _dl_close_worker': /home/USER/src/glibc-2.6/elf/dl-close.c:407: undefined reference to__sync_val_compare_and_swap_4’ /home/USER/src/glibc-2.6/elf/dl-close.c:409: undefined reference to __sync_fetch_and_add_4' collect2: ld returned 1 exit status make[2]: *** [/home/USER/build/glibc32-2.6/elf/ld.so] Error 1 make[2]: Leaving directory/home/USER/src/glibc-2.6/elf’ make[1]: [elf/subdir_lib] Error 2 make[1]: Leaving directory `/home/USER/src/glibc-2.6’ make: [all] Error 2
$ ../../src/glibc-2.6/configure --prefix=$HOME/glibc32-2.6 \ CC="gcc -m32" CXX="g++ -m32" i686-linux-gnu ... gcc -m32 -nostdlib -nostartfiles -shared \ -o /home/USER/build/glibc32-2.6/elf/ld.so -Wl,-z,combreloc -Wl,-z,relro -Wl,--hash-style=both -Wl,-z,defs /home/USER/build/glibc32-2.6/elf/librtld.os \ -Wl,--version-script=/home/USER/build/glibc32-2.6/ld.map \ -Wl,-soname=ld-linux.so.2 \ -T /home/USER/build/glibc32-2.6/elf/ld.so.lds /home/USER/build/glibc32-2.6/elf/librtld.os: In function
add_dependency': /home/USER/src/glibc-2.6/elf/dl-lookup.c:106: undefined reference to__sync_fetch_and_add_4’ /home/USER/src/glibc-2.6/elf/dl-lookup.c:110: undefined reference to __sync_val_compare_and_swap_4' /home/USER/build/glibc32-2.6/elf/librtld.os: In function_dl_profile_fixup’: /home/USER/src/glibc-2.6/elf/dl-runtime.c:196: undefined reference to __sync_val_compare_and_swap_4' /home/USER/src/glibc-2.6/elf/dl-runtime.c:205: undefined reference to__sync_fetch_and_add_4’ /home/USER/build/glibc32-2.6/elf/librtld.os: In function _dl_fixup': /home/USER/src/glibc-2.6/elf/dl-runtime.c:102: undefined reference to__sync_val_compare_and_swap_4’ /home/USER/src/glibc-2.6/elf/dl-runtime.c:110: undefined reference to __sync_fetch_and_add_4' /home/USER/build/glibc32-2.6/elf/librtld.os: In functiondl_open_worker’: /home/USER/src/glibc-2.6/elf/dl-open.c:425: undefined reference to __sync_val_compare_and_swap_4' /home/USER/src/glibc-2.6/elf/dl-open.c:427: undefined reference to__sync_fetch_and_add_4’ /home/USER/build/glibc32-2.6/elf/librtld.os: In function _dl_close_worker': /home/USER/src/glibc-2.6/elf/dl-close.c:407: undefined reference to__sync_val_compare_and_swap_4’ /home/USER/src/glibc-2.6/elf/dl-close.c:409: undefined reference to __sync_fetch_and_add_4' collect2: ld returned 1 exit status make[2]: *** [/home/USER/build/glibc32-2.6/elf/ld.so] Error 1 make[2]: Leaving directory/home/USER/src/glibc-2.6/elf’ make[1]: [elf/subdir_lib] Error 2 make[1]: Leaving directory `/home/USER/src/glibc-2.6’ make: [all] Error 2
add_dependency': /home/USER/src/glibc-2.6/elf/dl-lookup.c:106: undefined reference to
__sync_val_compare_and_swap_4' /home/USER/build/glibc32-2.6/elf/librtld.os: In function
__sync_val_compare_and_swap_4' /home/USER/src/glibc-2.6/elf/dl-runtime.c:205: undefined reference to
_dl_fixup': /home/USER/src/glibc-2.6/elf/dl-runtime.c:102: undefined reference to
__sync_fetch_and_add_4' /home/USER/build/glibc32-2.6/elf/librtld.os: In function
__sync_val_compare_and_swap_4' /home/USER/src/glibc-2.6/elf/dl-open.c:427: undefined reference to
_dl_close_worker': /home/USER/src/glibc-2.6/elf/dl-close.c:407: undefined reference to
__sync_fetch_and_add_4' collect2: ld returned 1 exit status make[2]: *** [/home/USER/build/glibc32-2.6/elf/ld.so] Error 1 make[2]: Leaving directory
这次,构建成功运行了很长时间,直到遇到错误。我进行了搜索,发现有一些提示表明我添加了“ -march”标志。最终成功了:
尝试6:
$ ../../src/glibc-2.6/configure --prefix=$HOME/glibc32-2.6 \ CC="gcc -m32" CXX="g++ -m32" \ CFLAGS="-O2 -march=i686" \ CXXFLAGS="-O2 -march=i686" \ i686-linux-gnu
谢谢大家!
我编辑了问题,但后来我意识到正确的方法是添加答案。这是最终有效的方法:
$ ../../src/glibc-2.6/configure --prefix=$HOME/glibc32-2.6 \ --host=i686-linux-gnu \ --build=i686-linux-gnu \ CC="gcc -m32" CXX="g++ -m32" \ CFLAGS="-O2 -march=i686" \ CXXFLAGS="-O2 -march=i686"
我认为放入-m32CC和CXX而不是CFLAGS和CXXFLAGS很重要,因为在制作过程中至少有一个不使用CFLAGS或CXXFLAGS的编译操作,而且-m32绝对必须始终存在。不知道为什么-march=i686有必要(考虑到-m32零件和--host/build选项),但确实如此。
-m32
-march=i686
--host/build