作为背景,我在 aarch64 上运行裸机 QEMU-4.1.0。
有几种方法可以让 QEMU 将编译后的代码加载到内存中。我想了解潜在的差异是什么,因为我看到了非常不同的行为,并且文档没有说明。
考虑这个第一个命令行:
qemu-system-aarch64 \
-s -S \
-machine virt,secure=on,virtualization=on \
-m 512M \
-smp 4 \
-display none \
-nographic \
-semihosting \
-serial mon:stdio \
-kernel my_file.elf \
-device loader,addr=0x40004000,cpu_num=0 \
-device loader,addr=0x40004000,cpu_num=1 \
-device loader,addr=0x40004000,cpu_num=2 \
-device loader,addr=0x40004000,cpu_num=3 \
;
Run Code Online (Sandbox Code Playgroud)
在另一个 shell 中,如果我启动 gdb 以查看 QEMU 已加载到内存中的内容,则它完全符合我的预期。事实上,gdb 有一个内置的命令用于这个......
(gdb) compare-sections
Section .start, range 0x40004000 -- 0x40006164: matched.
Section .vectors, range 0x40006800 -- 0x40006f90: matched.
Section .text, range 0x40006fc0 -- 0x4002ca7c: matched.
... …Run Code Online (Sandbox Code Playgroud) 我认为这个问题与其他类似的问题有很大不同。
我的流程大致是这样的:
### Compile
%> gcc -ggdb3 file0.c ... -fno-builtin -c -o file0.o
%> gcc -ggdb3 file1.c ... -fno-builtin -c -o file1.o
...
%> gcc -ggdb3 fileN.c ... -fno-builtin -c -o fileN.o
### Link
%> gcc -ggdb3 -nostdlib -nodefaultlibs -Tscript.lds -Ttext=0x4000000 \
-Wl,--build-id=none -o main.elf file0.o file1.o ... fileN.o
### Disassemble
%> objdump -Stsxd main.elf > main.dis
Run Code Online (Sandbox Code Playgroud)
我没有看到 . 生成的反汇编文件行之间的 C 代码objdump。 请参阅下图的示例。
我不责怪objdump,因为objdump --dwarf=decodedline main.elf什么也没有表现出来。我认为elf 文件中没有这些信息。
-g、-ggdb、 …