This is an archive of the discontinued LLVM Phabricator instance.

[lld] [ELF] Fix inclusion of weak symbols in the dynamic symbol table
ClosedPublic

Authored by rafaelauler on Oct 1 2014, 7:00 PM.

Details

Summary

This patch implements in the X86_64 ELF lld backend yet another feature that was
only available in the MIPS backend. However, this patch changes generic ELF
classes to make it trivial for other ELF backends to use this logic too. When
creating a dynamic executable that has dynamic relocations against weak
undefined symbols, these symbols must be exported to the dynamic symbol table
to seek a possible resolution at run time.

A common use case is the gmon_start weak glibc undefined symbol.

Diff Detail

Event Timeline

rafaelauler updated this revision to Diff 14306.Oct 1 2014, 7:00 PM
rafaelauler retitled this revision from to [lld] [ELF] Fix inclusion of weak symbols in the dynamic symbol table.
rafaelauler updated this object.
rafaelauler edited the test plan for this revision. (Show Details)
rafaelauler added reviewers: Bigcheese, shankarke.
rafaelauler added subscribers: Unknown Object (MLST), rafael.
emaste added a subscriber: emaste.Oct 2 2014, 4:55 AM
shankarke requested changes to this revision.Oct 2 2014, 4:12 PM
shankarke edited edge metadata.
shankarke added inline comments.
lib/ReaderWriter/ELF/DefaultLayout.h
567–587

If we are creating a dynamic relocation for a symbol, that symbol should go in the dynamic symbol table. Looks like this code is removing undefined symbols that are targets of dynamic relocations.

This revision now requires changes to proceed.Oct 2 2014, 4:12 PM

Hi Shankar,

Thanks for looking this code. I answered your question below.

lib/ReaderWriter/ELF/DefaultLayout.h
567–587

If the symbol is the target of a dynamic relocation, that relocation should be reported by the backend by "isDynamicRelocation" or "isPLTRelocation", shouldn't it? This code should separate regular relocations from dynamic ones, and I think that a good way to figure out which are the dynamic relocations is to ask the backend.

rafaelauler updated this revision to Diff 14593.Oct 8 2014, 1:16 PM
rafaelauler edited edge metadata.

Ping and rebase.

shankarke accepted this revision.Oct 8 2014, 3:35 PM
shankarke edited edge metadata.
This revision is now accepted and ready to land.Oct 8 2014, 3:35 PM
rafaelauler closed this revision.Oct 8 2014, 3:48 PM

Committed r219349.