[llvm-bugs] [Bug 48681] New: lld --exclude-libs doesn't hide builtins when using LTO

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Jan 7 00:11:27 PST 2021


https://bugs.llvm.org/show_bug.cgi?id=48681

            Bug ID: 48681
           Summary: lld --exclude-libs doesn't hide builtins when using
                    LTO
           Product: lld
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: rprichard at google.com
                CC: llvm-bugs at lists.llvm.org, smithp352 at googlemail.com

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
(https://reviews.llvm.org/D93003 and https://reviews.llvm.org/D93431). I
noticed this bug while checking to see if I had unintentionally changed
anything in the platform build.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210107/e603b946/attachment.html>


More information about the llvm-bugs mailing list