开发者

seg fault when running arm-elf-gcc compiled code

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开发者_如何学Python 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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜