[llvm-bugs] [Bug 52004] New: Binding not restored for wrapped symbols when using LTO

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Sep 28 12:56:15 PDT 2021


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

            Bug ID: 52004
           Summary: Binding not restored for wrapped symbols when using
                    LTO
           Product: lld
           Version: unspecified
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: ELF
          Assignee: unassignedbugs at nondot.org
          Reporter: smeenai at fb.com
                CC: i at maskray.me, llvm-bugs at lists.llvm.org,
                    smithp352 at googlemail.com

https://reviews.llvm.org/D33621 changed LTO to mark linker wrapped symbols as
weak, to prevent IPO for them, but the intent was for the linker to restore the
original binding. This got dropped by various changes to the wrapping code, in
particular https://github.com/llvm/llvm-project/commit/99f9e1373ba9 and
https://github.com/llvm/llvm-project/commit/b45c164fc252, so wrapped symbols
now retain the weak binding given by LTO. For example:

$ cat wrap.c
void foo() {}

$ clang -fuse-ld=lld -flto -shared -o libwrap.so -Wl,--wrap,foo wrap.c
$ llvm-readelf --dyn-syms libwrap.so
Symbol table '.dynsym' contains 7 entries:
   Num:    Value          Size Type    Bind   Vis       Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT   UND
     1: 0000000000000000     0 NOTYPE  WEAK   DEFAULT   UND __gmon_start__
     2: 0000000000000000     0 NOTYPE  WEAK   DEFAULT   UND
_ITM_deregisterTMCloneTable
     3: 0000000000000000     0 NOTYPE  WEAK   DEFAULT   UND
_ITM_registerTMCloneTable
     4: 0000000000000000     0 FUNC    WEAK   DEFAULT   UND
__cxa_finalize at GLIBC_2.2.5
     5: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT   UND __wrap_foo
     6: 00000000000015d0     6 FUNC    WEAK   DEFAULT    11 foo

While __wrap_foo is GLOBAL, the original foo has retained the weak binding
given by LTO. Contrast with the non-LTO case:

$ clang -fuse-ld=lld -shared -o libwrap.so -Wl,--wrap,foo wrap.c
$ llvm-readelf --dyn-syms libwrap.so
Symbol table '.dynsym' contains 7 entries:
   Num:    Value          Size Type    Bind   Vis       Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT   UND
     1: 0000000000000000     0 NOTYPE  WEAK   DEFAULT   UND __gmon_start__
     2: 0000000000000000     0 NOTYPE  WEAK   DEFAULT   UND
_ITM_deregisterTMCloneTable
     3: 0000000000000000     0 NOTYPE  WEAK   DEFAULT   UND
_ITM_registerTMCloneTable
     4: 0000000000000000     0 FUNC    WEAK   DEFAULT   UND
__cxa_finalize at GLIBC_2.2.5
     5: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT   UND __wrap_foo
     6: 00000000000015d0     6 FUNC    GLOBAL DEFAULT    11 foo

-- 
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/20210928/dd25d2d2/attachment.html>


More information about the llvm-bugs mailing list