【发布时间】:2022-01-15 00:00:27
【问题描述】:
通常一个问题会引导我进入另一个问题。
在尝试调试内联汇编代码时,我遇到了另一个基本问题。
长话短说,我想在 qemu 上运行 arm64 baremetal hello world 程序。
#include <stdio.h>
int main()
{
printf("Hello World!\n");
}
我这样编译它: aarch64-none-elf-gcc -g test.c
_exit_sbrk_write_close_lseek_read_fstat 和 _isatty 出现未定义的引用错误。我在过去了解到-specs=rdimon.specs 编译选项消除了这个错误。
于是我跑了
aarch64-none-elf-gcc -g test.c -specs=rdimon.specs
它可以使用 a.out 文件编译。
现在我运行 qemu baremetal 程序来调试代码。
qemu-system-aarch64 -machine virt,gic-version=max,secure=true,虚拟化=true -cpu cortex-a72 -kernel a.out -m 2048M -nographic -s -S
这是 gdb 的运行结果。
ckim@ckim-ubuntu:~/testdir/testinlinedebugprint$ aarch64-none-elf-gdb a.out
GNU gdb (GNU Toolchain for the A-profile Architecture 10.2-2020.11 (arm-10.16)) 10.1.90.20201028-git
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "--host=x86_64-pc-linux-gnu --target=aarch64-none-elf".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://bugs.linaro.org/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from a.out...
(gdb) set architecture aarch64
The target architecture is set to "aarch64".
(gdb) set serial baud 115200
(gdb) target remote :1234
Remote debugging using :1234
_start ()
at /tmp/dgboter/bbs/build02--cen7x86_64/buildbot/cen7x86_64--aarch64-none-elf/build/src/newlib-cygwin/libgloss/aarch64/crt0.S:90
90 /tmp/dgboter/bbs/build02--cen7x86_64/buildbot/cen7x86_64--aarch64-none-elf/build/src/newlib-cygwin/libgloss/aarch64/crt0.S: No such file or directory.
(gdb) b main
Breakpoint 1 at 0x4002f8: file test.c, line 26.
(gdb)
(gdb) r
The "remote" target does not support "run". Try "help target" or "continue".
(gdb) c
Continuing.
它不会中断和挂起。
我究竟做错了什么?以及如何解决/tmp/dgboter/bbs/build02--cen7x86_64/buildbot/cen7x86_64--aarch64-none-elf/build/src/newlib-cygwin/libgloss/aarch64/crt0.S: No such file or directory. 问题?
任何帮助将不胜感激。谢谢!
添加:
我意识到我之前也问过同样的问题(How to compile baremetal hello_world.c and run it on qemu-system-aarch64?)(啊!我的记忆......)我意识到我需要所有的东西,比如 start.S crt0.S 和链接器脚本,. . .我愚蠢地认为,当我实际上必须填充非常低级的东西时,裸机编译器会自动处理它。在某些情况下,我从事过裸机程序,但这是在其他人已经设置了这些初始环境之后(有时我什至对它们进行了多次修改!)。在裸机中,您必须提供所有东西。没有任何东西可以视为理所当然,因为它是“裸机”。我这么晚才意识到这个基本的东西..
【问题讨论】: