This is an archive of the discontinued LLVM Phabricator instance.

ELF: Forbid all relative relocations to absolute symbols in PIC, except for weak undefined.
ClosedPublic

Authored by pcc on May 2 2016, 5:37 PM.

Details

Summary

Weak undefined symbols resolve to the image base. This is a little strange,
but it allows us to link function calls to such symbols. Normally such a
call will be guarded with a comparison, which will load a zero from the GOT.

There's one example of such a function call in crti.o in Linux's CRT.

As part of this change, I also needed to make the synthetic start and end
symbols image base relative in the case where their sections were empty,
so that PC-relative references to those symbols would continue to work.

Diff Detail

Repository
rL LLVM

Event Timeline

pcc updated this revision to Diff 55926.May 2 2016, 5:37 PM
pcc retitled this revision from to ELF: Forbid all relative relocations to absolute symbols in PIC, except for weak undefined..
pcc updated this object.
pcc added reviewers: rafael, ruiu.
pcc added a subscriber: llvm-commits.
ruiu edited edge metadata.May 2 2016, 5:48 PM

Is a DefinedSynthetic with the null output section different from a DefinedRegular with the null input section? Both seems to be resolved to the same address.

pcc added a comment.May 2 2016, 5:50 PM

Isn't a DefinedRegular with a null input section an absolute symbol? What we need here is an image base relative symbol.

ruiu accepted this revision.May 2 2016, 6:15 PM
ruiu edited edge metadata.

LGTM with nits.

ELF/Writer.cpp
465 ↗(On Diff #55926)

Remove else after return.

467–468 ↗(On Diff #55926)

You want to return false (or true, as it is just a dummy value) after error() because error is not a noreturn function.

This revision is now accepted and ready to land.May 2 2016, 6:15 PM
This revision was automatically updated to reflect the committed changes.