linux - LD_PRELOAD causing segmentation fault in dynamic library loader -
i have written library intended loaded via ld_preload
. on linux systems, causing dynamic library loader segfault during initialisation.
i have simple test case exhibits behaviour, if link -lm
. example:
# works fine gcc -o vecadd.normal -std=c99 vecadd.c -lopencl ld_preload=/path/to/my/library.so ./vecadd.normal # causes segmentation fault gcc -o vecadd.broken -std=c99 vecadd.c -lopencl -lm ld_preload=/path/to/my/library.so ./vecadd.broken
the strange thing libm.so
seems included in both versions: ldd
shows same set of libraries, in different order:
vecadd.normal: linux-vdso.so.1 => (0x00007fffed9ff000) libopencl.so => /usr/lib64/libopencl.so (0x00007f135c9b1000) libc.so.6 => /lib64/libc.so.6 (0x00007f135c61c000) libdl.so.2 => /lib64/libdl.so.2 (0x00007f135c418000) libnuma.so.1 => /usr/lib64/libnuma.so.1 (0x00007f135c20f000) libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00007f135bf08000) libm.so.6 => /lib64/libm.so.6 (0x00007f135bc84000) libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f135ba6e000) /lib64/ld-linux-x86-64.so.2 (0x00007f135cbd4000) vecadd.broken: linux-vdso.so.1 => (0x00007fff25c74000) libopencl.so => /usr/lib64/libopencl.so (0x00007fb8c071e000) libm.so.6 => /lib64/libm.so.6 (0x00007fb8c0499000) libc.so.6 => /lib64/libc.so.6 (0x00007fb8c0105000) libdl.so.2 => /lib64/libdl.so.2 (0x00007fb8bff01000) libnuma.so.1 => /usr/lib64/libnuma.so.1 (0x00007fb8bfcf7000) libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00007fb8bf9f1000) libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007fb8bf7db000) /lib64/ld-linux-x86-64.so.2 (0x00007fb8c0941000)
google directed me ld_debug
, points libm.so
part of problem:
14143: symbol=fma; lookup in file=./vecadd.broken [0] 14143: symbol=fma; lookup in file=/path/to/my/library.so [0] 14143: symbol=fma; lookup in file=/usr/lib64/libopencl.so [0] 14143: symbol=fma; lookup in file=/lib64/libm.so.6 [0] 14143: binding file /path/to/my/library.so [0] /lib64/libm.so.6 [0]: normal symbol `fma' [glibc_2.2.5] segmentation fault (core dumped)
unfortunately machines can reproduce problem on don't appear have debug symbols dynamic library loader available (and don't have administrative permissions), gdb doesn't yield useful:
gdb ./vecadd.broken (gdb) set environment ld_preload /path/to/my/library.so (gdb) run starting program: vecadd.broken program received signal sigsegv, segmentation fault. 0x0000000000003dce in ?? () missing separate debuginfos, use: debuginfo-install glibc-2.12-1.132.el6_5.1.x86_64 (gdb) bt #0 0x0000000000003dce in ?? () #1 0x00007fff7f755369 in ?? () #2 0x00007fffffffd840 in ?? () #3 0x00007fff7fde9e91 in _dl_relocate_object () /lib64/ld-linux-x86-64.so.2 #4 0x00007fff7fde18a3 in dl_main () /lib64/ld-linux-x86-64.so.2 #5 0x00007fff7fdf3a0e in _dl_sysdep_start () /lib64/ld-linux-x86-64.so.2 #6 0x00007fff7fddf4a4 in _dl_start () /lib64/ld-linux-x86-64.so.2 #7 0x00007fff7fddeb08 in _start () /lib64/ld-linux-x86-64.so.2 #8 0x0000000000000001 in ?? () #9 0x00007fffffffde01 in ?? () #10 0x0000000000000000 in ?? ()
what's best way go finding root cause of problem?
you can upload own dynamic loader built symbols , call link app, like:
∞ /lib/ld-linux-x86-64.so.2 /bin/echo linked linked
Comments
Post a Comment