簡體   English   中英

本地構建的 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? 我應該做一些不同的事情來讓 GCC “意識到”我的 glibc 頭文件嗎?

默認情況下, limits.h文件未正確配置,因此您需要對其進行修補。

要解決此問題,您必須在 GCC 的源目錄中輸入 go 並鍵入命令:

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。

快速添加到Anthony中,完成調試別忘了在這一步結束時使用:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM