构建旧 Linux 内核时出现的 GCC 问题

构建旧 Linux 内核时出现的 GCC 问题

我正在尝试从为 ARM 编译的 Linux 内核源代码版本 2.6.37 开始构建。我需要这样做的原因与工作有关;我需要那个特定的版本。我可以毫无问题地为 ARM 构建最新版本的 Linux 内核。这是我的设置:

  • 主机运行的是 macOS 10.15.6
  • 在 VirtualBox 6.1.14 上运行 Ubuntu 20.04.1
  • 下载这个内核压缩包
  • sudo apt-get install build-essential binutils-multiarch gcc-arm-linux-gnueabi
  • make distclean
  • make ARCH=arm defconfig
  • ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- make all

这个精确的过程对于最新版本的内核来说运行良好,但对于这个旧版本,它会产生以下输出:

scripts/kconfig/conf --silentoldconfig Kconfig
  CHK     include/linux/version.h
  UPD     include/linux/version.h
  CHK     include/generated/utsrelease.h
  UPD     include/generated/utsrelease.h
  Generating include/generated/mach-types.h
  CC      kernel/bounds.s
In file included from include/linux/compiler.h:48,
                 from include/linux/stddef.h:4,
                 from include/linux/posix_types.h:4,
                 from include/linux/types.h:17,
                 from include/linux/page-flags.h:8,
                 from kernel/bounds.c:9:
include/linux/compiler-gcc.h:90:1: fatal error: linux/compiler-gcc9.h: No such file or directory
   90 | #include gcc_header(__GNUC__)
      | ^~~~
compilation terminated.
make[1]: *** [/home/nick/Documents/linux-2.6.37/./Kbuild:36: kernel/bounds.s] Error 1
make: *** [Makefile:954: prepare0] Error 2

进一步调查后,我发现该include/linux文件夹包含compiler-gcc3.h和的标头compiler-gcc4.h,但不包含 GCC9(这并不奇怪)。所以我的理解是,我需要一个比 GCC-9 更旧的 GCC 版本。接下来我:

  • 附有/etc/apt/sources.list以下内容:
deb [trusted=yes] http://snapshot.debian.org/archive/debian/20070730T000000Z/ lenny main
deb-src [trusted=yes] http://snapshot.debian.org/archive/debian/20070730T000000Z/ lenny main
deb [trusted=yes] http://snapshot.debian.org/archive/debian-security/20070730T000000Z/ lenny/updates main
deb-src [trusted=yes] http://snapshot.debian.org/archive/debian-security/20070730T000000Z/ lenny/updates main
  • sudo apt-get update --allow-unauthenticated

  • sudo apt-get install g++-3.4

  • sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-3.4 1

据我所知,这已成功安装 GCC-3.4。致电gcc -v确认了这一点。

update-alternatives编辑:我现在不再调用,而是修改了我的 MakeFile,如下所示:

HOSTCC       = gcc-3.4
HOSTCXX      = g++-3.4
CC      = $(CROSS_COMPILE)gcc-3.4

我在每一行都添加了“-3.4”。我知道这是一种更好的方法,但我仍然遇到同样的问题:

但是,当我调用时,我现在看到以下输出make ARCH=arm defconfig

  HOSTCC  scripts/basic/fixdep
/usr/bin/ld: cannot find crt1.o: No such file or directory
/usr/bin/ld: cannot find crti.o: No such file or directory
/usr/bin/ld: cannot find -lgcc_s
collect2: ld returned 1 exit status
make[1]: *** [scripts/Makefile.host:118: scripts/basic/fixdep] Error 1
make: *** [Makefile:397: scripts_basic] Error 2

我不知道发生了什么。如能得到任何帮助或指导,我将不胜感激。

答案1

根据要求,这是我在 Ubuntu Intel 主机上进行 ARM Web 服务器开发时使用的脚本。

MY_ARM_BASE=${HOME}/dev/toolchain/arm-2008q3
C_INCLUDE_PATH=${MY_ARM_BASE}/lib/gcc/arm-none-linux-gnueabi/4.3.2/include:${MY_ARM_BASE}/lib/gcc/arm-none-linux-gnueabi/4.3.2/include-fixed
LIBRARY_PATH=${MY_ARM_BASE}/arm-none-linux-gnueabi/libc/lib:${MY_ARM_BASE}/arm-none-linux-gnueabi/libc/usr/lib
CPLUS_INCLUDE_PATH=${MY_ARM_BASE}/arm-none-linux-gnueabi/include/c++/4.3.2
#OBJC_INCLUDE_PATH
COMPILER_PATH=${MY_ARM_BASE}/bin
#LD_RUN_PATH
#GPROF_PATH
#######
CC=${COMPILER_PATH}/gcc
CXX=${COMPILER_PATH}/g++
RANLIB=${COMPILER_PATH}/ranlib
STRIP=${COMPILER_PATH}/strip
export C_INCLUDE_PATH LIBRARY_PATH CPLUS_INCLUDE_PATH COMPILER_PATH
export CC CXX RANLIB STRIP

另一个脚本看起来像是用于运行 Web 浏览器的配置脚本:

GCC=${COMPILER_PATH}/gcc RANLIB=${COMPILER_PATH}/ranlib \
STRIP=${COMPILER_PATH}/strip ./configure --build=arm-linux \
--disable-static --enable-shared --prefix=/mnt/usb/lighty

这是 ARM 代码的实际 bin,我可能自己添加了简称的链接,这么多年过去了,我记不清了。

GCC=${COMPILER_PATH}/gcc RANLIB=${COMPILER_PATH}/ranlib
STRIP=${COMPILER_PATH}/strip ./configure --build=arm-linux
--disable-static --enable-shared --prefix=/mnt/usb/lighty

ls $HOME/dev/toolchain/arm-2008q3/bin
addr2line                         arm-none-linux-gnueabi-cpp        arm-none-linux-gnueabi-gprof    arm-none-linux-gnueabi-size     cpp        gprof    size
ar                                arm-none-linux-gnueabi-g++        arm-none-linux-gnueabi-ld       arm-none-linux-gnueabi-sprite   g++        ld       sprite
arm-none-linux-gnueabi-addr2line  arm-none-linux-gnueabi-gcc        arm-none-linux-gnueabi-nm       arm-none-linux-gnueabi-strings  gcc        nm       strings
arm-none-linux-gnueabi-ar         arm-none-linux-gnueabi-gcc-4.3.2  arm-none-linux-gnueabi-objcopy  arm-none-linux-gnueabi-strip    gcc-4.3.2  objcopy  strip
arm-none-linux-gnueabi-as         arm-none-linux-gnueabi-gcov       arm-none-linux-gnueabi-objdump  as                              gcov       objdump
arm-none-linux-gnueabi-c++        arm-none-linux-gnueabi-gdb        arm-none-linux-gnueabi-ranlib   c++                             gdb        ranlib
arm-none-linux-gnueabi-c++filt    arm-none-linux-gnueabi-gdbtui     arm-none-linux-gnueabi-readelf  c++filt                         gdbtui     readelf

相关内容