Consolidate all relocations in relocate_section
commit25927df3b75c5ce2b64ab8acdcc5974b4e1c89c1
authorThomas Preud'homme <robotux@celest.fr>
Sat, 12 Nov 2016 15:16:08 +0000 (12 23:16 +0800)
committerThomas Preud'homme <robotux@celest.fr>
Sat, 3 Dec 2016 17:26:51 +0000 (3 17:26 +0000)
treeb16a8d4b0ddd484d2b4995f9bfe96701b37258d3
parent2c38800bbe0544830863247a23594e37c531be8d
Consolidate all relocations in relocate_section

Static relocation of functions in dynamic libraries must use the PLT
entry as the target. Before this commit, it used to be done in 2 parts
for ARM, with the offset of the PLT entry from the beginning of the PLT
being put in the relocated place in build_got_entries () and then the
address of the PLT being added in relocate_section.

This led to code dealing with reading the offset of a bl instruction in
build_got_entries. Furthermore, the addition of the address of the start
of the PLT was done based on the relocation type which does not convey
whether a PLT entry should be used to reach the symbol.

This commit moves the decision to use the PLT as the target in
relocate_section, therefore having the instruction aware code contained
to the target-specific bit of that function (in <target>-link.c).

Note that relocate_syms is *not* the right place to do this because two
different relocations for the same symbol can make different decision.
This is the case in tcc -run mode where the static and dynamic
relocation are done by tcc.

Storing the PLT entry address in the symbol's st_value field and relying
on the specific relocation type being used for dynamic relocation would
work but the PLT entry address would then appear in the static symbol
table (symtab). This would also make the static symbol table entry
differ from the dynamic symbol table entry.
arm-link.c
arm64-link.c
tccelf.c
x86_64-link.c