<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - After r337339 (addrsig support), clang can emit unnecessary __gxx_personality_v0 references"
   href="https://bugs.llvm.org/show_bug.cgi?id=38506">38506</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>After r337339 (addrsig support), clang can emit unnecessary __gxx_personality_v0 references
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>7.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>release blocker
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>new bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>dimitry@andric.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>See also <a href="https://bugs.freebsd.org/230399">https://bugs.freebsd.org/230399</a>

While testing clang 7.0.0 on FreeBSD, we encountered linking errors in various
ports, similar to:

libtool: link: cc -O2 -pipe -O3 -fno-omit-frame-pointer -march=native
-fstack-protector -fexceptions -Wall -Wsign-compare -fstack-protector
-fuse-ld=bfd -o .libs/Gperf-simple Gperf-simple.o 
../src/.libs/libunwind-x86_64.so
/tmp/a/overlay/ports/devel/libunwind/work/libunwind-1.2.1/src/.libs/libunwind.so
../src/.libs/libunwind.so -lgcc_s -llzma -Wl,-rpath -Wl,/usr/local/lib
/usr/lib/libgcc_s.so: undefined reference to `__gxx_personality_v0'
cc: error: linker command failed with exit code 1 (use -v to see invocation)
*** Error code 1

Our libgcc_s.so is actually compiler-rt, with the unwinder from llvm's
libunwind.cpp.

With clang 7.0.0, the assembly output of this file now includes a .addrsig_sym
reference to __gxx_personality_v0:

        .ident  "FreeBSD clang version 7.0.0 (branches/release_70 338892)
(based on LLVM 7.0.0svn)"
        .section        ".note.GNU-stack","",@progbits
        .addrsig
        .addrsig_sym __gxx_personality_v0
        .addrsig_sym
_ZZN9libunwind17LocalAddressSpace18findUnwindSectionsEmRNS_18UnwindInfoSectionsEENUlP12dl_phdr_infomPvE_8__invokeES4_mS5_
        .addrsig_sym _ZN9libunwind17LocalAddressSpace17sThisAddressSpaceE
        .addrsig_sym
_ZN9libunwind13DwarfFDECacheINS_17LocalAddressSpaceEE5_lockE
        .addrsig_sym
_ZN9libunwind13DwarfFDECacheINS_17LocalAddressSpaceEE14_initialBufferE
        .section        .debug_line,"",@progbits
.Lline_table_start0:

This was not the case with clang 6.0.1.  It appears this has started with the
addition of -faddrsig support to the clang frontend, in
<<a href="https://reviews.llvm.org/rL337339">https://reviews.llvm.org/rL337339</a>>.

Minimal test case:

struct a {
  a(int);
};
void f() {
  new a(42);
}

$ clang-r337338 -O2 -S testcase1.cpp -o - | tail -5
        .p2align        2
                                        # -- End function

        .ident  "clang version 7.0.0 (trunk 337338)"
        .section        ".note.GNU-stack","",@progbits

$ clang-r337339 -O2 -S testcase1.cpp -o - | tail -5
        .ident  "clang version 7.0.0 (trunk 337339)"
        .section        ".note.GNU-stack","",@progbits
        .addrsig
        .addrsig_sym __gxx_personality_v0
        .addrsig_sym _Unwind_Resume

Adding -fno-addrsig makes the reference go away:

$ clang-r337339 -O2 -S testcase1.cpp -o - -fno-addrsig | tail -5
        .p2align        2
                                        # -- End function

        .ident  "clang version 7.0.0 (trunk 337339)"
        .section        ".note.GNU-stack","",@progbits

I don't think it's needed to emit this symbol at all?  Specifically in the case
of an unwinder library, it should definitely not have such a reference in
there.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>