[PATCH] D101996: [LLD] Improve reporting unresolved symbols in shared libraries

Jessica Clarke via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 2 21:16:07 PST 2021


jrtc27 added a comment.

This breaks the following (somewhat stupid, but simple) test case:

  diff --git a/lld/test/ELF/Inputs/allow-shlib-undefined-weak-def.s b/lld/test/ELF/Inputs/allow-shlib-undefined-weak-def.s
  new file mode 100644
  index 000000000000..f88b47c5aacb
  --- /dev/null
  +++ b/lld/test/ELF/Inputs/allow-shlib-undefined-weak-def.s
  @@ -0,0 +1,4 @@
  +.data
  +.globl foo
  +foo:
  +  .long 0
  diff --git a/lld/test/ELF/Inputs/allow-shlib-undefined-weak-ref.s b/lld/test/ELF/Inputs/allow-shlib-undefined-weak-ref.s
  new file mode 100644
  index 000000000000..45dc0b627145
  --- /dev/null
  +++ b/lld/test/ELF/Inputs/allow-shlib-undefined-weak-ref.s
  @@ -0,0 +1,6 @@
  +.weak foo
  +.globl ref_get_foo
  +ref_get_foo:
  +  movq foo at GOTPCREL(%rip), %rax
  +  movl (%rax), %eax
  +  retq
  diff --git a/lld/test/ELF/Inputs/allow-shlib-undefined-weak-wrap.s b/lld/test/ELF/Inputs/allow-shlib-undefined-weak-wrap.s
  new file mode 100644
  index 000000000000..792f5995776f
  --- /dev/null
  +++ b/lld/test/ELF/Inputs/allow-shlib-undefined-weak-wrap.s
  @@ -0,0 +1,5 @@
  +.globl wrap_get_foo
  +wrap_get_foo:
  +  movq foo at GOTPCREL(%rip), %rax
  +  movl (%rax), %eax
  +  retq
  diff --git a/lld/test/ELF/allow-shlib-undefined-weak.s b/lld/test/ELF/allow-shlib-undefined-weak.s
  new file mode 100644
  index 000000000000..e87390ff22d3
  --- /dev/null
  +++ b/lld/test/ELF/allow-shlib-undefined-weak.s
  @@ -0,0 +1,27 @@
  +# REQUIRES: x86
  +
  +## Verify that in the following case:
  +##
  +##   %t
  +##   +- %t-ref.so (weak reference to foo)
  +##   +- %t-wrap.so (non-weak reference to foo)
  +##      +- %t-def.so (defines foo)
  +##
  +## we don't report that foo is undefined in %t-ref.so when linking %t.
  +
  +# RUN: llvm-mc -filetype=obj -triple=x86_64 \
  +# RUN:   %p/Inputs/allow-shlib-undefined-weak-ref.s -o %t-ref.o
  +# RUN: llvm-mc -filetype=obj -triple=x86_64 \
  +# RUN:   %p/Inputs/allow-shlib-undefined-weak-def.s -o %t-def.o
  +# RUN: llvm-mc -filetype=obj -triple=x86_64 \
  +# RUN:   %p/Inputs/allow-shlib-undefined-weak-wrap.s -o %t-wrap.o
  +# RUN: ld.lld -shared %t-ref.o -o %t-ref.so
  +# RUN: ld.lld -shared %t-def.o -o %t-def.so
  +# RUN: ld.lld -shared %t-wrap.o %t-def.so -o %t-wrap.so
  +
  +# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o
  +# RUN: ld.lld %t.o %t-wrap.so %t-ref.so -o %t
  +
  +.globl _start
  +_start:
  +  callq wrap_get_foo at PLT

The test ends up failing with:

  .../tools/lld/test/ELF/Output/allow-shlib-undefined-weak.s.tmp-ref.so: undefined reference to foo [--no-allow-shlib-undefined]

which is bogus, because allow-shlib-undefined-weak.s.tmp-ref.so uses a weak reference, and so it being undefined is totally valid, and because the symbol is defined. If the symbol is instead defined in the executable, or not defined at all, the error goes away, it's specifically when defined in a different library present at link time.

A FreeBSD port hit this regression and now fails to build with LLD 13.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D101996/new/

https://reviews.llvm.org/D101996



More information about the llvm-commits mailing list