Path: blob/main/contrib/llvm-project/llvm/lib/Target/RISCV/MCTargetDesc/RISCVFixupKinds.h
35294 views
//===-- RISCVFixupKinds.h - RISC-V Specific Fixup Entries -------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef LLVM_LIB_TARGET_RISCV_MCTARGETDESC_RISCVFIXUPKINDS_H9#define LLVM_LIB_TARGET_RISCV_MCTARGETDESC_RISCVFIXUPKINDS_H1011#include "llvm/BinaryFormat/ELF.h"12#include "llvm/MC/MCFixup.h"13#include <utility>1415#undef RISCV1617namespace llvm::RISCV {18enum Fixups {19// 20-bit fixup corresponding to %hi(foo) for instructions like lui20fixup_riscv_hi20 = FirstTargetFixupKind,21// 12-bit fixup corresponding to %lo(foo) for instructions like addi22fixup_riscv_lo12_i,23// 12-bit fixup corresponding to foo-bar for instructions like addi24fixup_riscv_12_i,25// 12-bit fixup corresponding to %lo(foo) for the S-type store instructions26fixup_riscv_lo12_s,27// 20-bit fixup corresponding to %pcrel_hi(foo) for instructions like auipc28fixup_riscv_pcrel_hi20,29// 12-bit fixup corresponding to %pcrel_lo(foo) for instructions like addi30fixup_riscv_pcrel_lo12_i,31// 12-bit fixup corresponding to %pcrel_lo(foo) for the S-type store32// instructions33fixup_riscv_pcrel_lo12_s,34// 20-bit fixup corresponding to %got_pcrel_hi(foo) for instructions like35// auipc36fixup_riscv_got_hi20,37// 20-bit fixup corresponding to %tprel_hi(foo) for instructions like lui38fixup_riscv_tprel_hi20,39// 12-bit fixup corresponding to %tprel_lo(foo) for instructions like addi40fixup_riscv_tprel_lo12_i,41// 12-bit fixup corresponding to %tprel_lo(foo) for the S-type store42// instructions43fixup_riscv_tprel_lo12_s,44// Fixup corresponding to %tprel_add(foo) for PseudoAddTPRel, used as a linker45// hint46fixup_riscv_tprel_add,47// 20-bit fixup corresponding to %tls_ie_pcrel_hi(foo) for instructions like48// auipc49fixup_riscv_tls_got_hi20,50// 20-bit fixup corresponding to %tls_gd_pcrel_hi(foo) for instructions like51// auipc52fixup_riscv_tls_gd_hi20,53// 20-bit fixup for symbol references in the jal instruction54fixup_riscv_jal,55// 12-bit fixup for symbol references in the branch instructions56fixup_riscv_branch,57// 11-bit fixup for symbol references in the compressed jump instruction58fixup_riscv_rvc_jump,59// 8-bit fixup for symbol references in the compressed branch instruction60fixup_riscv_rvc_branch,61// Fixup representing a legacy no-pic function call attached to the auipc62// instruction in a pair composed of adjacent auipc+jalr instructions.63fixup_riscv_call,64// Fixup representing a function call attached to the auipc instruction in a65// pair composed of adjacent auipc+jalr instructions.66fixup_riscv_call_plt,67// Used to generate an R_RISCV_RELAX relocation, which indicates the linker68// may relax the instruction pair.69fixup_riscv_relax,70// Used to generate an R_RISCV_ALIGN relocation, which indicates the linker71// should fixup the alignment after linker relaxation.72fixup_riscv_align,73// Fixups indicating a TLS descriptor code sequence, corresponding to auipc,74// lw/ld, addi, and jalr, respectively.75fixup_riscv_tlsdesc_hi20,76fixup_riscv_tlsdesc_load_lo12,77fixup_riscv_tlsdesc_add_lo12,78fixup_riscv_tlsdesc_call,7980// Used as a sentinel, must be the last81fixup_riscv_invalid,82NumTargetFixupKinds = fixup_riscv_invalid - FirstTargetFixupKind83};8485static inline std::pair<MCFixupKind, MCFixupKind>86getRelocPairForSize(unsigned Size) {87switch (Size) {88default:89llvm_unreachable("unsupported fixup size");90case 1:91return std::make_pair(92MCFixupKind(FirstLiteralRelocationKind + ELF::R_RISCV_ADD8),93MCFixupKind(FirstLiteralRelocationKind + ELF::R_RISCV_SUB8));94case 2:95return std::make_pair(96MCFixupKind(FirstLiteralRelocationKind + ELF::R_RISCV_ADD16),97MCFixupKind(FirstLiteralRelocationKind + ELF::R_RISCV_SUB16));98case 4:99return std::make_pair(100MCFixupKind(FirstLiteralRelocationKind + ELF::R_RISCV_ADD32),101MCFixupKind(FirstLiteralRelocationKind + ELF::R_RISCV_SUB32));102case 8:103return std::make_pair(104MCFixupKind(FirstLiteralRelocationKind + ELF::R_RISCV_ADD64),105MCFixupKind(FirstLiteralRelocationKind + ELF::R_RISCV_SUB64));106}107}108109} // end namespace llvm::RISCV110111#endif112113114