boostorg / stacktrace

C++ library for storing and printing backtraces.
https://boost.org/libs/stacktrace
424 stars 71 forks source link

Possibility to print decodable addresses with ASLR anabled #180

Open McCzarny opened 1 week ago

McCzarny commented 1 week ago

Hello, I was trying to use the library to log backtraces so they could be later decoded using the binary. I've noticed that when Address Space Layout Randomization is enabled, I'm getting different address on each run:

$ ./build/Debug/boost-stacktrace-address-randomization 
 0# 0x000055655F1BB761 in ./build/Debug/boost-stacktrace-address-randomization
 1# 0x000055655F1BB7DE in ./build/Debug/boost-stacktrace-address-randomization
 2# 0x000055655F1BB7EE in ./build/Debug/boost-stacktrace-address-randomization
 3# 0x00007FDBA333FD90 in /lib/x86_64-linux-gnu/libc.so.6
 4# __libc_start_main in /lib/x86_64-linux-gnu/libc.so.6
 5# 0x000055655F1BB645 in ./build/Debug/boost-stacktrace-address-randomization

$ ./build/Debug/boost-stacktrace-address-randomization 
 0# 0x0000560C98DD3761 in ./build/Debug/boost-stacktrace-address-randomization
 1# 0x0000560C98DD37DE in ./build/Debug/boost-stacktrace-address-randomization
 2# 0x0000560C98DD37EE in ./build/Debug/boost-stacktrace-address-randomization
 3# 0x00007FAAD04E7D90 in /lib/x86_64-linux-gnu/libc.so.6
 4# __libc_start_main in /lib/x86_64-linux-gnu/libc.so.6
 5# 0x0000560C98DD3645 in ./build/Debug/boost-stacktrace-address-randomization

It seems that I can still decode the addresses if I get /proc/self/maps and subtract the base address from the generated stacktrace. I've noticed that there is a similar logic when addr2line flavor is enabled.

I'm aware that the work on the libarary may be limited because of C++23, but still there is a lot projects where it's easier to use a newer version of boost than upgrade a compiler.

apolukhin commented 5 days ago

If not, is it worth to implement it? I could try to provide the implementation.

Yes, please give it a try