Sometimes you want to determine if a particular symbol is used in your current execution environment when debugging. (When you want to hook a specific function with LD_PRELOAD, etc. => Reference: Replace printf later with LD_PRELOAD --Qiita)
The investigation method in that case is summarized.
Basically, I just use ldd and readelf, but I made it a tool because it was a big deal.
elf_symbol_searcher.sh
#!/bin/bash
APP=$1
SYMBOL=$2
LIST=$(echo $APP; ldd $APP \
| grep -v -E 'ld-linux*.so' \
| grep -v 'linux-vdso.so' \
| grep -v 'linux-gate.so' \
| awk '{print $3}')
for f in $LIST
do
echo $f
readelf -s -W $f | grep $SYMBOL
done
I'm getting the dependent libraries with ldd, but ld-linux * .so and Linux Virtual Dynamic Shared Objects (Reference library / l-lpic1-102-3 /)) is excluded.
You can get the symbol with nm, but you can't see the symbol if it is strip, so we are using readelf this time.
The execution example is as follows.
This time, the target is / usr / bin / weston, and the search target is ʻeglSwapBuffers`.
Execution result
$ ./elf_symbol_searcher.sh /usr/bin/weston eglSwapBuffers
/usr/bin/weston
166: 0000000000000000 0 FUNC GLOBAL DEFAULT UND eglSwapBuffers
/usr/lib/x86_64-linux-gnu/libwayland-server.so.0
/usr/lib/x86_64-linux-gnu/libpixman-1.so.0
/usr/lib/x86_64-linux-gnu/mesa-egl/libEGL.so.1
180: 0000000000006fb0 380 FUNC GLOBAL DEFAULT 11 eglSwapBuffersRegionNOK
187: 0000000000009850 339 FUNC GLOBAL DEFAULT 11 eglSwapBuffers
235: 00000000000079e0 427 FUNC GLOBAL DEFAULT 11 eglSwapBuffersWithDamageEXT
/usr/lib/x86_64-linux-gnu/mesa-egl/libGLESv2.so.2
/usr/lib/x86_64-linux-gnu/libxkbcommon.so.0
/lib/x86_64-linux-gnu/libdl.so.2
/lib/x86_64-linux-gnu/libm.so.6
/lib/x86_64-linux-gnu/libc.so.6
/usr/lib/x86_64-linux-gnu/libffi.so.6
/lib/x86_64-linux-gnu/librt.so.1
/lib/x86_64-linux-gnu/libpthread.so.0
/usr/lib/x86_64-linux-gnu/libX11-xcb.so.1
/usr/lib/x86_64-linux-gnu/libX11.so.6
/usr/lib/x86_64-linux-gnu/libxcb-dri2.so.0
/usr/lib/x86_64-linux-gnu/libxcb-xfixes.so.0
/usr/lib/x86_64-linux-gnu/libxcb.so.1
/usr/lib/x86_64-linux-gnu/libwayland-client.so.0
/usr/lib/x86_64-linux-gnu/libgbm.so.1
/usr/lib/x86_64-linux-gnu/libdrm.so.2
/usr/lib/x86_64-linux-gnu/libglapi.so.0
/usr/lib/x86_64-linux-gnu/libXau.so.6
/usr/lib/x86_64-linux-gnu/libXdmcp.so.6
It's very simple, but I was able to find out that there are symbols in libEGL, which implements weston and ʻeglSwapBuffers` in the body.
The script is also published below. (I plan to write it in python to make it a little easier to use) https://github.com/koara-local/elf_symbol_searcher
TODO
The above can also be used for debugging purposes, but it would be nice if you could search in a little more detail.
Such
Linux 101 Exam Preparation: Managing Shared Libraries
Recommended Posts