ELF: Forbid all relative relocations to absolute symbols in PIC, except for weak...
authorPeter Collingbourne <peter@pcc.me.uk>
Tue, 3 May 2016 01:21:08 +0000 (01:21 +0000)
committerPeter Collingbourne <peter@pcc.me.uk>
Tue, 3 May 2016 01:21:08 +0000 (01:21 +0000)
commit6a4225962d85bf41282cf549d6acd10ceb2ce9b3
treee60bc5451863a13d5a6bbe299d6a568ab9ef8910
parenta19859d5897cdb912e66523c52011235e93fea26
ELF: Forbid all relative relocations to absolute symbols in PIC, except for weak undefined.

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.

Differential Revision: http://reviews.llvm.org/D19844

llvm-svn: 268350
lld/ELF/OutputSections.cpp
lld/ELF/SymbolTable.cpp
lld/ELF/SymbolTable.h
lld/ELF/Symbols.cpp
lld/ELF/Symbols.h
lld/ELF/Writer.cpp
lld/test/ELF/relocation-relative-absolute.s [new file with mode: 0644]
lld/test/ELF/relocation-relative-synthetic.s [new file with mode: 0644]
lld/test/ELF/relocation-relative-weak.s [new file with mode: 0644]