Page MenuHomePhabricator

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

Authored by rafaelauler on Oct 3 2014, 1:18 PM.

Details

Summary

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:

my_weak_func1:
my_weak_func2:
my_weak_func3:

code

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.

Diff Detail

Event Timeline

rafaelauler updated this revision to Diff 14400.Oct 3 2014, 1:18 PM
rafaelauler retitled this revision from to [lld] [ELF] Fix bug in ELFFile::createAtoms() that caused lld to mislink musl.
rafaelauler updated this object.
rafaelauler edited the test plan for this revision. (Show Details)
rafaelauler added subscribers: Unknown Object (MLST), rafael.
shankarke accepted this revision.Oct 3 2014, 2:34 PM
shankarke added a reviewer: shankarke.
shankarke added a subscriber: shankarke.

Can you add a test ?

With that it LGTM.

This revision is now accepted and ready to land.Oct 3 2014, 2:34 PM

I added a test and committed r219034.

rafaelauler closed this revision.Oct 3 2014, 4:01 PM