linux-stable-sw-v4.19.180-sw64-2203.tar.gz 编译错误排查方法

出现:

bash 复制代码
  AR      arch/sw_64/chip/chip3/built-in.a
  AR      arch/sw_64/chip/built-in.a
  CC      kernel/futex.o
{standard input}: Assembler messages:
{standard input}:8070: ???  lstw and rd_f the first register  must be the same
{standard input}:8453: ???  lstw and rd_f the first register  must be the same
{standard input}:8629: ???  lstw and rd_f the first register  must be the same
{standard input}:8665: ???  lstw and rd_f the first register  must be the same
{standard input}:8693: ???  lstw and rd_f the first register  must be the same
make[1]: *** [scripts/Makefile.build:304?kernel/futex.o] ?? 1

这个看不懂原因,大概是两个指令的寄存器必须一致吧,而这个指令在哪呢?

打开make的调试日志

bash 复制代码
make  ARCH=sw_64 CROSS_COMPILE=sw_64-sunway-linux-gnu- V=1 >x.txt

查看最后输出的命令

sw_64-sunway-linux-gnu-gcc -Wp,-MD,kernel/.futex.o.d -nostdinc -isystem /opt/swgcc/usr/bin/../lib/gcc/sw_64-sunway-linux-gnu/10.3.0/include -I./arch/sw_64/include -I./arch/sw_64/include/generated -I./include -I./arch/sw_64/include/uapi -I./arch/sw_64/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/kconfig.h -include ./include/linux/compiler_types.h -D__KERNEL__ -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -fshort-wchar -Werror-implicit-function-declaration -Werror=return-type -Wno-format-security -std=gnu89 -fno-PIE -pipe -ffixed-8 -mno-fp-regs -fno-jump-tables -fno-delete-null-pointer-checks -Wno-frame-address -Wno-format-truncation -Wno-format-overflow -Wno-int-in-bool-context -Wno-address-of-packed-member -O2 -fno-allow-store-data-races -Wframe-larger-than=2048 -fno-stack-protector -Wno-unused-but-set-variable -Wno-unused-const-variable -fno-omit-frame-pointer -fno-optimize-sibling-calls -fno-var-tracking-assignments -Wdeclaration-after-statement -Wno-pointer-sign -Wno-stringop-truncation -Wno-zero-length-bounds -Wno-array-bounds -Wno-stringop-overflow -Wno-restrict -Wno-maybe-uninitialized -fno-strict-overflow -fno-merge-all-constants -fmerge-constants -fno-stack-check -fconserve-stack -Werror=implicit-int -Werror=strict-prototypes -Werror=date-time -Werror=incompatible-pointer-types -Werror=designated-init -fmacro-prefix-map=./= -Wno-packed-not-aligned -DKBUILD_BASENAME='"futex"' -DKBUILD_MODNAME='"futex"' -c -o kernel/.tmp_futex.o kernel/futex.c

将这个命令改成编译出汇编

sw_64-sunway-linux-gnu-gcc -Wp,-MD,kernel/.futex.o.d -nostdinc -isystem /opt/swgcc/usr/bin/../lib/gcc/sw_64-sunway-linux-gnu/10.3.0/include -I./arch/sw_64/include -I./arch/sw_64/include/generated -I./include -I./arch/sw_64/include/uapi -I./arch/sw_64/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/kconfig.h -include ./include/linux/compiler_types.h -D__KERNEL__ -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -fshort-wchar -Werror-implicit-function-declaration -Werror=return-type -Wno-format-security -std=gnu89 -fno-PIE -pipe -ffixed-8 -mno-fp-regs -fno-jump-tables -fno-delete-null-pointer-checks -Wno-frame-address -Wno-format-truncation -Wno-format-overflow -Wno-int-in-bool-context -Wno-address-of-packed-member -O2 -fno-allow-store-data-races -Wframe-larger-than=2048 -fno-stack-protector -Wno-unused-but-set-variable -Wno-unused-const-variable -fno-omit-frame-pointer -fno-optimize-sibling-calls -fno-var-tracking-assignments -Wdeclaration-after-statement -Wno-pointer-sign -Wno-stringop-truncation -Wno-zero-length-bounds -Wno-array-bounds -Wno-stringop-overflow -Wno-restrict -Wno-maybe-uninitialized -fno-strict-overflow -fno-merge-all-constants -fmerge-constants -fno-stack-check -fconserve-stack -Werror=implicit-int -Werror=strict-prototypes -Werror=date-time -Werror=incompatible-pointer-types -Werror=designated-init -fmacro-prefix-map=./= -Wno-packed-not-aligned -DKBUILD_BASENAME='"futex"' -DKBUILD_MODNAME='"futex"' -c -o kernel/.tmp_futex.S -S kernel/futex.c

查看汇编的8070行

代码来自 futex.h,仔细对照能找到对应的函数

下面我们从linux-stable-sw-v5.10.229-sw1.3.0.tar.gz 这个代码中找对应的函数,因为linux-stable-sw-v5.10.229-sw1.3.0.tar.gz是可以编译通过的

cpp 复制代码
#define __futex_atomic_op(insn, ret, oldval, uaddr, oparg, tmp)	\
	__asm__ __volatile__(					\
	"1:	lldw	%0, 0(%3)\n"				\
	"	ldi	%2, 1\n"				\
	"	wr_f	%2\n"					\
		insn						\
	"2:	lstw	%1, 0(%3)\n"				\
	"	rd_f	%1\n"					\
	"	beq	%1, 4f\n"				\
	"	bis	$31, $31, %1\n"				\
	"3:	.subsection 2\n"				\
	"4:	br	1b\n"					\
	"	.previous\n"					\
	"	.section __ex_table, \"a\"\n"			\
	"	.long	1b-.\n"					\
	"	ldi	$31, 3b-1b(%1)\n"			\
	"	.long	2b-.\n"					\
	"	ldi	$31, 3b-2b(%1)\n"			\
	"	.previous\n"					\
	:	"=&r" (oldval), "=&r"(ret), "=&r"(tmp)		\
	:	"r" (uaddr), "r"(oparg)				\
	:	"memory")

果然不一样了,然后将这个代码修改过去即可

/////

qemu执行内核的代码

bash 复制代码
#!/bin/bash

bin/qemu-system-sw64 \
 -M core3 \
 -cpu core3 \
 -m 4G \
 -smp 1\
 -name vm001 \
 -kernel ./vmlinux \
 -drive file=./busybox.qcow2,if=virtio \
 -append "root=/dev/vda rw console=ttyS0 ignore_loglevel notc init=/init" \
 -d int,guest_errors -D a.log \
 -device VGA \
 -serial stdio \
 -monitor telnet:localhost:7100,server,nowait,nodelay \
 -s

内核编译时注意dtb要采用内嵌的,名字是chip_vt

相关推荐
化雨成烟2 分钟前
linux基础命令2
linux·运维·服务器
运维踩坑日记3 分钟前
OpenStack 核心服务实战笔记
linux·运维·服务器·笔记·openstack
erzong23116 分钟前
Linux操作系统:线程池&踩坑修复
linux·运维·算法
AI你一生一世19 分钟前
当“版权主张”不再需要人类:从 Luanti 被下架看自动化维权的工程化风险
运维·人工智能·自动化·开源软件·内容分发·自动化维权·版权主张
ESDWAN20 分钟前
企业访问海外系统很慢,如何一步步定位问题?
服务器·网络·php
云计算练习生27 分钟前
什么是 Bash?Linux 默认 Shell 的核心功能
linux·操作系统·bash·shell·命令解释器
服务器硬件项目经理1 小时前
《超节点修仙录》· 第一卷·炼气期【第02话】 超节点的「身体构造」——CPU、GPU、内存、网卡都是干啥的
服务器·嵌入式硬件·gru·硬件工程·硬件
FlightYe1 小时前
音视频修炼之容器与协议(二):HLS和DASH流媒体
android·linux·ffmpeg·音视频·android runtime·dash
承渊政道1 小时前
Linux网络学习【从深入理解网络层原理到IP分片与重组全过程剖析】
linux·计算机网络·ubuntu·ip分片与重组
橘色的喵1 小时前
嵌入式Linux编程,如何把硬件中断交给用户态--UIO 的机制
linux·mcu·isr·中断·uio