Ayachi Nene
文章3
标签3
分类0
Linux kernel内核编译记录

Linux kernel内核编译记录

linux 内核编译

版本

4.15.0, ubuntu16.04默认内核为4.15.0-38-generic

genheaders.c头文件引用出错

问题描述

1
2
In file included from scripts/selinux/genheaders/genheaders.c:19:
./security/selinux/include/classmap.h:248:2: error: #error New address family defined, please update secclass_map.

解决方法

打开.h文件,添加头文件
#include <linux/socket.h>
打开.c文件,注释#include<sys/socket.h>

pager_preexec参数调用有误

问题描述

1
2
3
pager.c: In function ‘pager_preexec’:
pager.c:36:12: error: passing argument 2 to restrict-qualified parameter aliases with argument 4 [-Werror=restrict]
select(1, &in, NULL, &in, NULL);

解决方法

寻找高版本文件,更新对应函数,这个被定为bug

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
static void pager_preexec(void)
{
/*
* Work around bug in "less" by not starting it until we
* have real input
*/
fd_set in;
fd_set exception;

FD_ZERO(&in);
FD_ZERO(&exception);

FD_SET(0, &in);
FD_SET(0, &exception);

select(1, &in, NULL, &exception, NULL);

setenv("LESS", "FRSX", 0);
}

elf_getshnum重定义

问题描述

1
orc_dump.c:106:9: error: ‘elf_getshnum’ is deprecated [-Werror=deprecated-declarations]

解决方法

又是一个在高版本被修复的bug

https://bugzilla.kernel.org/show_bug.cgi?id=197847

1
2
3
4
5
6
7
8
9
10
11
--- tools/objtool/Makefile    2017-11-11 14:55:08.243236243 +0000
+++ tools/objtool/Makefile.new 2017-11-11 14:56:52.322443760 +0000
@@ -29,7 +29,7 @@
LDFLAGS += -lelf $(LIBSUBCMD)

# Allow old libelf to be used:
- elfshdr := $(shell echo '\#include <libelf.h>' | $(CC) $(CFLAGS) -x c -E - | grep elf_getshdr)
+ elfshdr := $(shell echo '#include <libelf.h>' | $(CC) $(CFLAGS) -x c -E - | grep elf_getshdr)
CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED)

AWK = awk
1
2
3
4
5
6
7
8
9
10
11
12
--- tools/build/Build.include    2017-11-11 14:57:12.862287367 +0000
+++ tools/build/Build.include.new 2017-11-11 14:56:37.232558659 +0000
@@ -62,8 +62,8 @@
$(fixdep) $(depfile) $@ '$(make-cmd)' > $(dot-target).tmp; \
rm -f $(depfile); \
mv -f $(dot-target).tmp $(dot-target).cmd, \
- printf '# cannot find fixdep (%s)\n' $(fixdep) > $(dot-target).cmd; \
- printf '# using basic dep data\n\n' >> $(dot-target).cmd; \
+ printf '\# cannot find fixdep (%s)\n' $(fixdep) > $(dot-target).cmd; \
+ printf '\# using basic dep data\n\n' >> $(dot-target).cmd; \
cat $(depfile) >> $(dot-target).cmd; \
printf '\n%s\n' 'cmd_$@ := $(make-cmd)' >> $(dot-target).cmd)

openssl宏重定义

问题描述

1
scripts/sign-file.c:89:9: warning: ‘ERR_get_error_line’ is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]

解决方法

这个api在openssl3.0已被弃用,但社区懒得支持,在sign-file.c中添加编译器指令忽略重定义问题

1
2
3
4
5
6
/*
* OpenSSL 3.0 deprecates the OpenSSL's ENGINE API.
*
* Remove this if/when that API is no longer used
*/
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"

objtool符号表未命中

问题描述

1
arch/x86/entry/.tmp_thunk_64.o: warning: objtool: missing symbol table

解决方法

更新后这玩意可能会空,因此把错误处理代码替换为return 0

https://www.spinics.net/lists/kernel/msg3797871.html

QEMU启动时提示处理器不支持LA57特性

https://lkml.kernel.org/lkml/20190225195122.930447522@linuxfoundation.org/
4.20的patch修复了这个问题,但是直接按照对应patch更新代码会导致另一个文件编译出错,因此需要下载此patch后更新的4.20.13版本,使用对应的cpuid.c文件进行修改

后续

QEMU始终无法启动4.15内核,最后改为使用22.04使用的5.19内核,编译一遍过
我究竟在研究什么东西…

本文作者:Ayachi Nene
本文链接:https://kahuuchino.github.io/2023/05/08/Linux-kernel-compile/
版权声明:本文采用 CC BY-NC-SA 3.0 CN 协议进行许可
×