llvm-project/lld/ELF/Arch/PPCInsns.def
Nemanja Ivanovic cddb0dbcef [LLD][PowerPC] Implement GOT to PC-Rel relaxation
This patch implements the handling for the R_PPC64_PCREL_OPT relocation as well
as the GOT relocation for the associated R_PPC64_GOT_PCREL34 relocation.

On Power10 targets with PC-Relative addressing, the linker can relax
GOT-relative accesses to PC-Relative under some conditions. Since the sequence
consists of a prefixed load, followed by a non-prefixed access (load or store),
the linker needs to replace the first instruction (as the replacement
instruction will be prefixed). The compiler communicates to the linker that
this optimization is safe by placing the two aforementioned relocations on the
GOT load (of the address).
The linker then does two things:

- Convert the load from the got into a PC-Relative add to compute the address
  relative to the PC
- Find the instruction referred to by the second relocation (R_PPC64_PCREL_OPT)
  and replace the first with the PC-Relative version of it

It is important to synchronize the mapping from legacy memory instructions to
their PC-Relative form. Hence, this patch adds a file to be included by both
the compiler and the linker so they're always in agreement.

Differential revision: https://reviews.llvm.org/D84360
2020-08-17 09:36:09 -05:00

28 lines
894 B
Modula-2

#ifndef PCREL_OPT
#error "Need to define function-style macro PCREL_OPT"
#endif
PCREL_OPT(NOINSN, NOINSN, NOMASK);
PCREL_OPT(LBZ, PLBZ, OPC_AND_RST);
PCREL_OPT(LHZ, PLHZ, OPC_AND_RST);
PCREL_OPT(LWZ, PLWZ, OPC_AND_RST);
PCREL_OPT(LHA, PLHA, OPC_AND_RST);
PCREL_OPT(LWA, PLWA, ONLY_RST);
PCREL_OPT(LD, PLD , ONLY_RST);
PCREL_OPT(LFS, PLFS, OPC_AND_RST);
PCREL_OPT(LXSSP, PLXSSP, ONLY_RST);
PCREL_OPT(LFD, PLFD, OPC_AND_RST);
PCREL_OPT(LXSD, PLXSD, ONLY_RST);
PCREL_OPT(LXV, PLXV, ST_STX28_TO5);
PCREL_OPT(LXVP, PLXVP, OPC_AND_RST);
PCREL_OPT(STB, PSTB, OPC_AND_RST);
PCREL_OPT(STH, PSTH, OPC_AND_RST);
PCREL_OPT(STW, PSTW, OPC_AND_RST);
PCREL_OPT(STD, PSTD, ONLY_RST);
PCREL_OPT(STFS, PSTFS, OPC_AND_RST);
PCREL_OPT(STXSSP, PSTXSSP, ONLY_RST);
PCREL_OPT(STFD, PSTFD, OPC_AND_RST);
PCREL_OPT(STXSD, PSTXSD, ONLY_RST);
PCREL_OPT(STXV, PSTXV, ST_STX28_TO5);
PCREL_OPT(STXVP, PSTXVP, OPC_AND_RST);