RandomUser
RandomUser

Reputation: 4220

Executable runtime crash caused by linking with dynamic library

Stack: MIPS, Linux, C, C++ using GNU Tools to compile and link (building on x86 for MIPS)

Fair warning: I'm a C, C++ novice, feel free to suggest anything which might be obvious as it's possible I have not tried it yet.

I am able to build an executable which dynamically links to a library (live555), if I statically link to this everything works fine, however when I attempt to dynamically link the executable crashes during runtime. To confirm I am building the .so files correctly, I've also tried building other executables (the test tools included with live555) to dynamically link against these .so libs and these tools work fine.

The linking/build seems to work fine, no errors or warnings are thrown during the build. I can inspect the crashing executable with readelf -d and clearly see the .so references. I can also run ldd on the MIPS system on the executable and the libraries seem to be loaded fine, strace output also shows these libraries as being loaded. Unfortunately the strace output doesn't really provide me with any insite, I've talked with others familiar with this system and they are not sure what the problem is.

Just looking for ideas and tools to try, if anyone has any thoughts I'd appropriate them!

Thanks for reading

Upvotes: 3

Views: 3806

Answers (1)

Misha M
Misha M

Reputation: 11299

There is not enough information here to start troubleshooting in depth. Some ideas to start debugging, from least to most time-consuming:

  1. After you run ldd on your executable, check the path(s) where that library is being loaded from, make sure the library is the version you compiled / linked against. Easy way is to get it's MD5 hash on your target and host, make sure they are the same.
    • Also check to make sure you don't have multiple instances of the library installed
    • Double check the aliases for your library, make sure they point to the same place
  2. Try enabling crash dump generation $> ulimit -c unlimited, run gdb or DDD, load the crash dump and inspect your environment.
  3. Check your CFLAGS, it could be as @YannRamin said, you need -fPIC for MIPS. You can run make -n to see how your binary is being generated.
  4. Check your LDPATH env on target and make sure it is sensible; empty is perfectly fine btw.
  5. Check your LDFLAGS during compile / linking. You might have to run make -n, look for gcc command or collect command, then copy-paste the entire line and add --verbose to the end so you can see exactly what the linker is doing. You might have to fix paths for sources / object files, depending on how your build system is setup.

The idea is to try and eliminate potential issues, such as:

  • wrong library version: installed vs compiled against
  • multiple locations / bad aliasing
  • symbol pollution when compiling / linking
  • many others

You're lucky that you have Linux installed, so should be fairly easy, just might be time consuming.

Upvotes: 1

Related Questions