GCC 4.9.4交叉编译器构建(limits.h问题)

时间:2017-06-07 17:51:20

标签: gcc cross-compiling toolchain

导致问题的基本步骤:

cd linux-2.6.35.9/
make ARCH=x86 INSTALL_HDR_PATH=${PREFIX}/${TARGET} headers_install
cd ../

cd build-binutils/
sh ../binutils-2.28/configure --prefix=${PREFIX} --target=${TARGET}
make
make install
cd ../

cd build-gcc/
sh ../gcc-4.9.4/configure --prefix=${PREFIX} --target=${TARGET} --enable-languages=c,c++ --disable-multilib
make all-gcc
make install-gcc
cd ../

我遇到的问题是最终安装到$ {PREFIX} / lib / gcc / $ {TARGET} /4.9.4/include-fixed/limits.h的内容似乎不会是对的。具体来说," fixincludes"在构建和安装GCC时,需要一些名为" sys-include"的目录。从未实现过,如果没有,上述limits.h不会引用相关的syslimits.h(在同一目录中)。

如果我查看构建/安装序列的输出,那么引用从组件limitx.h,limity.h和其他一些位构建此文件。此测试失败,它只是安装" generic" GCC附带的limits.h(不包括对syslimits.h的引用,它使用GCC的#include_next指令包含$ {PREFIX} / $ {TARGET} /include/limits.h其中的实际内容我需要NAME_MAX和PATH_MAX。

文件中缺少的位是:

/* This administrivia gets added to the beginning of limits.h
   if the system has its own version of limits.h.  */

/* We use _GCC_LIMITS_H_ because we want this not to match
   any macros that the system's limits.h uses for its own purposes.  */
#ifndef _GCC_LIMITS_H_  /* Terminated in limity.h.  */
#define _GCC_LIMITS_H_

#ifndef _LIBC_LIMITS_H_
/* Use "..." so that we find syslimits.h only in this same directory.  */
#include "syslimits.h"
#endif

那么有一个选项我没有传递给GCC的配置脚本,或者我没有在这一步之前传递一些能够正确创建sys-include目录的东西吗?

[编辑]

TARGET=i686-redhat-linux(来自" gcc -dumpmachine&#34的目标三元组;在我们用于项目的构建服务器上)

可能更有用的信息(?):包裹只是" wget"从相应的档案中提取。我正在构建一个最新的Ubuntu 16.04安装,我安装了libgmp-dev和libmpfr-dev,以避免使用编译器源代码编译它们。

1 个答案:

答案 0 :(得分:0)

经过多次挖掘和反复试验后,我将我开始使用How to Build a GCC Cross-Compiler的一些内容与有关配置GCC的明显弃用选项--with-headers的信息进行了匹配。 (--with-headers=${PREFIX}/${TARGET}/include/linux)虽然有效,但是当我构建编译器支持库时,它抱怨缺少bits/stdio_lim.h。我找到了另一篇帖子here来讨论这个问题(你必须稍微介绍一下)并且在我提到的第一页中提到了感人的gnu/stubs.h

从我自己的评论中添加以下内容,注意您必须删除${PREFIX}/${TARGET}/sys-include步骤之后构建的make install-gcc目录,否则您的普通C标头将与特定于Linux内核的文件发生冲突默认情况下包含在搜索路径中的标题。

我只想说,在对我使用的旧版Glibc应用补丁(2.11.3)之后,整个序列最终都是这样的:

export TARGET=i686-redhat-linux
export PREFIX=$(pwd)/output
export PATH=${PATH}:${PREFIX}/bin

mkdir build-binutils
mkdir build-gcc
mkdir build-glibc

cd linux-2.6.35.9/
make ARCH=x86 INSTALL_HDR_PATH=${PREFIX}/${TARGET} headers_install
cd ../

cd build-binutils/
sh ../binutils-2.28/configure --prefix=${PREFIX} --target=${TARGET}
make
make install
cd ../

cd build-gcc/
sh ../gcc-4.9.4/configure --prefix=${PREFIX} --target=${TARGET} --enable-languages=c,c++ --disable-multilib --with-headers=${PREFIX}/${TARGET}/include/linux
make all-gcc
make install-gcc
cd ../
rm --recursive --force ${PREFIX}/${TARGET}/sys-include

cd build-glibc/
sh ../glibc-2.11.3/configure --prefix=${PREFIX}/${TARGET} --build=$(gcc -dumpmachine) --host=${TARGET} --target=${TARGET} --disable-multilib libc_cv_forced_unwind=yes libc_cv_c_cleanup=yes
make install-bootstrap-headers=yes install-headers
make csu/subdir_lib
install csu/crt1.o csu/crti.o csu/crtn.o ${PREFIX}/${TARGET}/lib
${TARGET}-gcc -nostdlib -nostartfiles -shared -x c /dev/null -o ${PREFIX}/${TARGET}/lib/libc.so
touch ${PREFIX}/${TARGET}/include/gnu/stubs.h ${PREFIX}/${TARGET}/include/bits/stdio_lim.h
cd ../

cd build-gcc/
make all-target-libgcc
make install-target-libgcc
cd ../

cd build-glibc/
make
make install
cd ../

我没有看到任何页面实际上达到这个深度(也许Preshing on Programming页面实际上并不完全正确?)但是我将测试这个配置并确保软件完全为目标构建问题。 (我在一个文件中测试了来自limits.h的NAME_MAX,它看起来效果很好而且花花公子。)

我也不知道我需要放入--disable-multilib这个东西,但这似乎是其他网页正在做的事情。 GCC邮件列表中的链接说明了使用--with-newlib--disable-shared作为选项,但线程上的人不能同意这些是正确的解决方案。

如果有人对此有更深入的了解,我肯定会感谢这个问题的不那么苛刻,更官方的解决方案。

如果有人想知道,修复Glibc 2.11.3的补丁(有两个)是配置脚本与GNU Make 4 +一起使用的一个自定义修复:

sed -i 's/\(3.79\)/4.* | \1/' glibc-2.11.3/configure

...以及库中两个文件的实际补丁来修复i686支持:

patch glibc-2.11.3/nptl/sysdeps/pthread/pt-initfini.c <<__EOF__
@@ -45,6 +45,11 @@
 /* Embed an #include to pull in the alignment and .end directives. */
 asm ("\n#include \"defs.h\"");

+asm ("\n#if defined __i686 && defined __ASSEMBLER__");
+asm ("\n#undef __i686");
+asm ("\n#define __i686 __i686");
+asm ("\n#endif");
+
 /* The initial common code ends here. */
 asm ("\n/*@HEADER_ENDS*/");

__EOF__
patch glibc-2.11.3/sysdeps/unix/sysv/linux/i386/sysdep.h <<__EOF__
@@ -29,6 +29,10 @@
 #include <dl-sysdep.h>
 #include <tls.h>

+#if defined __i686 && defined __ASSEMBLER__
+#undef __i686
+#define __i686 __i686
+#endif

 /* For Linux we can use the system call table in the header file
        /usr/include/asm/unistd.h
__EOF__

我从here获得了最后一个补丁。