【发布时间】:2025-12-23 15:45:06
【问题描述】:
我目前正在构建一个针对 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?我应该做一些不同的事情来让 GCC “意识到”我的 glibc 标头吗?
【问题讨论】: