WuBingzheng / libleak

detect memory leak by LD_PRELOAD, without changing the target program
249 stars 52 forks source link

backtrace library dependency #19

Open babuveld opened 3 years ago

babuveld commented 3 years ago

Hi,

can you let me know which backtrace library used for linking. Is it a standard linux backtrace library or a third-party library?

WuBingzheng commented 3 years ago

libbacktrace is built-in with GCC at my Ubuntu 16.04. It locates at /usr/lib/gcc/x86_64-linux-gnu/5/libbacktrace.a.

You can get and build it from https://github.com/ianlancetaylor/libbacktrace if your system does not have it.

mjhammel commented 2 years ago

We build for an embedded platform and our gcc 9 build does not generate libbacktrace. So I got it from the above link and built it as a shared lib. We're not seeing any backtraces, just a lot of lines like this:

callstack[1] expires. count=843 size=64/53114 alloc=6633 free=5788

though libleak doesn't seem to complain about libbacktrace in any way. Ctrl-C on the app doesn't generate callback stats.

Is a shared lib okay? ldd on libleak.so finds libbacktrace.so.0 (a symlink to libbacktrace.so). Is a static libbacktrace required for libleak?

mjhammel commented 2 years ago

Follow up: I changed our build so libbacktrace could be built statically and linked by libleak, but still no stack traces are being shown. I also wrote a little leaking program (instead of the big program we're trying to test) to verify the libleak build but still get nothing. We've done this for X86_64 and A8 platforms. I've been told the prebuilt .so binary works, so there must be something I'm not doing correctly in my build - or maybe libleak doesn't work with gcc 9?

ierturk commented 2 years ago

Hi @mjhammel,

I experienced the same problem on ARM, and resolve it as in the following link. It's regarding the CFLAGS for building Libleak.

https://github.com/WuBingzheng/libleak/issues/21#issuecomment-1208562003

Hope this works for you as well.

ierturk

mjhammel commented 2 years ago

I managed to get it working on x86_64 without the suggested compile options. I have not re-tested on A8 because the issue that requested it was resolved before I could complete my testing and I don't have access to those A8 devices now. So I can't say it if it helped for ARM, but I made note of it in our build/wiki and will retest when the opportunity presents itself again.

Thanks @ierturk for the suggestion!

harish-agr commented 1 year ago

I am facing issue while linking libbacktrace with libleak on ARM platform and getting below error. relocation R_ARM_THM_MOVW_ABS_NC against `a local symbol' can not be used when making a shared object

Please find detail when compiling libleak on ARM platform. Before this I have compiled libbacktrace and able to generate library.

@:~/workspace/extra/memtool/memory_leak/libleak$ make arm-linux-gnueabihf-gcc -std=c99 -g -O2 -Wall -fPIC -funwind-tables -mapcs-frame -rdynamic -Ilibwuya -I../libbacktrace/include -rdynamic -Wl,--version-script,exportmap -c -o libleak.o libleak.c CFLAGS='-std=c99 -g -O2 -Wall -fPIC -funwind-tables -mapcs-frame -rdynamic -ffreestanding' make -C libwuya -Wl,--version-script,exportmap make[1]: Entering directory @/workspace/extra/memtool/memory_leak/libleak/libwuya' make[1]: Nothing to be done for 'all'. make[1]: Leaving directory '@/workspace/extra/memtool/memory_leak/libleak/libwuya'

arm-linux-gnueabihf-gcc -shared -o libleak.so libleak.o -Llibwuya -L../libbacktrace/lib -lwuya -lpthread -ldl -lbacktrace

arm-linux-gnueabihf-gcc -shared -o libleak.so libleak.o -Llibwuya -L../libbacktrace/lib -lwuya -lpthread -ldl -lbacktrace /opt/toolchains/stbgcc-4.8-1.5/lib/gcc/arm-linux-gnueabihf/4.8.5/../../../../arm-linux-gnueabihf/bin/ld: ../libbacktrace/lib/libbacktrace.a(fileline.o): relocation R_ARM_THM_MOVW_ABS_NC against `a local symbol' can not be used when making a shared object; recompile with -fPIC ../libbacktrace/lib/libbacktrace.a: error adding symbols: Bad value collect2: error: ld returned 1 exit status Makefile:15: recipe for target 'libleak.so' failed make: *** [libleak.so] Error 1

Thanks Harish