Files
TheRock/compiler/amd-llvm/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCLFIRewriter.h
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

101 lines
4.0 KiB
C++

//===- AArch64MCLFIRewriter.h -----------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file declares the AArch64MCLFIRewriter class, the AArch64 specific
// subclass of MCLFIRewriter.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIB_TARGET_AARCH64_MCTARGETDESC_AARCH64MCLFIREWRITER_H
#define LLVM_LIB_TARGET_AARCH64_MCTARGETDESC_AARCH64MCLFIREWRITER_H
#include "llvm/MC/MCInstrInfo.h"
#include "llvm/MC/MCLFIRewriter.h"
#include "llvm/MC/MCRegister.h"
#include "llvm/MC/MCRegisterInfo.h"
namespace llvm {
class MCContext;
class MCExpr;
class MCInst;
class MCStreamer;
class MCSubtargetInfo;
/// Rewrites AArch64 instructions for LFI sandboxing.
///
/// This class implements the LFI (Lightweight Fault Isolation) rewriting
/// for AArch64 instructions. It transforms instructions to ensure memory
/// accesses and control flow are confined within the sandbox region.
///
/// Reserved registers:
/// - X27: Sandbox base address (always holds the base)
/// - X28: Safe address register (always within sandbox)
/// - X26: Scratch register for intermediate calculations
/// - X25: context register (points to thread-local runtime data)
/// - SP: Stack pointer (always within sandbox)
/// - X30: Link register (always within sandbox)
class AArch64MCLFIRewriter : public MCLFIRewriter {
public:
AArch64MCLFIRewriter(MCContext &Ctx, std::unique_ptr<MCRegisterInfo> &&RI,
std::unique_ptr<MCInstrInfo> &&II)
: MCLFIRewriter(Ctx, std::move(RI), std::move(II)) {}
bool rewriteInst(const MCInst &Inst, MCStreamer &Out,
const MCSubtargetInfo &STI) override;
private:
/// Recursion guard to prevent infinite loops when emitting instructions.
bool Guard = false;
/// Deferred `.tlsdesccall` symbol. The directive attaches a
/// R_AARCH64_TLSDESC_CALL relocation to the following BLR. Since LFI inserts
/// a guard before that BLR, the marker is deferred and re-emitted between
/// the guard and the branch so the relocation stays on the BLR.
const MCExpr *PendingTLSDescCall = nullptr;
// Instruction classification. Returns the reserved register that may be
// modified, or an invalid register if no reserved register is touched.
MCRegister mayModifyReserved(const MCInst &Inst) const;
// Instruction emission.
void emitInst(const MCInst &Inst, MCStreamer &Out,
const MCSubtargetInfo &STI);
void emitAddMask(MCRegister Dest, MCRegister Src, MCStreamer &Out,
const MCSubtargetInfo &STI);
void emitBranch(unsigned Opcode, MCRegister Target, MCStreamer &Out,
const MCSubtargetInfo &STI);
void emitPendingTLSDescCall(MCStreamer &Out, const MCSubtargetInfo &STI);
void emitMov(MCRegister Dest, MCRegister Src, MCStreamer &Out,
const MCSubtargetInfo &STI);
// Rewriting logic.
void doRewriteInst(const MCInst &Inst, MCStreamer &Out,
const MCSubtargetInfo &STI);
// Control flow.
void rewriteIndirectBranch(const MCInst &Inst, MCStreamer &Out,
const MCSubtargetInfo &STI);
void rewriteReturn(const MCInst &Inst, MCStreamer &Out,
const MCSubtargetInfo &STI);
// Link register modification.
void rewriteLRModification(const MCInst &Inst, MCStreamer &Out,
const MCSubtargetInfo &STI);
// System instructions.
void rewriteSyscall(const MCInst &Inst, MCStreamer &Out,
const MCSubtargetInfo &STI);
void rewriteTPRead(const MCInst &Inst, MCStreamer &Out,
const MCSubtargetInfo &STI);
void rewriteTPWrite(const MCInst &Inst, MCStreamer &Out,
const MCSubtargetInfo &STI);
};
} // namespace llvm
#endif // LLVM_LIB_TARGET_AARCH64_MCTARGETDESC_AARCH64MCLFIREWRITER_H