[PATCH] [ELF] LLD does not create a record in the .dynsym if a strong symbol defined in the executable file replaces a weak symbol from a shared library.

Simon Atanasyan simon at atanasyan.com
Tue Aug 5 06:21:46 PDT 2014


Hi Bigcheese, shankarke, ruiu,

LLD does not create a record in the .dynsym if a strong symbol defined in the executable file replaces a weak symbol from a shared library. This bug affects all ELF architectures and leads to segfault:
 
  % cat foo.c
  extern int __attribute__((weak)) flag;
  int foo() { return flag; }

  % cat main.c
  int flag = 1;
  int foo();
  int main() { return foo() == 1 ? 0 : -1; }

  % clang -c -fPIC foo.c main.c
  % lld -flavor gnu -target x86_64 -shared -o libfoo.so ... foo.o
  % lld -flavor gnu -target x86_64 -o a.out ... main.o libfoo.so
  % ./a.out
  Segmentation fault

The problem is in the `Resolver` class. We lose all information about coalesced symbols after the `Resolver::resolve()` method is finished. Besides, the symbol resolving code is target independent and we need to keep it in this state.

The patch solves the problem by introducing a new class `ELFResolver` which is inherited from the `Resolver` class. In this new class we override the `checkUndefines()` method, iterate over atoms and configure dynamic export settings for `ELFDefinedAtom` when necessary.

The `Driver` class requests an instance if the `Resolver` class from the `LinkingContext`. For non-ELF targets we continue to use `Resolver` class. For ELF targets we create an instance of `ELFResolver`.

http://reviews.llvm.org/D4789

Files:
  include/lld/Core/LinkingContext.h
  include/lld/Core/Resolver.h
  include/lld/ReaderWriter/ELFLinkingContext.h
  lib/Core/LinkingContext.cpp
  lib/Driver/Driver.cpp
  lib/ReaderWriter/ELF/Atoms.h
  lib/ReaderWriter/ELF/DefaultTargetHandler.h
  lib/ReaderWriter/ELF/ELFLinkingContext.cpp
  lib/ReaderWriter/ELF/ELFResolver.h
  lib/ReaderWriter/ELF/TargetHandler.h
  test/elf/X86_64/dynsym-weak.test
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4789.12194.patch
Type: text/x-patch
Size: 12206 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140805/8b0a1262/attachment.bin>


More information about the llvm-commits mailing list