How can I debug program linking specific version of shared library? - linker

helloworld.c:
int main(){}
[1] 9845 illegal hardware instruction (core dumped) LD_PRELOAD=./libc.so.6 ./helloworld
This preload libc is an old version of glibc
Can I debug helloworld linking it on my system?
Or is there a fast way to deploy a virtual machine with the specific version of shared libraries?

Can I debug helloworld linking it on my system?
Yes, but you need to do it correctly. This answer provides details, and an explanation for why your LD_PRELOAD didn't work.

From your post I could see POC dumping core. So, better use gdb to analyze the coredump and see the crashing callstack. Make sure you load the right libc in gdb while analyzing coredump.
Else use LD_DEBUG=all before invoking POC and see if any pointers to crash by seeing the details during runtime.

Related

Run valgrind on cross compiled executable

I'm using Ubuntu 18.04 VM and trying to find a way to valgrind check an arm-Linux executable. I've tried compiling with local gcc but ran into some problems. The executable is created by Makefile provided from project. I've tried linaro emulator, following guides online, but faced multiple issues which for each one I've searched on online for solutions but all failed. What are the ways I can valgrind?
As long as I can check program for memory leak, any way is fine.
What I get when I valgrind executable now:
valgrind: failed to start tool 'memcheck' for platform 'arm-linux': No such file or directory
The file it self is fyi:
nrf52832_xxaa.out: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, with debug_info, not stripped
I've searched through multiple posts for solutions but couldn't find any.
Cross compile valgrind, and execute on the target. There are no other ways. Can't even use qemu to execute valgrind.
It is mandatory to run the executable on the device.
Please consider the option to download the precompiled package for your arch example from https://packages.debian.org/search?keywords=valgrind, follow the mandatory dependencies, and install all on you embedded device. I use to base the version according to the installed version of libc.

Use Valgrind on shared library that is closed before the app exits

How to find memory leaks in shared library (.so) that is loaded dynamically in a third party app, for which the code is not available (but has been built with debug info)? The problem is probably that the shared library is dlclose'd before the exit of the application and Valgrind no longer has the debug information of the application and reports the addresses of memory leaks as question marks.
Currently have tried the following:
Built the project with debug info using both clang and gcc
compilers
LD_PRELOAD the shared library before running the application
Is there anything that can be done so that Valgrind can detect the debug symbols?
Here is an extract from valgrind 3.14 NEWS:
The new option --keep-debuginfo=no|yes (default no) can be used to retain debug info for unloaded code. This allows saved stack traces
(e.g. for memory leaks) to include file/line info for code that has
been dlclose'd (or similar). See the user manual for more
information and known limitations.
So, just using --keep-debuginfo=yes should show the proper stacktraces for the leaks.
Using the correct flags for the linker on gcc, the shared library is forced to stay loaded until the application exits. This option is called:
-z nodelete
Sample flags for building with gcc:
gcc -fPIC -g -c -Wall -z nodelete
and for CMAKE:
set(CMAKE_SHARED_LINKER_FLAGS, "-z nodelete")
The above have only been tested with gcc.

"Type 'MPI_Status' could not be resolved" in Eclipse Parallel Tools Platform (Kepler)

I'm trying to get a development environment going for programming with MPI and C. I had a look around and found Eclipse Parallel Tools Platform.
I am experiencing lots of errors of the form Type 'MPI_Status' could not be resolved and other resolution errors from vanilla eclipse-ptp-kepler. I'm on Linux x86_64 (Ubuntu 12.04.3 LTS) using the helloworld MPI C example with the Linux GCC Toolchain.
Also perhaps noteworthy: Launching the default "Local C/C++ Application" Run Configuration gives Launch failed. Binary not found
Any help would be greatly appreciated! Suggestions about other development environments are welcome if you are unsure of the solution to this problem.
Thanks for reading!
MPI_Status is typically defined in mpi.h, so you'll have to make sure it's in your include path. The "launch failed" error also suggests that maybe the mpirun, mpiexec or mpicc programs are missing from your executable path. You might have to either set up an MPI implementation like OpenMPI locally and point PTP to it, or follow the directions here to set up a remote build: http://help.eclipse.org/kepler/index.jsp?topic=%2Forg.eclipse.ptp.doc.user%2Fhtml%2Ftoc.html
you need to pass the flag -fopenmp to gcc to enable OpenMP, don't forget that OpenMP is a technology that needs support from the compiler; on other implementation the flag may vary, check the docs for your compiler.

Unable to load shared library: undefined symbols

I have my own program with plugins (dynamic shared libraries) on a linux (ubuntu) system. My libraries (plugins) use OpenCV (maybe not so important).
My plugins are in /usr/local/lib/mysoft/.
I have compiled my program successfully even with libraries, successfully installed so everything seems to be OK up to this point.
When I run my program, it loads a bunch of these libraries based on some configuration file. I have several libraries which are loaded successfully but I cannot load one library. It gives me error when loading (used dlopen() to open the library):
/usr/local/lib/mysoft/libMyPlugin2.so: undefined symbol: _ZN2cv6resizeERKNS_11_InputArrayERKNS_12_OutputArrayENS_5Size_IiEEddi
Segmentation fault (core dumped)
Tue Nov 20 19:11:29 CET 2012
It obviously has some problems to find cv::resize which is part of OpenCV but I don't understand why.
I checked following things:
OpenCV is probably correctly installed since other libraries use it as well and are loaded without problems
no dependencies of my program, libMyPlugin2.so or OpenCV are missing (checked with ldd)
Architecture of all libraries and binaries seems to be the same (I checked it with objdump -f)
Does anybody have an idea what am I doing wrong?
This post seems to be so relevant but still didn't help:
Linux shared library that uses a shared library undefined symbol
Well I found the problem, hopefully it can help others...
The problem - I was missing one OpenCV library when compiling. So I replaced "opencv_core opencv_highgui" by "opencv_core opencv_imgproc opencv_highgui" and everything works.
So although I was able to compile it one of the dependencies was missing - I guess something has changed in OpenCV cause these sources worked perfectly (even with build) with older versions of the OpenCV.

Creating a GNU C environment in apple darwin

I had no luck finding precompiled packages of glibc for apple darwin. I could not compile gcc from source, and I'm assuming that compiling glibc will also be very difficult. What I want:
Configuring the darwin system so that it only uses the GNU C runtime libraries, along with gcc.
I can specify more if needed.
I still haven't found a solution to this problem, but that is irrelevant now. The segmentation fault can only be reproduced in the 64 bit darwin libc. Furthermore, running the program with valgrind on the darwin suppresses the fault.
This led me to the conclusion that the problem is in the code, rather than the libraries. The code was not mine at the beginning, hence it's not my problem anymore. The program in some stage tries to access unallocated memory and my guess is that using glibc somehow compensates this error.

Resources