I have compiled various C and C++ source files in attempt to generate async
unwind tables for better stack trace accuracy with asynchronous signals, adding
-fasynchronous-unwind-tables to compile options. I have so far been completely
unable to come up with any example where the option would produce any
difference in the generated binaries, and unwind tables (.eh_frame)
specifically.

For example please compile the following source file foo.cc:

      struct A1 { virtual ~A1(); virtual double foo(void); };
      struct A2 { virtual ~A2(); virtual double bar(void); };
      struct B : A1, A2 { ~B(); virtual double foo(void); };
      A1::~A1() {}
      double A1::foo() { return 3.14; }
      A2::~A2() {}
      double A2::bar() { return 2.17; }
      B::~B() {}
      double B::foo() { return A1::foo() + A2::bar(); }

    with and without -fasynchronous-unwind-tables:

      c++ -fasynchronous-unwind-tables -O2 -fPIC -W -Wall -shared -o libfooa.so
foo.cc
      c++ -O2 -fPIC -W -Wall -shared -o libfoob.so foo.cc

    then compare unwind information:

      for x in a b; do
        objdump -w -x -d libfoo$x.so > foo$x-disasm.txt
        readelf -Wa --debug=frames libfoo$x.so > foo$x-info.txt
      done

      diff -u foo{a,b}-disasm.txt
      --- fooa-disasm.txt       2010-03-23 18:28:46.000000000 +0100
      +++ foob-disasm.txt       2010-03-23 18:28:46.000000000 +0100
      @@ -1,6 +1,6 @@

      -libfooa.so:     file format elf64-x86-64
      -libfooa.so
      +libfoob.so:     file format elf64-x86-64
      +libfoob.so
       architecture: i386:x86-64, flags 0x00000150:
       HAS_SYMS, DYNAMIC, D_PAGED
       start address 0x0000000000000c90

      diff -u foo{a,b}-info.txt  
      (no output)

    note that there is basically no difference at all, and there is
    no unwind info for the thunks, disassembly has:

      0000000000000df0 <_ZN1B3fooEv>:
       df0: 53                      push   %rbx
       df1: 48 89 fb                mov    %rdi,%rbx
       df4: 48 83 c3 08             add    $0x8,%rbx
       df8: 48 83 ec 10             sub    $0x10,%rsp
       dfc: e8 7f fe ff ff          callq  c80 <_zn2a13fo...@plt>
       e01: 48 89 df                mov    %rbx,%rdi
       e04: f2 0f 11 44 24 08       movsd  %xmm0,0x8(%rsp)
       e0a: e8 41 fe ff ff          callq  c50 <_zn2a23ba...@plt>
       e0f: f2 0f 58 44 24 08       addsd  0x8(%rsp),%xmm0
       e15: f2 0f 11 44 24 08       movsd  %xmm0,0x8(%rsp)
       e1b: 48 83 c4 10             add    $0x10,%rsp
       e1f: 5b                      pop    %rbx
       e20: c3                      retq   
       e21: 66 66 66 66 66 66 2e 0f 1f 84 00 00 00 00 00    nopw  
%cs:0x0(%rax,%rax,1)

      0000000000000e30 <_ZThn8_N1BD1Ev>:
       e30: 48 83 c7 f8             add    $0xfffffffffffffff8,%rdi
       e34: eb 0a                   jmp    e40 <_ZN1BD1Ev>
       e36: 66 2e 0f 1f 84 00 00 00 00 00   nopw   %cs:0x0(%rax,%rax,1)

      0000000000000e40 <_ZN1BD1Ev>:
       e40: 48 89 6c 24 f8          mov    %rbp,-0x8(%rsp)
       e45: 48 89 5c 24 f0          mov    %rbx,-0x10(%rsp)
       e4a: 48 83 ec 18             sub    $0x18,%rsp
       [snip]

    and unwind info has a gap at 0xe30, the thunk, and does not describe
    the epilogue at address 0xe1b:

      000000b0 0000001c 000000b4 FDE cie=00000000 pc=00000df0..00000e21
        Augmentation data:     00 00 00 00

        DW_CFA_advance_loc: 1 to 00000df1
        DW_CFA_def_cfa_offset: 16
        DW_CFA_offset: r3 (rbx) at cfa-16
        DW_CFA_advance_loc: 11 to 00000dfc
        DW_CFA_def_cfa_offset: 32
        DW_CFA_nop
        DW_CFA_nop
        DW_CFA_nop

      000000d0 0000001c 000000d4 FDE cie=00000000 pc=00000e40..00000e99
        Augmentation data:     83 00 00 00

        DW_CFA_advance_loc: 14 to 00000e4e
        DW_CFA_def_cfa_offset: 32
        DW_CFA_offset: r3 (rbx) at cfa-24
        DW_CFA_offset: r6 (rbp) at cfa-16
        DW_CFA_nop
        DW_CFA_nop
        DW_CFA_nop
        DW_CFA_nop

I believe the part about missing unwind info for epilogues is a known problem
and patches have been committed to the head. Similarly lack of unwind
information for global ctors and dtors seems to be known. But how about the
missing unwind information for the thunks?

More exactly where should I expect the -fasynchronous-unwind-tables option to
make a difference? Any example code / output available?

The compiler is GCC 4.3.4 with binutils 2.19.1 on RHEL5-derived system.

$ c++ -v
Using built-in specs.
Target: x86_64-unknown-linux-gnu
Configured with: ../configure
--prefix=/build/3jm/slc5_amd64_gcc434/external/gcc/4.3.4
--enable-languages=c,c++,fortran
--with-gmp=/build/3jm/slc5_amd64_gcc434/external/gcc/4.3.4/tmp/gmp
--with-mpfr=/build/3jm/slc5_amd64_gcc434/external/gcc/4.3.4/tmp/mpfr
--enable-shared
Thread model: posix
gcc version 4.3.4 (GCC) 

$ as -v /dev/null
GNU assembler version 2.19.1 (x86_64-unknown-linux-gnu) using BFD version (GNU
Binutils) 2.19.1

$ ld -v 
GNU ld (GNU Binutils) 2.19.1


-- 
           Summary: -fasynchronous-unwind-tables does not seem to do
                    anything
           Product: gcc
           Version: 4.3.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: lat at cern dot ch
 GCC build triplet: x86_64-unknown-linux-gnu
  GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43498

Reply via email to