运行arm-elf-gcc编译代码时出现seg错误

发布于 2024-10-01 00:13:10 字数 699 浏览 5 评论 0原文

使用 MacPorts,我刚刚在 MacBook Pro 上安装了 arm-elf-gcc。这工作完美无缺,一切似乎都运行良好。

然而,在用 C 和 C++ 编译一个简单的 hello world 测试程序并尝试在目标板(运行 Debian Linux 的基于 ARM9 的板)上运行后,它们立即出现段错误。

我对如何调试这个有点困惑,因为目标板可用的工具有限并且没有 gdb。我已经使用 Linux 托管的交叉编译器成功构建并运行了其他代码,因此它应该可以工作。

有什么想法吗?

按照我构建并运行 gdbserver 的建议,我在主机上的 gdb 中得到以下信息:

程序收到信号 SIGSEGV,分段错误。 0x00000000 在 ?? ()

我认为这可能是标准 c 库的问题,所以我删除了所有调用,只有一个返回 0 的空 main,它是用 -Wall -g hello-arm.cpp -static 编译的。作为测试,我使用 Linux 托管的交叉编译器编译了相同的源代码,它运行和退出都很好。我能看到的唯一区别是 Linux 编译版本的大小超过两倍,以及 file 命令的输出差异:

arm-elf-gcc:ELF 32 位 LSB 可执行文件,ARM,版本1,静态链接,未剥离

arm-*-linux:ELF 32位LSB可执行文件,ARM,版本1,静态链接,适用于GNU/Linux 2.4.18,未剥离

Using MacPorts i have just installed arm-elf-gcc on to my MacBook Pro. This worked flawlessly and all seems to run fine.

However, after compiling a simple hello world test program in C and C++ and trying to run either on the target board (an ARM9 based board running Debian Linux) they immediately seg fault.

I'm a bit stuck as how to go about debugging this, as the target board has limited tools available and no gdb. I have successfully built and run other code using a Linux hosted cross compiler so it should work.

Any ideas?

Following the suggestion I have built and run gdbserver, I get the following in gdb on the host:

Program received signal SIGSEGV, Segmentation fault.
0x00000000 in ?? ()

I thought it may be a problem with the standard c libs so I removed any calls and have just an empty main that return 0, it is compiled with -Wall -g hello-arm.cpp -static. As a test I compiled the same source with a Linux hosted cross compiler and it runs and exits fine. The only difference I can see is the that Linux compiled version is over twice the size and the difference in output from the file command:

arm-elf-gcc: ELF 32-bit LSB executable, ARM, version 1, statically linked, not stripped

arm-*-linux: ELF 32-bit LSB executable, ARM, version 1, statically linked, for GNU/Linux 2.4.18, not stripped

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

就像说晚安 2024-10-08 00:13:10

在这种情况下,通常的调试方法是在目标板上运行 gdbserver,并通过主机上运行的 gdb 连接到它(通过以太网)。

或者,您可以尝试将 Mac 编译的“Hello World”程序中的程序集与(工作的)Linux 编译的程序集进行比较,看看有什么不同。

The usual method of debugging in this situation is to run gdbserver on the target board, and connect to it (via ethernet) with gdb running on a host computer.

Alternately, you could try comparing the assembly in a Mac-compiled "Hello World" program and a (working) Linux-compiled one to see what's different.

箹锭⒈辈孓 2024-10-08 00:13:10

经过几天的研究,我开始对嵌入式编译器有了更多的了解。我不太确定通过 MacPorts 安装的 arm-elf-gcc 和我在 Linux 机器上安装的 arm-unknown-linux 工具链之间的区别。我刚刚看到一个 pdf 标题为“GNU 简介编译器”,其中包含以下段落:

重要:使用 GNU 编译器
创建你的可执行文件并不完全是
与使用 GNU 链接器相同,
手臂精灵,你自己。原因是
GNU 编译器自动
链接多项标准体系
库到您的可执行文件中。这些
库允许您的程序
与操作系统交互,
使用标准C库函数,
使用某些语言功能以及
运算(例如除法)等等
在。如果您想确切地看到哪个
图书馆正在被链接到
可执行文件,你应该通过
详细标志
-v 给编译器。

这对于
嵌入式系统!此类系统不
通常有一个操作系统。
这意味着在系统中链接
图书馆几乎总是
无意义:如果没有操作
系统,例如,然后调用
标准 printf 函数不会使
很有道理。

因此,当我稍后回到我的开发机器时,我将确定与 Linux 构建链接的库并将它们添加到 arm-elf-gcc 构建中。

当我有更多信息时,我会更新此内容,但我只是想记录我的发现,以防其他人遇到这些问题。

After digging around for a couple of days I am starting to understand a bit more about embedded compilers. I wasn't really sure of the difference between arm-elf-gcc installed via MacPorts and the arm-unknown-linux toolchain I had installed on my Linux box. I just came across a pdf titled "An introduction to the GNU compiler" which contains the following paragraph:

Important: Using the GNU Compiler to
create your executable is not quite
the same as using the GNU Linker,
arm-elf-ld, yourself. The reason is
that the GNU Compiler automatically
links a number of standard system
libraries into your executable. These
libraries allow your program to
interact with an operating system, to
use the standard C library functions,
to use certain language features and
operations (such as division), and so
on. If you wish to see exactly which
libraries are being linked into the
executable, you should pass the
verbose flag
-v to the compiler.

This has important implications for
embedded systems! Such systems do not
usually have an operating system.
This means that linking in the system
libraries is almost always
meaningless: if there is no operating
system, for example, then calling the
standard printf function does not make
much sense.

So when I get back to my dev machine later I will determine the libraries linked in with the Linux build and add them to the arm-elf-gcc build.

I'll update this when I have more information but I just want to document my findings in case any one else has these problems.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文