本地构建的 GCC 交叉编译器报告 MB_LEN_MAX 错误 -D_FORTIFY_SOURCE=2

Locally built GCC cross-compiler reports MB_LEN_MAX wrong with -D_FORTIFY_SOURCE=2

我目前正在构建一个针对 PowerPC 架构的交叉编译器。它能够构建 Linux 个可以在目标上运行并执行的二进制文件,但是当我启用编译器标志“-D_FORTIFY_SOURCE=2”时我遇到了问题。我这样构建一个简单的 hello world 应用程序:

#include <limits.h>
#include <stdlib.h>

int main(int argc, char* argv[])
{
  return 0;
}

我使用我的交叉编译器编译它并得到以下错误:

$ powerpc-linux-gnu-gcc -D_FORTIFY_SOURCE=2 -O2 hello.c
In file included from /opt/crossgcc/powerpc-linux-gnu/include/stdlib.h:958:0,
                 from hello.c:2:
/opt/crossgcc/powerpc-linux-gnu/include/bits/stdlib.h: In function 'wctomb':
/opt/crossgcc/powerpc-linux-gnu/include/bits/stdlib.h:90:3: error: #error "Assumed value of MB_LEN_MAX wrong"
 # error "Assumed value of MB_LEN_MAX wrong"
   ^

我相信这是因为我没有正确引导我的 GCC 构建,但据我所知,我正在正确构建它。我用来构建编译器的脚本如下:

#! /bin/bash
set -e
INSTALL_PATH=$PWD/output
TARGET=powerpc-linux-gnu
LINUX_ARCH=powerpc
PARALLEL_MAKE=-j4
BINUTILS_VERSION=binutils-2.32
GCC_VERSION=gcc-8.3.0
LINUX_KERNEL_VERSION=linux-5.1.9
GLIBC_VERSION=glibc-2.29
export PATH=$INSTALL_PATH/bin:$PATH

cd $GCC_VERSION
./contrib/download_prerequisites
cd ..

mkdir -p build-binutils
cd build-binutils
../$BINUTILS_VERSION/configure --prefix=$INSTALL_PATH --target=$TARGET
make $PARALLEL_MAKE
make install
cd ..

cd $LINUX_KERNEL_VERSION
make ARCH=$LINUX_ARCH INSTALL_HDR_PATH=$INSTALL_PATH/$TARGET headers_install
cd ..

# Build GCC compiler
mkdir -p build-gcc
cd build-gcc
../$GCC_VERSION/configure \
  --prefix=$INSTALL_PATH \
  --target=$TARGET \
  --disable-silent-rules \
  --with-gnu-as --with-gnu-ld \
  --enable-languages="c,c++" \
  --enable-theads=posix \
  --enable-c99 \
  --enable-long-long \
  --enable-lto \
  --enable-libssp \
  --enable-secureplt \
  --disable-libmudflag \
  --enable-secureplt \
  --disable-nls \
  --with-long-double-128
make $PARALLEL_MAKE all-gcc
make install-gcc
cd ..

mkdir -p build-glibc
cd build-glibc
../$GLIBC_VERSION/configure \
  --prefix=$INSTALL_PATH/$TARGET \
  --build=$(gcc -dumpmachine) \
  --host=$TARGET \
  --target=$TARGET \
  --with-headers=$INSTALL_PATH/$TARGET/include \
  libc_cv_forced_unwind=yes
make install-bootstrap-headers=yes install-headers
make $PARALLEL_MAKE csu/subdir_lib
install csu/crt1.o csu/crti.o csu/crtn.o $INSTALL_PATH/$TARGET/lib
$TARGET-gcc -nostdlib -nostartfiles -shared -x c /dev/null -o $INSTALL_PATH/$TARGET/lib/libc.so
touch $INSTALL_PATH/$TARGET/include/gnu/stubs.h
cd ..

cd build-gcc
make $PARALLEL_MAKE all-target-libgcc
make install-target-libgcc
cd ..

cd build-glibc
make $PARALLEL_MAKE
make install
cd ..

cd build-gcc
make $PARALLEL_MAKE all
make install
cd ..

我是否错误地引导了我的 GCC?我是否应该做一些不同的事情来制作我的 glibc 头文件的 GCC "aware"?

默认情况下 limits.h 文件配置不正确,因此您需要对其进行修补。

要解决此问题,您必须进入 GCC 的源目录并键入命令:

cd $GCC_VERSION
cat gcc/limitx.h gcc/glimits.h gcc/limity.h > \
`dirname $(${TARGET}-gcc -print-libgcc-file-name)`/include-fixed/limits.h

这会在底部添加一个 #include_next <limits.h>,最终选择右边的 header。

快速添加到, to complete the debugging do not forget at the end of this step使用:

$LFS/tools/libexec/gcc/$LFS_TGT/10.2.0/install-tools/mkheaders