[PATCH] D59275: [ELF] Do not emit weak-undef symbols in .dynsym if config is -static -pie.

Peter Collingbourne via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 12 15:58:59 PDT 2019


pcc added a comment.

It looks like our handling of weak undef in executables is a little unusual. At least it does not match the other two linkers. Taking `ELF/weak-undef.s` as an example:

  $ ld.lld ra/obj/lld/test/ELF/Output/weak-undef.s.tmp.o -o ra/obj/lld/test/ELF/Output/weak-undef.s.tmp -pie 
  $ nm -D ra/obj/lld/test/ELF/Output/weak-undef.s.tmp
                   w foo
  $ ld.gold ra/obj/lld/test/ELF/Output/weak-undef.s.tmp.o -o ra/obj/lld/test/ELF/Output/weak-undef.s.tmp -pie 
  $ nm -D ra/obj/lld/test/ELF/Output/weak-undef.s.tmp
  nm: ra/obj/lld/test/ELF/Output/weak-undef.s.tmp: no symbols
  $ ld.bfd ra/obj/lld/test/ELF/Output/weak-undef.s.tmp.o -o ra/obj/lld/test/ELF/Output/weak-undef.s.tmp -pie 
  $ nm -D ra/obj/lld/test/ELF/Output/weak-undef.s.tmp
  nm: ra/obj/lld/test/ELF/Output/weak-undef.s.tmp: no symbols
  
  $ echo 'void foo() {}' | clang -shared -o foo.so -x c -
  $ ld.bfd ra/obj/lld/test/ELF/Output/weak-undef.s.tmp.o -o ra/obj/lld/test/ELF/Output/weak-undef.s.tmp -pie foo.so
  $ nm -D ra/obj/lld/test/ELF/Output/weak-undef.s.tmp |grep foo
                   w foo
  $ ld.gold ra/obj/lld/test/ELF/Output/weak-undef.s.tmp.o -o ra/obj/lld/test/ELF/Output/weak-undef.s.tmp -pie foo.so
  $ nm -D ra/obj/lld/test/ELF/Output/weak-undef.s.tmp |grep foo
                   w foo
  $ ld.lld ra/obj/lld/test/ELF/Output/weak-undef.s.tmp.o -o ra/obj/lld/test/ELF/Output/weak-undef.s.tmp -pie foo.so
  $ nm -D ra/obj/lld/test/ELF/Output/weak-undef.s.tmp |grep foo
                   w foo
  
  $ echo 'void bar() {}' | clang -shared -o bar.so -x c -
  $ ld.bfd ra/obj/lld/test/ELF/Output/weak-undef.s.tmp.o -o ra/obj/lld/test/ELF/Output/weak-undef.s.tmp -pie bar.so
  $ nm -D ra/obj/lld/test/ELF/Output/weak-undef.s.tmp |grep foo
  $ ld.gold ra/obj/lld/test/ELF/Output/weak-undef.s.tmp.o -o ra/obj/lld/test/ELF/Output/weak-undef.s.tmp -pie bar.so
  $ nm -D ra/obj/lld/test/ELF/Output/weak-undef.s.tmp |grep foo
  $ ld.lld ra/obj/lld/test/ELF/Output/weak-undef.s.tmp.o -o ra/obj/lld/test/ELF/Output/weak-undef.s.tmp -pie bar.so
  $ nm -D ra/obj/lld/test/ELF/Output/weak-undef.s.tmp |grep foo
                   w foo

So what the other linkers appear to implement is that a shared object defining the weak symbol must be available at link time in order for the symbol to be resolved at runtime, which is essentially what you've implemented here for static PIE. Maybe we should do the same thing for other executables?



================
Comment at: lld/test/ELF/Inputs/static-pie-weak-undef.s:1
+        .global main
+main:
----------------
I don't think you need this test file.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59275





More information about the llvm-commits mailing list