https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91929

            Bug ID: 91929
           Summary: missing inline subroutine information in static build
                    using sin/cos
           Product: gcc
           Version: 9.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: debug
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mail at milianw dot de
  Target Milestone: ---

Hey there,

take the attached C++ code sample and compile it with `g++ -O2 -g -static` to
produce the attached binary. Sampling it with perf produces strange backtraces
even when including inline frames - it seems like the information is simply
lacking from the generated binary? See e.g.:

```
$ addr2line -i -C -f -p -e vector_static_gcc_v9.1.0 -a 418790
0x0000000000418790: __cos_fma at ??:?

$ addr2line -i -C -f -p -e vector_static_gcc_v9.1.0 -a 401572
0x0000000000401572: generate_n<std::back_insert_iterator<std::vector<double> >,
int, main()::<lambda()> > at /usr/include/c++/9.1.0/bits/stl_algo.h:4449
 (inlined by) main at /.../vector.cpp:16
```

Here's a backtrace from GDB showing this odd behavior:

```
(gdb) b __cos_fma
Breakpoint 2 at 0x418790
(gdb) c
Continuing.

Breakpoint 2, 0x0000000000418790 in __cos_fma ()
(gdb) bt
#0  0x0000000000418790 in __cos_fma ()
#1  0x0000000000401573 in
std::generate_n<std::back_insert_iterator<std::vector<double> >, int,
main()::<lambda()> > (__n=100000, __gen=..., 
    __first=...) at /usr/include/c++/9.1.0/new:174
#2  main () at ../../../manual/clients/vector.cpp:16
```

I'm missing inline frames for the lambda and `std::cos<int>` or similar. When
replacing g++ with clang++ 8.0.1 this looks better:

```
(gdb) bt
#0  0x00000000004191d0 in __cos_fma ()
#1  0x0000000000402663 in std::cos<int> (__x=<optimized out>)
    at
/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/9.1.0/../../../../include/c++/9.1.0/cmath:197
#2  main::$_0::operator() (this=<optimized out>) at ./vector.cpp:14
#3  std::generate_n<std::back_insert_iterator<std::vector<double,
std::allocator<double> > >, int, main::$_0> (__first=..., __n=100000, 
    __gen=...) at
/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/9.1.0/../../../../include/c++/9.1.0/bits/stl_algo.h:4450
#4  main () at ./vector.cpp:12
```

Reply via email to