abseil / abseil-cpp

Abseil Common Libraries (C++)
https://abseil.io
Apache License 2.0
15.05k stars 2.62k forks source link

Stack unwinding seems limited to a single frame #1315

Open blackgnezdo opened 2 years ago

blackgnezdo commented 2 years ago

I'm trying to switch from https://github.com/google/glog to abseil for InstallFailureSignalHandler. With the former I was getting a full stack. With absl::InstallFailureSignalHandler({}); I'm getting a terse:

*** SIGSEGV received at time=1667849759 on cpu 5 ***
PC: @           0xfb3fa9  (unknown)  (anonymous namespace)::inducedFailure()
[1]    33171 segmentation fault (core dumped)

This is with abseil 20220623.1, when I used 20210324.1 I was getting more honest diagnostics containing

    @ ... and at least 1 more frames

I looked at the options in FailureSignalHandlerOptions, none of them seem applicable. Is full stack trace on failure possible with Abseil?

derekmauro commented 2 years ago

https://github.com/abseil/abseil-cpp/blob/master/.github/ISSUE_TEMPLATE/00-bug_report.md

This report does not contain sufficient information for us to look into this problem. Please provide all of the requested information from the bug report form.

blackgnezdo commented 2 years ago

Describe the bug

The stack trace rendered by a signal caught via absl::InstallFailureSignalHandler({}) contains just a single frame.

Steps to reproduce the bug

Notice a single frame is printed by the binary whereas gdb prints all three frames:

% bin/a
*** SIGSEGV received at time=1667856423 on cpu 3 ***
PC: @           0x206a76  (unknown)  bar()
[1]    22351 segmentation fault (core dumped)  bin/a
% gdb bin-unwrapped/a.unwrapped
GNU gdb (GDB) 11.1
Reading symbols from bin-unwrapped/a.unwrapped...
(gdb) r
Starting program: bin-unwrapped/a.unwrapped
...
Program received signal SIGSEGV, Segmentation fault.
bar () at a/bar.cpp:2
2     char c = *(static_cast<char*>(0));
(gdb) bt
#0  bar () at a/bar.cpp:2
#1  0x0000000000206a60 in foo () at a/foo.cpp:4
#2  0x0000000000206a4d in main (argc=1, argv=0x7fffffffe3f8) at a/a.cpp:8

What version of Abseil are you using?

20220623.1

What operating system and version are you using

Ubuntu 18.04, using Nix

What compiler and version are you using?

% PATH=/nix/store/4r36p9x75156bcrsxgi82bq2hmbkrb0r-llvm-binutils-wrapper-11.1.0/bin /nix/store/r147h09xzk3450psbxi0sy12fq8lqmzp-gcc-wrapper-10.3.0/bin/g++ --version
g++ (GCC) 10.3.0

What build system are you using?

Nix 2.10 (substantially wrapped and modified)

Additional context

Here's the complete setup:

% for i in a/*cpp; do echo "=== $i" ; cat $i; done
=== a/a.cpp
#include <absl/debugging/failure_signal_handler.h>

extern void foo();
extern char bar();

int main(int argc, char *argv[]) {
  absl::InstallFailureSignalHandler({});  // Using the default options
  foo();
  return bar();
}
=== a/bar.cpp
char bar() {
  char c = *(static_cast<char*>(0));
  return c+c;
}
=== a/foo.cpp
extern char bar();

void foo() {
  bar();
}

The program is built with a custom Nix wrapper which eventually runs these commands under the hood:

% /nix/store/r147h09xzk3450psbxi0sy12fq8lqmzp-gcc-wrapper-10.3.0/bin/g++ -c a/bar.cpp -o /nix/store/jlg9jgd5p5scmcrmk92wdcw2zmba1vqf-a.a.__modules_bar.cpp/bar.o -ffile-prefix-map=/nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/include/= -std=c++20 -ffunction-sections -fdata-sections -Wl,--gc-sections -O0 -g -Wl,--gdb-index -Wall -DDEV_BUILD -I. -I/nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/include

% /nix/store/r147h09xzk3450psbxi0sy12fq8lqmzp-gcc-wrapper-10.3.0/bin/g++ -c a/foo.cpp -o /nix/store/8iq31ggc11cagfi5cf9dlbb2rm2ryi2y-a.a.__modules_foo.cpp/foo.o -ffile-prefix-map=/nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/include/= -std=c++20 -ffunction-sections -fdata-sections -Wl,--gc-sections -O0 -g -Wl,--gdb-index -Wall -DDEV_BUILD -I. -I/nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/include

% /nix/store/r147h09xzk3450psbxi0sy12fq8lqmzp-gcc-wrapper-10.3.0/bin/g++ -c a/a.cpp -o /nix/store/mwr7gwirgd3skx83881p36z555ypsl7k-a.a.__modules_a.cpp/a.o -ffile-prefix-map=/nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/include/= -std=c++20 -ffunction-sections -fdata-sections -Wl,--gc-sections -O0 -g -Wl,--gdb-index -Wall -DDEV_BUILD -I. -I/nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/include

% PATH=/nix/store/4r36p9x75156bcrsxgi82bq2hmbkrb0r-llvm-binutils-wrapper-11.1.0/bin /nix/store/r147h09xzk3450psbxi0sy12fq8lqmzp-gcc-wrapper-10.3.0/bin/g++ -o /nix/store/4zv4brd0vx5lgp40n19ijpvaqxdpsbwz-a.a/bin/a -std=c++20 -ffunction-sections -fdata-sections -Wl,--gc-sections -O0 -g -fuse-ld=lld -Wl,--gdb-index -Wall -DDEV_BUILD -I. -I/nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/include /nix/store/1i6h486aakci7smpi95rbrfbxfg1k1fc-a.a.__modules_a.cpp/a.o /nix/store/8iq31ggc11cagfi5cf9dlbb2rm2ryi2y-a.a.__modules_foo.cpp/foo.o /nix/store/jlg9jgd5p5scmcrmk92wdcw2zmba1vqf-a.a.__modules_bar.cpp/bar.o -Wl,--start-group /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_cordz_sample_token.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_strerror.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_symbolize.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_random_internal_randen.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_examine_stack.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_random_internal_randen_hwaes.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_int128.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_graphcycles_internal.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_hashtablez_sampler.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_flags_reflection.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_stacktrace.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_bad_variant_access.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_leak_check.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_city.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_bad_any_cast_impl.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_random_internal_distribution_test_util.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_spinlock_wait.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_throw_delegate.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_flags_commandlineflag_internal.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_exponential_biased.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_random_seed_gen_exception.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_random_seed_sequences.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_low_level_hash.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_civil_time.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_flags_commandlineflag.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_random_distributions.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_malloc_internal.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_synchronization.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_raw_logging_internal.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_random_internal_pool_urbg.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_demangle_internal.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_periodic_sampler.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_failure_signal_handler.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_cordz_handle.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_cordz_functions.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_str_format_internal.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_flags_config.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_bad_optional_access.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_strings_internal.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_cord_internal.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_flags.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_raw_hash_set.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_flags_parse.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_statusor.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_flags_marshalling.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_cord.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_random_internal_randen_hwaes_impl.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_flags_usage_internal.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_time.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_time_zone.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_base.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_scoped_set_env.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_strings.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_cordz_info.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_flags_internal.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_flags_program_name.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_hash.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_status.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_random_internal_seed_material.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_debugging_internal.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_log_severity.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_flags_private_handle_accessor.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_flags_usage.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_random_internal_randen_slow.a /nix/store/kzlxpff7v14r1sm8gsy2xkpdxn85v913-absl-20220623.1/lib/libabsl_random_internal_platform.a -Wl,--end-group

% /nix/store/7iv8vfrk1gyns0rxhr72h6b1lszg0xgn-patchelf-0.13/bin/patchelf --shrink-rpath /nix/store/4zv4brd0vx5lgp40n19ijpvaqxdpsbwz-a.a/bin-unwrapped/a.unwrapped
blackgnezdo commented 2 years ago

Switching to glog-0.6.0 yields a nicely complete version:

% bin/a
*** Aborted at 1667857676 (unix time) try "date -d @1667857676" if you are using GNU date ***
PC: @                0x0 (unknown)
*** SIGSEGV (@0x0) received by PID 28948 (TID 0x7f86fbe60e40) from PID 0; stack trace: ***
    @     0x7f86fc3ab33e google::(anonymous namespace)::FailureSignalHandler()
    @     0x7f86fbec0c40 (unknown)
    @           0x20189f bar()
    @           0x201893 foo()
    @           0x20187b main
    @     0x7f86fbeac790 __libc_start_main
    @           0x2017aa _start
    @                0x0 (unknown)
blackgnezdo commented 2 years ago

As I was staring at glog output I noticed that it's superior in one more minor way: it prints the address that caused the failure SIGSEGV (@0x0) which is sadly lacking from abseil output.

blackgnezdo commented 2 years ago

I spent a bit more time isolating the issue and it seems to be specific to nix. I used this CMakeLists.txt with my cpp files above.

cmake_minimum_required(VERSION 3.5)

project(my_project)

# Abseil requires C++14
set(CMAKE_CXX_STANDARD 14)
set(ABSL_PROPAGATE_CXX_STD ON)

# Process Abseil's CMake build system
add_subdirectory(abseil-cpp)

add_executable(hello_world a.cpp bar.cpp foo.cpp)

# Declare dependency on the absl::strings library
target_link_libraries(hello_world absl::strings absl::failure_signal_handler)

I ran in two configurations:

  1. Ubuntu-18 with gcc-10 and g++-10 packages
    • CC=gcc-10 CXX=/usr/bin/g++-10 cmake .. && cmake --build . --target hello_world
  2. Nix
    • nix-shell -p gcc cmake
    • CC=$(which gcc) CXX=$(which g++) cmake .. && cmake --build . --target hello_world

The resulting binaries are pretty different:

-rwxr-xr-x 1 greg greg 173048 Nov  8 13:59 build-gcc-10/hello_world
-rwxr-xr-x 1 greg greg 154056 Nov  8 14:02 build-nix/hello_world
blackgnezdo commented 2 years ago

Output of nm in both configurations.

blackgnezdo commented 2 years ago

The failure is easy to reproduce with docker. Complete log