Hello,
I had a complex client running with DR 8.0.0-1 for a while now with no issues at all. Recently though, I have had to move my work to another server, running the following:
- Ubuntu 22.04
- kernel 5.15.0-79-generic
- gcc/g++ 11.4.0
- libc 2.35
- DR 8.0.0-1 (though similar issues arise on DR 10.0.0)
My older system was:
- Ubuntu 21.04
- kernel 5.11.0-49-generic
- gcc/g++ 10.3.0
- libc 2.33
- DR 8.0.0-1
For some reason, the client which was working fine on an Ubuntu 21.04 system (Unfortunately, I no longer have access to the other system info) now suffers from segmentation faults in libc calls!
I was able to generate a minimal example, which works fine on the old system, but fails in the new. This failure only happens when I run DR with the -debug flag.
```cpp
#include <iostream>
#include <dr_api.h>
DR_EXPORT void dr_client_main(client_id_t id, int argc, const char** argv)
{
std::cout << "Test1\n";
std::cerr << "Test1\n";
std::cout << "Test2\n";
}
```
```cmake
cmake_minimum_required(VERSION 3.22)
project(Test)
set(CMAKE_CXX_STANDARD 20)
if (NOT DEFINED ENV{DYNAMORIO_PATH})
message( SEND_ERROR "DYNAMORIO_PATH must be defined and point to DynamoRIO" )
endif()
find_package(DynamoRIO REQUIRED PATHS $ENV{DYNAMORIO_PATH}/)
add_library(Test SHARED Test.cpp)
configure_DynamoRIO_client(Test)
```
```running
/path/to/DR8.0.0-1/bin64/drrun -debug -c libTest.so -- /path/to/apsp 1 256 16
```
```output
<log dir=/tools/DynamoRIO/DynamoRIO-Linux-8.0.0-1/bin64/../logs/apsp.149430.00000000>
<Starting application /work/mewais/DCArch/DCSim/Bench/CRONO/apps/apsp/apsp (149430)>
<Initial options = -no_dynamic_options -loglevel 4 -client_lib '/home/mewais/Test/Build/libTest.so;0;' -code_api -stack_size 56K -signal_stack_size 32K -max_elide_jmp 0 -max_elide_call 0 -early_inject -emulate_brk -no_inline_ignored_syscalls -native_exec_default_list '' -no_native_exec_managed_code -no_indcall2direct >
<Paste into GDB to debug DynamoRIO clients:
set confirm off
add-symbol-file '/home/mewais/Test/Build/libTest.so' 0x00007f107b97c0a0
add-symbol-file '/tools/DynamoRIO/DynamoRIO-Linux-8.0.0-1/lib64/debug/libdynamorio.so' 0x0000000071040fe0
add-symbol-file '/lib/x86_64-linux-gnu/libstdc++.so.6' 0x00007f10bf5aa420
add-symbol-file '/lib/x86_64-linux-gnu/libm.so.6' 0x00007f10bf8833a0
add-symbol-file '/lib/x86_64-linux-gnu/libc.so.6' 0x00007f10bf0e9700
add-symbol-file '/usr/lib64/ld-linux-x86-64.so.2' 0x00007f10bf83a090
add-symbol-file '/lib/x86_64-linux-gnu/libgcc_s.so.1' 0x00007f10bf81a660
>
<(1+x) Handling our fault in a TRY at 0x000000007129f6b2>
<Application /work/mewais/DCArch/DCSim/Bench/CRONO/apps/apsp/apsp (149430). Tool internal crash at PC 0x00007f10bf151a7f. Please report this at your tool's issue tracker. Program aborted.
Received SIGSEGV at pc 0x00007f10bf151a7f in thread 149430
Base: 0x0000000071000000
Registers:eax=0x0000000000000000 ebx=0x0000000000000006 ecx=0x00007f0ffb9f7700 edx=0x0000000000000006
esi=0x00007f0ffba3bc80 edi=0x0000000000000001 esp=0x00007ffc83b13078 ebp=0x00007f0ffba3bc80
r8 =0x0000000000000000 r9 =0x00007f0ffba3c000 r10=0x00007ffc83b12240 r11=0x0000000000000246
r12=0x0000000000000006 r13=0x00007f10bf2db780 r14=0x00007f10bf2d7600 r15=0x00007f10bf2d6a00
eflags=0x0000000000010246
version 8.0.0, build 1
-no_dynamic_options -loglevel 4 -client_lib '/home/mewais/Test/Build/libTest.so;0;' -code_api -stack_size 56K -signal_stack_size 32K -max_elide_jmp 0 -max_elide_call 0 -early_inject -emulate_brk -no_inline_ignored_syscalls -native_exec_default_list '' -no_native_exec_managed_code -no_indcall2direct
0x00007f0ffba3bc80 0xcdcdcdcdcdcdcdcd>
```
```gdb
(gdb) c
Continuing.
<(1+x) Handling our fault in a TRY at 0x000000007129f6b2>
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7732a7f in __GI___pthread_enable_asynccancel () at ./nptl/cancellation.c:34
34 ./nptl/cancellation.c: No such file or directory.
(gdb) where
#0 0x00007ffff7732a7f in __GI___pthread_enable_asynccancel () at ./nptl/cancellation.c:34
#1 0x00007ffff77b6a57 in __GI___libc_write (nbytes=6, buf=0x7fff33fdfc80, fd=1) at ../sysdeps/unix/sysv/linux/write.c:26
#2 __GI___libc_write (fd=1, buf=0x7fff33fdfc80, nbytes=6) at ../sysdeps/unix/sysv/linux/write.c:24
#3 0x00007ffff772cf6d in _IO_new_file_write (f=0x7ffff78bc780, data=0x7fff33fdfc80, n=6) at ./libio/fileops.c:1180
#4 0x00007ffff772ea61 in new_do_write (to_do=6, data=0x7fff33fdfc80 "Test1\n", '\315' <repeats 193 times>, <incomplete sequence \315>..., fp=0x7ffff78bc780) at ./libio/libioP.h:947
#5 _IO_new_do_write (to_do=6, data=0x7fff33fdfc80 "Test1\n", '\315' <repeats 193 times>, <incomplete sequence \315>..., fp=0x7ffff78bc780) at ./libio/fileops.c:425
#6 _IO_new_do_write (fp=fp@entry=0x7ffff78bc780, data=0x7fff33fdfc80 "Test1\n", '\315' <repeats 193 times>, <incomplete sequence \315>..., to_do=6) at ./libio/fileops.c:422
#7 0x00007ffff772ef43 in _IO_new_file_overflow (f=0x7ffff78bc780, ch=10) at ./libio/fileops.c:783
#8 0x00007ffff772feb4 in __GI__IO_default_xsputn (n=<optimized out>, data=<optimized out>, f=<optimized out>) at ./libio/genops.c:399
#9 __GI__IO_default_xsputn (f=f@entry=0x7ffff78bc780, data=<optimized out>, n=n@entry=6) at ./libio/genops.c:370
#10 0x00007ffff772d79b in _IO_new_file_xsputn (n=6, data=<optimized out>, f=<optimized out>) at ./libio/fileops.c:1264
#11 _IO_new_file_xsputn (f=0x7ffff78bc780, data=<optimized out>, n=6) at ./libio/fileops.c:1196
#12 0x00007ffff7722057 in __GI__IO_fwrite (buf=0x7fffb3f21000, size=1, count=6, fp=0x7ffff78bc780) at ./libio/libioP.h:947
#13 0x00007ffff7c25b65 in do_forward_check_eflags (inst=0x7ffff7d13da0, eflags=32767, eflags_valid=4157678696, eflags_invalid=0, state=0x0) at /home/travis/build/DynamoRIO/dynamorio/core/arch/x86/optimize.c:1862
Backtrace stopped: previous frame inner to this frame (corrupt stack?)
(gdb) c
Continuing.
<Application /work/mewais/DCArch/DCSim/Bench/CRONO/apps/apsp/apsp (149399). Tool internal crash at PC 0x00007ffff7732a7f. Please report this at your tool's issue tracker. Program aborted.
Received SIGSEGV at pc 0x00007ffff7732a7f in thread 149399
Base: 0x0000000071000000
Registers:eax=0x0000000000000000 ebx=0x0000000000000006 ecx=0x00007fff33f9b700 edx=0x0000000000000006
esi=0x00007fff33fdfc80 edi=0x0000000000000001 esp=0x00007fffffffcd08 ebp=0x00007fff33fdfc80
r8 =0x0000000000000000 r9 =0x00007fff33fe0000 r10=0x00007fffffffbed0 r11=0x0000000000000246
r12=0x0000000000000006 r13=0x00007ffff78bc780 r14=0x00007ffff78b8600 r15=0x00007ffff78b7a00
eflags=0x0000000000010246
version 8.0.0, build 1
-no_dynamic_options -loglevel 4 -client_lib '/home/mewais/Test/Build/libTest.so;0;' -code_api -stack_size 56K -signal_stack_size 32K -max_elide_jmp 0 -max_elide_call 0 -early_inject -emulate_brk -no_inline_ignored_syscalls -native_exec_default_list '' -no_native_exec_managed_code -no_indcall2direct
0x00007fff33fdfc80 0xcdcdcdcdcdcdcdcd>
[Inferior 1 (process 149399) exited with code 0377]
```
In my real client, the issues arise even without use of the -debug flag. I assume this is because my client is much more complex and more heavily dependent on the standard C++ library either directly or through third party libs.