namhyung / uftrace

Function graph tracer for C/C++/Rust/Python
https://uftrace.github.io/slide/
GNU General Public License v2.0
3.06k stars 474 forks source link

t168_lib_nested.py gets segfault in i386 build #1439

Open honggyukim opened 2 years ago

honggyukim commented 2 years ago

The test t168_lib_nested.py shows segfault in i386 build.

$ ./configure --arch=i386
$ make -j
$ cd tests
$ ./runtest.py -vdp -O0 168
Start 1 tests with 1 worker
Test case                 pg
------------------------: O0
build command for library: gcc -o libabc_test_lib.so -fno-inline -fno-builtin -fno-ipa-cp -fno-omit-frame-pointer -D_FORTIFY_SOURCE=0 -m32    -shared -fPIC s-lib.c
build command for library: g++ -o libfoo.so -fno-inline -fno-builtin -fno-ipa-cp -fno-omit-frame-pointer -D_FORTIFY_SOURCE=0 -m32    -shared -fPIC s-libfoo.cpp
build command for executable: gcc -o t-nest-libcall -fno-inline -fno-builtin -fno-ipa-cp -fno-omit-frame-pointer -D_FORTIFY_SOURCE=0 -m32  -pg -O0  s-nest-libcall.c    -Wl,-rpath,$ORIGIN -L.  -labc_test_lib -lfoo
test command: /home/honggyu/work/uftrace/uftrace live --no-pager --no-event --libmcount-path=/home/honggyu/work/uftrace -D3 --nest-libcall t-nest-libcall
[allocate_shmem_buffer:36] sess_id = /uftrace-3d792d1aa9a08b10-9593-000
WARN: child terminated by signal: 11: Segmentation fault
WARN: cannot open record data: /tmp/uftrace-live-URNYsx: No data available
168 lib_nested          : SG

The segfault shows at this location.

  27│ static struct mcount_shmem_buffer *allocate_shmem_buffer(char *sess_id, size_t size,
  28│                                                          int tid, int idx)
  29│ {
  30│         int fd;
  31│         int saved_errno = 0;
  32│         struct mcount_shmem_buffer *buffer = NULL;
  33│
  34│         snprintf(sess_id, size, SHMEM_SESSION_FMT, mcount_session_name(), tid, idx);
  35│
  36├───────> fd = shm_open(sess_id, O_RDWR | O_CREAT | O_TRUNC, 0600);
  37│         if (fd < 0) {
  38│                 saved_errno = errno;
  39│                 pr_dbg("failed to open shmem buffer: %s\n", sess_id);
  40│                 goto out;
  41│         }

The backtrace is here.

(gdb) bt
#0  0xf7d756ab in shm_open (name=0xffffc341 "uftrace-3fc09aaa37d78589-9778-000", oflag=578, mode=384) at ../sysdeps/posix/shm_open.c:36
#1  0xf7fa1542 in allocate_shmem_buffer (sess_id=sess_id@entry=0xffffc340 "/uftrace-3fc09aaa37d78589-9778-000", tid=tid@entry=9778, idx=idx@entry=0, size=128) at /home/honggyu/work/uftrace/libmcount/record.c:37
#2  0xf7fa1ec6 in prepare_shmem_buffer (mtdp=0xf7a096f0) at /home/honggyu/work/uftrace/libmcount/record.c:80
#3  0xf7f999ce in mcount_prepare () at /home/honggyu/work/uftrace/libmcount/mcount.c:790
#4  0xf7f9dec5 in __plthook_entry (regs=0xffffc4d4, module_id=4160739728, child_idx=4, ret_addr=0xffffc4ec) at /home/honggyu/work/uftrace/libmcount/plthook.c:781
#5  plthook_entry (ret_addr=0xffffc4ec, child_idx=32, module_id=4160739728, regs=0xffffc4d4) at /home/honggyu/work/uftrace/libmcount/plthook.c:935
#6  0xf7fb6f66 in plt_hooker () at /home/honggyu/work/uftrace/arch/i386/plthook.S:30
honggyukim commented 2 years ago

The same segfault shows in test 192 as well for the same problem in --nest-libcall.

168 lib_nested          : SG SG SG SG SG SG SG SG SG SG
192 lib_name            : SG SG SG SG SG SG SG SG SG SG
namhyung commented 2 years ago

From a quick glance, I cannot find what's wrong. The session id seems valid...

honggyukim commented 2 years ago

I also don't have an idea why it gets crashed.