[all-commits] [llvm/llvm-project] b257d3: [ELF][PPC64] Suppress toc-indirect to toc-relative...
Fangrui Song via All-commits
all-commits at lists.llvm.org
Thu Apr 30 09:17:14 PDT 2020
Branch: refs/heads/master
Home: https://github.com/llvm/llvm-project
Commit: b257d3c8a897b9999b9bdb660fc8eaad772a0085
https://github.com/llvm/llvm-project/commit/b257d3c8a897b9999b9bdb660fc8eaad772a0085
Author: Fangrui Song <maskray at google.com>
Date: 2020-04-30 (Thu, 30 Apr 2020)
Changed paths:
M lld/ELF/InputSection.cpp
M lld/ELF/InputSection.h
M lld/ELF/Relocations.cpp
M lld/ELF/Writer.cpp
A lld/test/ELF/ppc64-toc-relax2.s
Log Message:
-----------
[ELF][PPC64] Suppress toc-indirect to toc-relative relaxation if R_PPC64_TOC16_LO is seen
The current implementation assumes that R_PPC64_TOC16_HA is always followed
by R_PPC64_TOC16_LO_DS. This can break with R_PPC64_TOC16_LO:
// Load the address of the TOC entry, instead of the value stored at that address
addis 3, 2, .LC0 at tloc@ha # R_PPC64_TOC16_HA
addi 3, 3, .LC0 at tloc@l # R_PPC64_TOC16_LO
blr
which is used by boringssl's util/fipstools/delocate/delocate.go
https://github.com/google/boringssl/blob/master/crypto/fipsmodule/FIPS.md has some documentation.
In short, this tool converts an assembly file to avoid any potential relocations.
The distance to an input .toc is not a constant after linking, so it cannot use an `addis;ld` pair.
Instead, it jumps to a stub which loads the TOC entry address with `addis;addi`.
This patch checks the presence of R_PPC64_TOC16_LO and suppresses
toc-indirect to toc-relative relaxation if R_PPC64_TOC16_LO is seen.
This approach is conservative and loses some relaxation opportunities but is easy to implement.
addis 3, 2, .LC0 at toc@ha # no relaxation
addi 3, 3, .LC0 at toc@l # no relaxation
li 9, 0
addis 4, 2, .LC0 at toc@ha # can relax but suppressed
ld 4, .LC0 at toc@l(4) # can relax but suppressed
Also note that interleaved R_PPC64_TOC16_HA and R_PPC64_TOC16_LO_DS is
possible and this patch accounts for that.
addis 3, 2, .LC1 at toc@ha # can relax
addis 4, 2, .LC2 at toc@ha # can relax
ld 3, .LC1 at toc@l(3) # can relax
ld 4, .LC2 at toc@l(4) # can relax
Reviewed By: #powerpc, sfertile
Differential Revision: https://reviews.llvm.org/D78431
More information about the All-commits
mailing list