nju-projectn / nemu Goto Github PK
View Code? Open in Web Editor NEWNJU EMUlator, a full system x86/mips32/riscv32/riscv64 emulator for teaching
License: Other
NJU EMUlator, a full system x86/mips32/riscv32/riscv64 emulator for teaching
License: Other
I've tried to follow the procedure in tutorial, and an error occur when I try to compile it.
+ CXX src/utils/disasm.cc
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
+ LD $NEMU_HOME$/build/riscv32-nemu-interpreter
Native Ubuntu is supported systemd, but not in WSL. So I try to replace the "systemd command" with "sysvinit command", but find no way to start. So is there any suggerstion for me to start?
NEMU_HOME= is not a NEMU repo. Stop.
I met a error that the lecture does not mention,i retry to download all the files ,but i met the error again .And i spend a lot of time searching for the answer but i still have no idea how to fix it.Maybe it is my computer's problem? I hope you can give me some suggestions.Thank you.
this error happened when i compile the project by make
,then the error occured. I can roughly understand the problem , but i can solve it .
my environment is the virtual machine(VMware) and the ubuntu 20.04 system
src/utils/disasm.cc:55:8: error: ‘class llvm::MCInstPrinter’ has no member named ‘setPrintBranchImmAsAddress’
55 | gIP->setPrintBranchImmAsAddress(true);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
make: *** [/home/tom/ics2021/nemu/scripts/build.mk:40: /home/tom/ics2021/nemu/build/obj-riscv32-nemu-interpreter/src/utils/disasm.o] Error 1
My suggestion is that instead of defining global at t0 t1 t2
and praying for no conflicts, we should encourge local definitions, which means any needed intermediate "registers" should be put into the corresponding function scope. e.g.
/// rtlreg_t at;
// ...
void interpret_rtl_addi(const rtlreg_t* dest, const rtlreg_t* src, int imm){
/// rtl_li(&at, imm);
/// rtl_add(dest, src, &at);
rtlreg_t imm_at;
rtl_li(&imm_at, imm)
rtl_add(dest, src, &imm_at);
}
I expect some arguments like "this is simulation of hardware behavior". However, I'm somewhat familiar with Verilog, and I don't think there's a counterpart of RTL temporary registers like at
.
Maybe it is a concept borrowed from MIPS, but AFAIK they are not sharing lots of similarities.
As we know, a graph of IC is a combination of synchronized circuits and combinatorial circuits, with the latter stateless and the former stateful.
Obviously, due to C language semantics, a globally defined at
rtl register is more like a part of global state. However, the usage of temporary RTL registers(e.g. the "at" in rtl_li(&at, imm)
), are basically something like wire
in verilog, which is combinatorial, thus stateless.
What's more, when we refer to intel manual, the defnition of temporary registers is quite arbitrary, instead of sticking to some fixed set of temporary registers. Take near relative CALL
in 64bit as an example:
tempDEST ← SignExtend(DEST); (* DEST is rel32 *)
tempRIP ← RIP + tempDEST;
IF stack not large enough for a 8-byte return address
THEN #SS(0); FI;
Push(RIP);
RIP ← tempRIP;
Here tempXXXs are local and stateless. Though we can use global registers like at t0 t1
to simulate this behavior, it is not intuisive and invites unexpected bugs.
In conclusion, we should encourge local definitions in function scopes, especially RTL ones. It will benifit code readability and robustness dramatically.
老师您好,我在PA2中实现了声卡并通过了Audio_test(有声音)。
但带音效的红白机版本我无法正常运行,会卡在Initialize audio处不再继续,开始会有一小段电流声。经检测,将声音改为HQ_SOUND_NONE可以正常使用。请问这个版本的PA是否可以使用声卡?
make menuconfig 是成功的,但是接下来 make 编译的时候失败了,根据提示在 script/build.mk 第 54 行添加了 -fPIE。但是,依然报了同样的错误,我对 gcc 不是很熟悉,关于这个错误,我该怎么解决它呢?
OS: fedora36
llvm: 14.0.0
gcc: 12.1.1
g++: 12.1.1
make[1]: Entering directory '/home/yuan/Documents/ysyx-workbench'
make[1]: Leaving directory '/home/yuan/Documents/ysyx-workbench'
+ LD /home/yuan/Documents/ysyx-workbench/nemu/build/riscv32-nemu-interpreter
/usr/bin/ld: /home/yuan/Documents/ysyx-workbench/nemu/build/obj-riscv32-nemu-interpreter/src/device/io/map.o: relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a PIE object; recompile with -fPIE
/usr/bin/ld: /home/yuan/Documents/ysyx-workbench/nemu/build/obj-riscv32-nemu-interpreter/src/device/io/mmio.o: relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIE
/usr/bin/ld: /home/yuan/Documents/ysyx-workbench/nemu/build/obj-riscv32-nemu-interpreter/src/device/io/port-io.o: relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a PIE object; recompile with -fPIE
/usr/bin/ld: /home/yuan/Documents/ysyx-workbench/nemu/build/obj-riscv32-nemu-interpreter/src/engine/interpreter/hostcall.o: relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a PIE object; recompile with -fPIE
/usr/bin/ld: /home/yuan/Documents/ysyx-workbench/nemu/build/obj-riscv32-nemu-interpreter/src/cpu/cpu-exec.o: relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a PIE object; recompile with -fPIE
/usr/bin/ld: /home/yuan/Documents/ysyx-workbench/nemu/build/obj-riscv32-nemu-interpreter/src/cpu/difftest/ref.o: relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIE
/usr/bin/ld: /home/yuan/Documents/ysyx-workbench/nemu/build/obj-riscv32-nemu-interpreter/src/monitor/monitor.o: relocation R_X86_64_32S against `.rodata.str1.1' can not be used when making a PIE object; recompile with -fPIE
/usr/bin/ld: /home/yuan/Documents/ysyx-workbench/nemu/build/obj-riscv32-nemu-interpreter/src/monitor/sdb/expr.o: relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIE
/usr/bin/ld: /home/yuan/Documents/ysyx-workbench/nemu/build/obj-riscv32-nemu-interpreter/src/monitor/sdb/sdb.o: relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a PIE object; recompile with -fPIE
/usr/bin/ld: /home/yuan/Documents/ysyx-workbench/nemu/build/obj-riscv32-nemu-interpreter/src/monitor/sdb/watchpoint.o: relocation R_X86_64_32 against `.bss' can not be used when making a PIE object; recompile with -fPIE
/usr/bin/ld: /home/yuan/Documents/ysyx-workbench/nemu/build/obj-riscv32-nemu-interpreter/src/utils/log.o: relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a PIE object; recompile with -fPIE
/usr/bin/ld: /home/yuan/Documents/ysyx-workbench/nemu/build/obj-riscv32-nemu-interpreter/src/memory/paddr.o: relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a PIE object; recompile with -fPIE
/usr/bin/ld: /home/yuan/Documents/ysyx-workbench/nemu/build/obj-riscv32-nemu-interpreter/src/isa/riscv32/inst.o: relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIE
collect2: error: ld returned 1 exit status
make: *** [/home/yuan/Documents/ysyx-workbench/nemu/scripts/build.mk:54: /home/yuan/Documents/ysyx-workbench/nemu/build/riscv32-nemu-interpreter] Error 1
在/abstract-machine/am/src/native/platform.h中,__am__cpu_t结构体中有一个变量:uint8_t sigstack[SIGSTKSZ]
在用native测试时会显示‘variably modified array at file scope’,STFW后发现是不能把常量作为数组的大小。
(https://stackoverflow.com/questions/13645936/variably-modified-array-at-file-scope-in-c)
暂时的解决办法是,输出SIGSTKSZ的值(在我的Ubuntu22,.04下是8192),换为uint8_t sigstack[8192]中即可解决这个问题。
另一个问题是,用native会提示缺少"SDL2/SDL.h",似乎Ubuntu22.04不自带这个库。我在解决的这个问题中遇到了一些麻烦,但最后还是解决了。
我知道下个学期上课后我会重做PA,应该也会更新用Ubuntu22.04来进行(我目前用Ubuntu22.04来做ICS2021,我自知是不合适的),于是我想报告一下这个问题(因为讲义上这两个问题都没见到),不知道这是否是需要被更新的问题,还是只是我个人的问题。
开发环境
系统版本:WSL2 Ubuntu 20.04.5 LTS
GCC版本:9.4.0 (Ubuntu 9.4.0-1ubuntu~20.04.1)
指令架构:riscv64
问题描述
在开启CONFIG_DIFFTEST
宏之后,在nemu
目录下执行make run
命令,终端会报很多类似下图中的错误。
原因分析
结合报错信息上网查找相关资料,得知optional
是C++17标准中引入的新功能,而9.4.0版本的GCC默认使用的是C++11标准,所以需要在编译时通过参数指定C++标准版本。于是接下来我排查了动态生成的spike-diff/repo/build/Makefile
文件,发现C++编译选项中已经添加了-std=c++17
参数,即已经开启了对C++17标准的支持。但是为什么还会出现这种问题?optional
是在GCC 7.2中首次从实验标准转为正式标准,GCC 9中肯定也存在。
后来终于发现在nemu/tools/spike-diff/Makefile
中添加-std=c++17
能编译成功,可是编译出错的位置是在spike
仓库内部,并不在spike-diff
中,说明在编译生成spike的静态链接库时编译依赖会向上传递?总之,该问题应该与GCC版本有关,某些版本的编译器需要手动添加参数。
问题发现者
@Jasonyanyusong
@myyerrol
解决方案
如下图所示,在nemu/tools/spike-diff/Makefile
文件中的编译选项中添加-std=c++17
即可。
如果只开启 -fsanitize=address,那么检测器只会告诉程序员代码泄露发生在哪个函数。而开启-g后,Asan会提示发生在哪一行中。
CFLAGS_BUILD += $(if $(CONFIG_CC_ASAN),-fsanitize=address -g,) # 增加 -g
/ics2023/nemu$ make
make: llvm-config: No such file or directory
+ CXX src/utils/disasm.cc
src/utils/disasm.cc:21:10: fatal error: llvm/MC/MCAsmInfo.h: No such file or directory
21 | #include "llvm/MC/MCAsmInfo.h"
| ^~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make: *** [/home/ubuntu/Home/Multipass_Files/ics2023/nemu/scripts/build.mk:40: /home/ubuntu/Home/Multipass_Files/ics2023/nemu/build/obj-riscv32-nemu-interpreter/src/utils/disasm.o] Error 1
Ubuntu 22.04.3 LTS
$ make menuconfig
ics2021/nemu/scripts/config.mk:5: Warning: .config does not exists!
ics2021/nemu/scripts/config.mk:6: To build the project, first run 'make menuconfig'.
=========================
Dir: ~/ics2021/nemu
Distro: Ubuntu 22.04 LTS
Kernel: Linux 5.15.0-27-generic
GCC: 11.2.0
LLVM: 14.0.0
When I first using make ARCH=native run mainargs=mario
to test rom game
# Building fceux-run [native]
+ CXX src/emufile.cpp
# Building am-archive [native]
# Building klib-archive [native]
# Creating image [native]
+ LD -> build/fceux-native
/home/arutoria/ics2022/fceux-am/build/fceux-native
ROM is mario
Starting FCEUX 2.2.3-interim git...
Found ROM 'mario'
Loading ...
PRG ROM: 2 x 16KiB
CHR ROM: 1 x 8KiB
ROM MD5: 0x8e3630186e35d477231bf8fd50e54cdd
Mapper #: 0
Mapper name: NROM
Mirroring: Vertical
Battery-backed: No
Trained: No
Power on
Initializing video...
XDG_RUNTIME_DIR (/usr/lib/) is not owned by us (uid 1000), but by uid 0! (This could e.g. happen if you try to connect to a non-root PulseAudio as a root user, over the native protocol. Don't do that.)
XDG_RUNTIME_DIR (/usr/lib/) is not owned by us (uid 1000), but by uid 0! (This could e.g. happen if you try to connect to a non-root PulseAudio as a root user, over the native protocol. Don't do that.)
then I add export XDG_RUNTIME_DIR=/home/arutoria/ics2022/fceux-am
in ~/.bashrc (Frankly, I don't know what this is gonna do). Run again
..........
Mapper #: 0
Mapper name: NROM
Mirroring: Vertical
Battery-backed: No
Trained: No
Power on
Initializing video...
ALSA lib confmisc.c:855:(parse_card) cannot find card '0'
ALSA lib conf.c:5178:(_snd_config_evaluate) function snd_func_card_inum returned error: No such file or directory
ALSA lib confmisc.c:422:(snd_func_concat) error evaluating strings
ALSA lib conf.c:5178:(_snd_config_evaluate) function snd_func_conca
I don't know what's problem is it, and steps is following the 2022 pa. Hoping to get some help.
Besides, testing the key program also with a problem: show ````Try to press any key (uart or keyboard)... ``` then rather pop up a window than appear
# Building amtest-run [native]
+ CC src/tests/hello.c
+ CC src/tests/devscan.c
+ AS src/tests/audio/audio-data.S
+ CC src/tests/audio.c
+ CC src/tests/keyboard.c
+ CC src/tests/intr.c
+ CC src/tests/mp.c
+ CC src/tests/vm.c
+ CC src/tests/video.c
+ CC src/tests/rtc.c
+ CC src/main.c
# Building am-archive [native]
# Building klib-archive [native]
# Creating image [native]
+ LD -> build/amtest-native
/home/arutoria/ics2022/am-kernels/tests/am-tests/build/amtest-native
Try to press any key (uart or keyboard)...
Authorization is required, but no Authorization protocol specified
Attached is the suggested patch.
In src/isa/$ISA/logo.c
, isa_logo
doesn't have a termination character to indicate the end of a string.
unsigned char isa_logo[] = {
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x5f, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x5f, 0x5f, 0x20,
0x20, 0x5f, 0x5f, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x5f, 0x20, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x28, 0x5f, 0x29, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x7c, 0x20, 0x20, 0x5c, 0x2f, 0x20, 0x20, 0x7c, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x7c, 0x20,
0x7c, 0x0a, 0x20, 0x20, 0x5f, 0x20, 0x5f, 0x5f, 0x20, 0x5f, 0x20, 0x5f,
0x5f, 0x5f, 0x20, 0x20, 0x5f, 0x5f, 0x5f, 0x20, 0x5f, 0x5f, 0x5f, 0x5f,
0x5f, 0x5f, 0x5f, 0x5f, 0x20, 0x20, 0x20, 0x5f, 0x5f, 0x20, 0x7c, 0x20,
0x5c, 0x20, 0x20, 0x2f, 0x20, 0x7c, 0x20, 0x5f, 0x5f, 0x20, 0x5f, 0x20,
0x5f, 0x20, 0x5f, 0x5f, 0x20, 0x20, 0x5f, 0x20, 0x20, 0x20, 0x5f, 0x20,
0x20, 0x5f, 0x5f, 0x20, 0x5f, 0x7c, 0x20, 0x7c, 0x0a, 0x20, 0x7c, 0x20,
0x27, 0x5f, 0x5f, 0x7c, 0x20, 0x2f, 0x20, 0x5f, 0x5f, 0x7c, 0x2f, 0x20,
0x5f, 0x5f, 0x7c, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5c, 0x20, 0x5c,
0x20, 0x2f, 0x20, 0x2f, 0x20, 0x7c, 0x20, 0x7c, 0x5c, 0x2f, 0x7c, 0x20,
0x7c, 0x2f, 0x20, 0x5f, 0x60, 0x20, 0x7c, 0x20, 0x27, 0x5f, 0x20, 0x5c,
0x7c, 0x20, 0x7c, 0x20, 0x7c, 0x20, 0x7c, 0x2f, 0x20, 0x5f, 0x60, 0x20,
0x7c, 0x20, 0x7c, 0x0a, 0x20, 0x7c, 0x20, 0x7c, 0x20, 0x20, 0x7c, 0x20,
0x5c, 0x5f, 0x5f, 0x20, 0x5c, 0x20, 0x28, 0x5f, 0x5f, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x5c, 0x20, 0x56, 0x20, 0x2f, 0x20, 0x20,
0x7c, 0x20, 0x7c, 0x20, 0x20, 0x7c, 0x20, 0x7c, 0x20, 0x28, 0x5f, 0x7c,
0x20, 0x7c, 0x20, 0x7c, 0x20, 0x7c, 0x20, 0x7c, 0x20, 0x7c, 0x5f, 0x7c,
0x20, 0x7c, 0x20, 0x28, 0x5f, 0x7c, 0x20, 0x7c, 0x20, 0x7c, 0x0a, 0x20,
0x7c, 0x5f, 0x7c, 0x20, 0x20, 0x7c, 0x5f, 0x7c, 0x5f, 0x5f, 0x5f, 0x2f,
0x5c, 0x5f, 0x5f, 0x5f, 0x7c, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x5c, 0x5f, 0x2f, 0x20, 0x20, 0x20, 0x7c, 0x5f, 0x7c, 0x20, 0x20,
0x7c, 0x5f, 0x7c, 0x5c, 0x5f, 0x5f, 0x2c, 0x5f, 0x7c, 0x5f, 0x7c, 0x20,
0x7c, 0x5f, 0x7c, 0x5c, 0x5f, 0x5f, 0x2c, 0x5f, 0x7c, 0x5c, 0x5f, 0x5f,
0x2c, 0x5f, 0x7c, 0x5f, 0x7c, 0x0a, /* '\0' should be placed here */
};
Therefore, in src/engine/interpreter/hostcall.c
, there is a statement which access isa_logo
as a string:
printf(ASNI_FMT("If it is the first case, see\n%s\nfor more details.\n\n"
"If it is the second case, remember:\n"
"* The machine is always right!\n"
"* Every line of untested code is always wrong!\n\n", ASNI_FG_RED), isa_logo);
In the absence of '\0' at the end of isa_logo
, memory access is not assured to be within legal bound. Hence, the program is under the risk of global heap overflow
issue.
See also: llvm/llvm-project@89b5706 and Differential Revision
One of workarounds:
if [ "$(llvm-config --version | awk -F. '{print $1}')" -ge "14" ]; then
sed -i "s/\"llvm\/Support\/TargetRegistry.h\"/\"llvm\/MC\/TargetRegistry.h\"/g" $NEMU_HOME/src/utils/disasm.cc
fi
ics2021/nemu/src/cup/cpu-exec.c line 47:#define NUMBERIC_FMT MUXDEF(CONFIG_TARGET_AM, "%ld", "%'ld") may be need to be changed as #define NUMBERIC_FMT MUXDEF(CONFIG_TARGET_AM, "%ld", "%lld")
您好,我在centos平台上编译nemu,发现出错的位置在init_disasm函数中,我尝试了去除MUXDEF,直接采用i686-pc–linux–gnu或者mipsel-pc–linux–gnu作为该函数的参数,发现编译成功。在init_disasm函数中,我发现它调用四个llvm的初始化函数,它们引入了一些后缀名为def的文件,我打开这些文件发现没有riscv,从而我尝试在.def文件中加入RISCV,但并没有解决该问题。我怀疑问题出在llvm上(12.0版),但是找不到解决方法,期待您的回复。
根据您的讲义,我重新安装了llvm,版本为11.0,目前已经能够成功编译NEMU。
Hi, I'm not a student from NJU, but learning NJU's ICS accroding to ICS offcial website && open-source code right now. It's a very fantasitic experience to me! I have already learnt a lot from this course despite I'm just on the way to finish lab2.4! I want to say thank you for your guys hard works in this course and generosity at first!
So here is my question.
Line 128 in 09bb925
checkregs
need a PC
parameter, I think that means we should check pc's value in it's definition. But after ref_difftest_exec
, the PC
value in ref's CPU_STATE
should be next_pc
. So I think we should pass next_pc
or npc
when calling checkregs
just like the code belowLine 109 in 09bb925
But ICS course gives student freedom to exploring by themselves. So I'm doubting whether it's a mistake, or it's on purpose for training student, or I'm just totally wrong like the code should be works fine(or works in some ISAs).
At last, very thanks for your guys again!
似乎这个项目没有license,我在源码中也没找到相关声明。
觉得做为开源项目很有必要添加一个license。主要下游打包和有些用户可能需要明确的license,比如gentoo每个包都要license。其次是永远无法预测谁会用何种方式滥用这个项目,之前有过些经典案例。
I have a question about the difftest
in the file src/isa/riscv64/local-include/reg.h
static inline const char* reg_name(int idx, int width) { extern const char* regs[]; return regs[check_reg_idx(idx)]; }
why there is a parameter 'width' not used
如题,在GitBook中,有一些使用字符表示的图标,例如PA2.4中“现在我们就可以厘清符号表和字符串表之间的关系了:”的后面。由于PA本身显示代码块的样式使得行间距很大,加之符号本身也并不是很清晰,导致看起来不够明确。建议调整行间距,或者改成相应的图片显示。
举例,在行间距较小的github中,行间距小,是这样的:
LOAD +-- 0x001000 0x03000000 0x03000000 +0x1d600 0x27240 RWE 0x1000
| | |
| +-------------------+ |
| | |
| | | | |
| | | | |
| | +-----------+ --- |
| | |00000000000| ^ |
| | --- |00000000000| | |
| | ^ |...........| | |
| | | |...........| +------+
| +--+ |...........| |
| | |...........| |
| v |...........| v
+-------> +-----------+ ---
| |
| |
Memory
用 make menuconfig
生成配置文件时出现:
ld: library not found for -ltinfo
请问缺少的库如何安装?是否必须在 Linux 下编译?
/nemu/src/isa/目录下只有riscv32 和riscv64相关代码 请问x86 和mps32相关的代码是要学生自己实现吗?
try to setup NEMU in WSL of ubuntu20.04 instance
~/ics2021/nemu$ make
prompts for building information are below
System has not been booted with systemd as init system (PID 1).
Can't operate.Failed to create bus connection: Host is down
which is a quite typical problem that WSL doesn't use Systemd and systemctl command instead of Sysvinit command. Is there any way to fix this issue without installing other third-party tools for systemctl in WSL?
在PA2第一部分"RTFSC(2)"的末尾,要求学生通过string
和hello-str
以外的所有测试样例,但difftest到PA2最后一部分才提出,这让习惯一步一步做的学生可能花费大量低效的时间来调试实现错误的指令。建议将difftest移到第一部分最后面。
如题
I had a crash when I was doing PA2-2-Differential Testing. I collapsed in getopt_long.
The following is a screenshot of the crash.
After a few traceing and debuging with nemu and glibc, I think maybe the flag RTLD_DEEPBIND
cause this crash (Of course I am not seting CC_ASAN in Kconfig). When I just open the dynamic library with flag RTLD_LAZY
, the program won't crash.
Line 51 in 49366fa
I am not sure about the specific reason, but I hope this information is helpful.
PA2 提供 -fsanitize=address 的编译开关,开启后可以触发 readline 库的一个内存泄漏漏洞。
性质:完全不影响PA流程。
可能有用的补充性质:我推测,绝大部分学生不会遇到、部分学生探究无果、部分学生STFW找到描述这个漏洞的追踪器、少部分学生完全理解并解释了这个现象。
为什么有必要提及:这个漏洞令人困惑,因为问题不出在学生的代码;它可能偶然被触发然后无法复现 ;即使能稳定触发,由于readline 库本身不含追踪信息,LeakSanitizer只能打印2个调用栈,很难追踪调试。我建议:在讲义中提及这个漏洞,不要给发现这个问题的学生留下遗憾。
漏洞描述:直接原因是调用了 add_history(),根本原因是 _rl_start_using_history() 没有 free 当前 data.
复现:只要在对当前行有修改的情况下用历史功能就会触发。
具体而言,
$ cd $NEMU_HOME; make memuconfig
开启 fsanitize address
$ make run;
> (nemu)
敲击 a<CR>b<UP><CR>q<CR> 按键序列(<CR>、<UP>是Vi风格的按键代码转义)
得到
> ==<pid>==ERROR: LeakSanitizer: detected memory leaks
>
> Direct leak of 32 byte(s) in 1 object(s) allocated from:
> #0 0x7f55100b4887 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:145
> #1 0x7f5510b4fbac in xmalloc (/lib/x86_64-linux-gnu/libreadline.so.8+0x39bac)
>
> SUMMARY: AddressSanitizer: 32 byte(s) leaked in 1 allocation(s).
> make: *** [path-to-ics/ics2023/nemu/scripts/native.mk:38: run] Error 1
表明成功触发.
解释 readline v8.2 修复了这个漏洞, diff一下 readline-/misc.c 就能看出来.
版本 readline version <= 8.1.2
临时修复 从源码编译 readline 8.2
diff --git a/nemu/src/filelist.mk b/nemu/src/filelist.mk
--- a/nemu/src/filelist.mk
+++ b/nemu/src/filelist.mk
@@ -19,7 +19,7 @@
-LIBS += $(if $(CONFIG_TARGET_NATIVE_ELF),-lreadline -ldl -pie,)
+LIBS += $(if $(CONFIG_TARGET_NATIVE_ELF),-ldl -pie,) path-to-directory/readline-8.2/libreadline.a -lncurses
FAQ 为什么不升级 readline? 要更换PPA。弄个NJU特供PPA?
为什么不安装新版 readline? 可能是我的问题,但是v8.2 ./configure && sudo make install 会由于兼容性不可用(找不到符号,会使一些CLI、Terminal如 gnone-terminal 崩溃)。
什么时候的漏洞? 不知道。给三个时间点:readline copyright 从 1987年开始,这个漏洞至少2006年(v5.2)就存在,第一个可考的漏洞反馈在2022年,同年被首次修复。
怎样在讲义中提及
宏一层层套 看起来非常费劲 严重牺牲了可读性 本来指令很简单的 我想学生在做作业的时候一定也花了大量时间去理清楚这些宏
Running make menuconfig
on Gentoo Linux can produce following error message even if nucrses being installed:
/usr/lib/gcc/x86_64-pc-linux-gnu/12/../../../../x86_64-pc-linux-gnu/bin/ld: /home/pzy/Documents/Sync/ics2022/nemu/tools/kconfig/build/obj-mconf/lxdialog/util.o: undefined reference to symbol 'nodelay' /usr/lib/gcc/x86_64-pc-linux-gnu/12/../../../../x86_64-pc-linux-gnu/bin/ld: /usr/lib64/libtinfo.so.6: error adding symbols: DSO missing from command line
It turns out to be the problem of Gentoo's "tinfo" USE flag, this use flag forces some symbols from libncurses.so to be moved to libtinfo.so.
This can be easily fixed bu adding "-ltinfo" after LIBS += -lncurses
of /nemu/tools/kconfig/Makefile
However, I'm wondering if there is need to add this fix to source code or if pkg-config
can be intruduce to source code to generate needed libraries to compeletely avoid this problem?
I have put forward a issues afternoon,but later i found that my ubuntu version is 20.04 and the requested is 21.04 . so i think the problem
is the version of llvm in my machine is too low . so i update it to llvm 14 -- the latest version .Howerver,i met another problem following
src/utils/disasm.cc:5:10: fatal error: llvm/Support/TargetRegistry.h: No such file or directory
5 | #include "llvm/Support/TargetRegistry.h"
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
i think the reason of this maybe i need to update other things ,but i reinstall all the things ,the error still exist.And i try to search for the answer but i haven't find it .And because i have used the ubuntu 20.04 for a long peroid of time ,so i haven't decide to change it to ubuntu 21.04.I hope you can give me some tips on how to solve this .Thank you.
I use clang format in vscode. However, I've encountered an issue where header files are automatically sorted, causing unexpected changes as illustrated below:
--- a/abstract-machine/am/src/native/ioe/audio.c
+++ b/abstract-machine/am/src/native/ioe/audio.c
@@ -1,8 +1,8 @@
#define _GNU_SOURCE
+#include <SDL2/SDL.h>
#include <fcntl.h>
-#include <unistd.h>
#include <klib.h>
-#include <SDL2/SDL.h>
+#include <unistd.h>
This leads to compilation error:
abstract-machine/am/src/native/ioe/audio.c: In function ‘__am_audio_init’:
abstract-machine/am/src/native/ioe/audio.c:13:15: error: implicit declaration of function‘pipe2’; did you mean ‘pipe’? [-Werror=implicit-function-declaration]
13 | int ret = pipe2(fds, O_NONBLOCK);
| ^~~~~
| pipe
cc1: all warnings being treated as errors
Would it be possible to consider adding a comment or notice in the codebase to emphasize this behavior? It would be helpful to prevent such sorting of header files and subsequent compilation errors.
现在编译menuconfig时,会从CONFIG_CC的值中提取CC。但是在初始执行make menuconfig
时,CONFIG_CC为空,导致CC的值也为空。根据GNU make的文档:
Except by explicit request, make exports a variable only if it is either defined in the environment initially, or if set on the command line and its name consists only of letters, numbers, and underscores.
如果在调用make
时,环境变量中有CC,就会导致这个空的CC被export。而fixdep目录下的Makefile没有指定CC,就会导致因为找不到CC而failed。
root@a55311a49b3b:/home/xin/ics-pa/nemu# CC=gcc make menuconfig
/home/xin/ics-pa/nemu/scripts/config.mk:20: Warning: .config does not exists!
/home/xin/ics-pa/nemu/scripts/config.mk:21: To build the project, first run 'make menuconfig'.
+ CC confdata.c
+ CC expr.c
+ CC preprocess.c
+ CC symbol.c
+ CC util.c
+ YACC build/parser.tab.h
+ LEX build/lexer.lex.c
+ CC build/lexer.lex.c
+ CC build/parser.tab.c
+ CC mconf.c
+ CC lxdialog/util.c
+ CC lxdialog/checklist.c
+ CC lxdialog/yesno.c
+ CC lxdialog/inputbox.c
+ CC lxdialog/textbox.c
+ CC lxdialog/menubox.c
+ LD /home/xin/ics-pa/nemu/tools/kconfig/build/mconf
+ CC confdata.c
+ CC expr.c
+ CC preprocess.c
+ CC symbol.c
+ CC util.c
+ CC build/lexer.lex.c
+ CC build/parser.tab.c
+ CC conf.c
+ LD /home/xin/ics-pa/nemu/tools/kconfig/build/conf
+ CC fixdep.c
make[1]: O2: No such file or directory
+ LD /home/xin/ics-pa/nemu/tools/fixdep/build/fixdep
/usr/bin/ld: cannot find /home/xin/ics-pa/nemu/tools/fixdep/build/obj-fixdep/fixdep.o: No such file or directory
collect2: error: ld returned 1 exit status
make[1]: *** [/home/xin/ics-pa/nemu/scripts/build.mk:54: /home/xin/ics-pa/nemu/tools/fixdep/build/fixdep] Error 1
make: *** [/home/xin/ics-pa/nemu/scripts/config.mk:42: /home/xin/ics-pa/nemu/tools/fixdep/build/fixdep] Error 2
如果在顶层Makefile判断CONFIG_CC非空后再赋值,即可解决这个问题。
Help command's description should be display information ...... .
Because information is an uncountable noun.
PA is a wonderful course. Thanks a lot.
编译出现 "error no matching function for call to ’llvmLLTarget::createMCAsmInfo‘" 问题,提升函数的参数个数不对,是不是版本号问题?
nemu/src/isa
这个文件夹只有 riscv32
以及 riscv64
这两个 ISA 指令集架构。make menuconfig
选择 x86
的 ISA 之后,再进行 make
编译,发现它无法找到 x86
的 isa-def.h
文件。而这里的仓库也没有 x86
的 ISA,只有 riscv32
,riscv64
, mips32
以及longarch32
的 ISA。
我在 GitHub 找了好久也没有发现,所以请问哪里可以找见?
What's the relation between OpenXiangShan/NEMU and NJU-ProjectN/nemu?
This error is raised after i upgraded my system from ubuntu 20.04 to 22.04.
The whole error log is as follows:
i try to fix this issue by disabling the "Werror=array-bounds" check by following codes added in the makefile:
CFLAGS += -Wno-array-bounds
Then i successfully "make ISA=riscv run", and start nemu.
So could you help to check if these codes have some bug with ubuntu 22.04, or there may have some other ways to fix it.
Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.