[PATCH] [lld] [ELF] Fix bug in ELFFile::createAtoms() that caused lld to mislink musl

Rafael Auler rafaelauler at gmail.com
Fri Oct 3 13:18:56 PDT 2014

Hi Bigcheese, shankar.easwaran,

When creating the graph edges of the atoms of an ELF file, special care must be
taken with atoms that represent weak symbols. They cannot be the target of any
Reference::kindLayoutAfter edge because they can be merged and point to other
code, screwing up the final layout of the atoms. ELFFile::createAtoms()
correctly handles this corner case. The problem is that createAtoms() assumed
that there can be no zero-sized weak symbols, which is not true. Consider:


In this case, we have two zero-sized weak symbols, my_weak_func1 and
my_weak_func2, and one non-zero weak symbol my_weak_func3. createAtoms() would
correctly handle my_weak_func3, but not the first two symbols. This problem
happens in the musl C library when a zero-sized weak symbol is merged and
screws up the file layout. Since this musl code lives at the finalization hooks,
any C program linked with LLD and musl was correctly executing, but segfaulting
at the end.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D5606.14400.patch
Type: text/x-patch
Size: 619 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20141003/625f0d00/attachment.bin>

More information about the llvm-commits mailing list