<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 - lld --exclude-libs doesn't hide builtins when using LTO"
   href="https://bugs.llvm.org/show_bug.cgi?id=48681">48681</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>lld --exclude-libs doesn't hide builtins when using LTO
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>lld
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>All Bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>rprichard@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, smithp352@googlemail.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Android uses --exclude-libs to hide symbols from the builtins and unwinder
libraries (e.g. libclang_rt.builtins-aarch64-android.a, 
libgcc{,_real,_stripped}.a, libunwind_llvm.a, etc). When a symbol in one of
these excluded libraries isn't referenced by any LLVM IR input file, but is
referenced after the link-time compile step, then --exclude-libs fails to hide
the symbol.

Test script:

    #!/bin/bash
    set -e

    LLVM=/x/llvm-upstream/stage1/bin
    CC="$LLVM/clang -target x86_64-linux-gnu"
    AR="$LLVM/llvm-ar"

    cat >archive_func.c <<EOF
      void __divti3() {}
    EOF

    cat >dso_func.c <<EOF
      __int128 dso_func(__int128 x, __int128 y) { return x / y; }
    EOF

    $CC archive_func.c -fpic -c
    rm -fr libarchive.a
    $AR rcs libarchive.a archive_func.o

    $CC -flto -c dso_func.c -fpic
    $CC -flto -fuse-ld=lld -nostdlib dso_func.o -shared -o libdso.so
$PWD/libarchive.a  -Wl,--exclude-libs,libarchive.a -Wl,-y,__divti3

    $LLVM/llvm-readelf --dyn-syms -W libdso.so

Output:

    $ ./test.sh
    /x/mess/libarchive.a: lazy definition of __divti3
    lto.tmp: reference to __divti3
    /x/mess/libarchive.a(archive_func.o): definition of __divti3

    Symbol table '.dynsym' contains 3 entries:
       Num:    Value          Size Type    Bind   Vis       Ndx Name
         0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT   UND 
         1: 0000000000001370     6 FUNC    GLOBAL DEFAULT     8 __divti3
         2: 0000000000001380    99 FUNC    GLOBAL DEFAULT     8 dso_func

I expected __divti3 to be hidden (and not appear in the `llvm-readelf
--dyn-syms` output). Removing the -flto argument when compiling dso_func.c (or
adding it when compiling archive_func.c) results in the expected output.

Both the Android platform and the NDK use --exclude-libs on builtins, but I'm
working on patches to instead mark the symbols in the archives hidden
(<a href="https://reviews.llvm.org/D93003">https://reviews.llvm.org/D93003</a> and <a href="https://reviews.llvm.org/D93431">https://reviews.llvm.org/D93431</a>). I
noticed this bug while checking to see if I had unintentionally changed
anything in the platform build.</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>