Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does the library compiled on two slightly different machines behaves slightly different?

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..

like image 361
EightyEight Avatar asked Aug 12 '09 19:08

EightyEight


People also ask

Why a compiler needs to know about both the target architecture?

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).

How does a compiler know if a function belongs to a statically linked source or a dynamically linked source?

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.

How do I find GCC version library?

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 .


3 Answers

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:

  1. Does the testapp link to the library?

  2. Is the library static or dynamic?

  3. Is the library in the library search path, or have you added its directory to ld.so.conf?

  4. Are you following any installation procedures for the library and testapp?

  5. Are the two libraries and testapps bit-for-bit compatible? Do you expect them to be?

  6. Are you running as the same user as your coworker, with same environment and permissions?

like image 35
Rob Jones Avatar answered Oct 02 '22 22:10

Rob Jones


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.

like image 40
Zan Lynx Avatar answered Oct 02 '22 22:10

Zan Lynx


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 :-)

like image 188
ebo Avatar answered Oct 02 '22 22:10

ebo