构建 Linux 内核时没有创建目标“scripts/extract-cert”的规则 - Centos 7、devtoolset-9

构建 Linux 内核时没有创建目标“scripts/extract-cert”的规则 - Centos 7、devtoolset-9

我正在尝试调试我的构建环境,以使用一些补丁集编译 Linux 内核。

我在 CentOS 7 环境中安装了 devtoolset-9 以满足 5.15.86 linux 内核分支的最低 gcc 版本要求。当使用 simple 编译内核时make bzImage,出现以下错误:

make[2]: *** No rule to make target `scripts/extract-cert', needed by `certs/x509_certificate_list'.  Stop.

然后我尝试通过 cd'ing 到脚本并运行来制作 extract-cert make extract-cert,但出现以下错误:

    cc     extract-cert.c   -o extract-cert
/opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/ld: /tmp/ccx32b6d.o: in function `display_openssl_errors':
extract-cert.c:(.text+0x3e): undefined reference to `ERR_peek_error'
/opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/ld: extract-cert.c:(.text+0x7f): undefined reference to `ERR_error_string'
/opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/ld: extract-cert.c:(.text+0xc2): undefined reference to `ERR_get_error_line'
/opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/ld: /tmp/ccx32b6d.o: in function `drain_openssl_errors':
extract-cert.c:(.text+0xdd): undefined reference to `ERR_peek_error'
/opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/ld: extract-cert.c:(.text+0xf6): undefined reference to `ERR_get_error_line'
/opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/ld: /tmp/ccx32b6d.o: in function `write_cert':
extract-cert.c:(.text+0x132): undefined reference to `BIO_new_file'
/opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/ld: extract-cert.c:(.text+0x186): undefined reference to `X509_get_subject_name'
/opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/ld: extract-cert.c:(.text+0x1a0): undefined reference to `X509_NAME_oneline'
/opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/ld: extract-cert.c:(.text+0x1b9): undefined reference to `i2d_X509_bio'
/opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/ld: /tmp/ccx32b6d.o: in function `main':
extract-cert.c:(.text+0x230): undefined reference to `OPENSSL_add_all_algorithms_noconf'
/opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/ld: extract-cert.c:(.text+0x235): undefined reference to `ERR_load_crypto_strings'
/opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/ld: extract-cert.c:(.text+0x23a): undefined reference to `ERR_clear_error'
/opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/ld: extract-cert.c:(.text+0x338): undefined reference to `ENGINE_load_builtin_engines'
/opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/ld: extract-cert.c:(.text+0x347): undefined reference to `ENGINE_by_id'
/opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/ld: extract-cert.c:(.text+0x386): undefined reference to `ENGINE_init'
/opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/ld: extract-cert.c:(.text+0x3e2): undefined reference to `ENGINE_ctrl_cmd_string'
/opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/ld: extract-cert.c:(.text+0x437): undefined reference to `ENGINE_ctrl_cmd'
/opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/ld: extract-cert.c:(.text+0x48a): undefined reference to `BIO_new_file'
/opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/ld: extract-cert.c:(.text+0x4df): undefined reference to `PEM_read_bio_X509'
/opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/ld: extract-cert.c:(.text+0x4fb): undefined reference to `ERR_peek_last_error'
/opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/ld: extract-cert.c:(.text+0x522): undefined reference to `ERR_clear_error'
/opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/ld: extract-cert.c:(.text+0x57a): undefined reference to `BIO_free'
collect2: error: ld returned 1 exit status
make: *** [extract-cert] Error 1

我在 OpenSSL 源代码中搜索github并找到链接器抱怨的符号。所以看来这是一个 OpenSSL 错误。我已经安装了 OpenSSL,但我不确定它如何与 devtoolset-9 一起使用。如何让 devtoolset-9 中的链接器找到 OpenSSL 库? pkgconfig 文件对我来说看起来是正确的,并且库存在于 /usr/lib64/ 中

$>gcc --version
gcc (GCC) 9.3.1 20200408 (Red Hat 9.3.1-2) Copyright (C) 2019 Free Software Foundation, Inc. This is free software; see the source for copying conditions.  There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
openssl version
OpenSSL 1.0.2k-fips  26 Jan 2017

$>yum list installed | grep ssl
openssl.x86_64                          1:1.0.2k-26.el7_9        @updates
openssl-devel.x86_64                    1:1.0.2k-26.el7_9        @updates
openssl-libs.x86_64                     1:1.0.2k-26.el7_9        @updates

$>find . -name 'libssl*'
./usr/lib64/pkgconfig/libssl.pc
./usr/lib64/libssl.so.1.0.2k
./usr/lib64/libssl.so.10
./usr/lib64/libssl3.so
./usr/lib64/libssl.so

$>cat ./usr/lib64/pkgconfig/libssl.pc
prefix=/usr
exec_prefix=${prefix}
libdir=${exec_prefix}/lib64
includedir=${prefix}/include

Name: OpenSSL-libssl
Description: Secure Sockets Layer and cryptography libraries
Version: 1.0.2k
Requires: libcrypto
Libs: -L${libdir} -lssl
Libs.private: -ldl -lz -lgssapi_krb5 -lkrb5 -lcom_err -lk5crypto
Cflags: -I${includedir} -I/usr/include

$>cat ./usr/lib64/pkgconfig/libcrypto.pc
prefix=/usr
exec_prefix=${prefix}
libdir=${exec_prefix}/lib64
includedir=${prefix}/include
enginesdir=/usr/lib64/openssl/engines

Name: OpenSSL-libcrypto
Description: OpenSSL cryptography library
Version: 1.0.2k
Requires:
Libs: -L${libdir} -lcrypto
Libs.private: -ldl -lz
Cflags: -I${includedir}

@Ginnungagap:的结果echo | gcc -xc -E -v -是:

$> echo | gcc -xc -E -v -
Using built-in specs.
COLLECT_GCC=gcc
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/opt/rh/devtoolset-9/root/usr --mandir=/opt/rh/devtoolset-9/root/usr/share/man --infodir=/opt/rh/devtoolset-9/root/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --with-default-libstdcxx-abi=gcc4-compatible --enable-plugin --enable-initfini-array --with-isl=/builddir/build/BUILD/gcc-9.3.1-20200408/obj-x86_64-redhat-linux/isl-install --disable-libmpx --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 9.3.1 20200408 (Red Hat 9.3.1-2) (GCC)
COLLECT_GCC_OPTIONS='-E' '-v' '-mtune=generic' '-march=x86-64'
 /opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/cc1 -E -quiet -v - -mtune=generic -march=x86-64
ignoring nonexistent directory "/opt/rh/devtoolset-9/root/usr/lib/gcc/x86_64-redhat-linux/9/include-fixed"
ignoring nonexistent directory "/opt/rh/devtoolset-9/root/usr/lib/gcc/x86_64-redhat-linux/9/../../../../x86_64-redhat-linux/include"
#include "..." search starts here:
#include <...> search starts here:
 /opt/rh/devtoolset-9/root/usr/lib/gcc/x86_64-redhat-linux/9/include
 /usr/local/include
 /opt/rh/devtoolset-9/root/usr/include
 /usr/include
End of search list.
# 1 "<stdin>"
# 1 "<built-in>"
# 1 "<command-line>"
# 31 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 32 "<command-line>" 2
# 1 "<stdin>"
COMPILER_PATH=/opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/:/opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/:/opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/:/opt/rh/devtoolset-9/root/usr/lib/gcc/x86_64-redhat-linux/9/:/opt/rh/devtoolset-9/root/usr/lib/gcc/x86_64-redhat-linux/
LIBRARY_PATH=/opt/rh/devtoolset-9/root/usr/lib/gcc/x86_64-redhat-linux/9/:/opt/rh/devtoolset-9/root/usr/lib/gcc/x86_64-redhat-linux/9/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/opt/rh/devtoolset-9/root/usr/lib/gcc/x86_64-redhat-linux/9/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-E' '-v' '-mtune=generic' '-march=x86-64'

答案1

此问题是由于 script/Makefile 中的 Makefile 损坏造成的。我从旧内核版本中挑选了一个自定义补丁,并且在某些时候新的 kbuild 简写 hostprogs-总是引入了-y。当我挑选旧补丁时,它又改回了 hostprogs-y。这导致 script/* 中的帮助程序无法由 kbuild 构建。

extract-cert 的 Makefile 条目示例:

hostprogs-always-$(CONFIG_SYSTEM_TRUSTED_KEYRING)   += extract-cert

来自拼凑的信息是这里

引用 Masahiro Yamada 的补丁:

要构建主机程序,您需要将程序名称添加到“hostprogs”以使用必要的构建规则,但这还不足以构建它们,因为没有依赖性。

有两种类型的主机程序:作为另一种的先决条件构建(例如 lib/Makefile 中的 gen_crc32table),或者总是在 Kbuild 访问 Makefile 时构建(例如 script/genksyms/Makefile 中的 genksyms)。

后者通常出现在scripts/下的Makefile中,其中包含内核构建期间全局使用的主机程序。要构建它们,您需要将它们添加到“hostprogs”和“always-y”中。

此提交添加了 hostprogs-always-y 作为简写。

答案2

extract-certs 已从 kernel 5.17 中的 script/ 移至 certs/犯罪

我想必须更新 make 目标

相关内容