Here's the setup:
My coworker has a Fedora x64_86 machine with a gcc 4.3.3 cross compiler (from buildroot). I have an Ubuntu 9.04 x64_86 machine with the same cross compiler.
My coworker built an a library + test app that works on a test machine, I compiled the same library and testapp and it crashes on the same test machine.
As far as I can tell, gcc built against buildroot-compiled ucLibc, so, same code, same compiler. What kinds of host machine differences would impact cross compiling?
Any insight appreciated.
Update: To clarify, the compilers are identical. The source code for the library and testapp is identical. The only difference is that the testapp + lib have been compiled on different machines..
We often use target in compilation because different systems (CPU architectures) have different instruction sets, e.g. ARM, MIPS, etc. The compiler needs to know which instruction set is the target, so that it can create the correct output (bytecode).
The linker locates all the undefined references in the libraries. If the library is a static one, the linker just adds the actual machine code to your final executable. On the other hand, if the library is a shared one, the linker only records the name (and version?) of the library in the executable's header.
Use objdump and add --section to specify section name. For example, if your compiled a program named foo in the source dir, you can run the following commands to get GCC's version info: $ objdump -s --section . comment foo sizeof: file format elf32-i386 Contents of section .
In what way does it crash? Can you be more specific, provide output, return codes, etc... Have you tried plugging in some useful printf()'s?
And, I think we need a few more details here:
Does the testapp link to the library?
Is the library static or dynamic?
Is the library in the library search path, or have you added its directory to ld.so.conf?
Are you following any installation procedures for the library and testapp?
Are the two libraries and testapps bit-for-bit compatible? Do you expect them to be?
Are you running as the same user as your coworker, with same environment and permissions?
Obviously, something isn't identical.
Try using objdump and its many options, especially -d, to determine what is different.
You didn't make a point of it, so I am going to guess binutils is the difference. That is the set of tools used in building binaries. It includes ld, as and objdump.
Cross-compilers need their own set of binutils for the target architecture. However, unlike GCC I do not believe the binutils tools do a double bootstrap build and verify step, so it is possible that some difference from the original x86_64 build environment made it into them.
I'd try building the binutils packages for ARM again, using the ARM crosscompiler. See if that makes a difference.
It's something I have seen in regular x86 Gentoo stage1 installs too: after getting the bootstrap system and compilers installed and updated, a Gentoo user is well-recommended to rebuild system again using the updated tools.
If your code crashes (I assume you get a sigsegv), there seems to be a bug. It's most likely some kind of undefined behaviour, like using a dangling pointer or writing over a buffer boundary.
The unfortunate point of undefined behaviour is, that it may work on some machines. I think you are experiencing such an event here. Try to find the bug and you'll know what happens :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With