1 //===-- RISCVMCAsmInfo.cpp - RISCV Asm properties -------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file contains the declarations of the RISCVMCAsmInfo properties.
11 //===----------------------------------------------------------------------===//
13 #include "RISCVMCAsmInfo.h"
14 #include "MCTargetDesc/RISCVMCExpr.h"
15 #include "llvm/ADT/Triple.h"
16 #include "llvm/BinaryFormat/Dwarf.h"
17 #include "llvm/MC/MCStreamer.h"
20 void RISCVMCAsmInfo::anchor() {}
22 RISCVMCAsmInfo::RISCVMCAsmInfo(const Triple &TT) {
23 CodePointerSize = CalleeSaveStackSlotSize = TT.isArch64Bit() ? 8 : 4;
25 AlignmentIsInBytes = false;
26 SupportsDebugInformation = true;
27 ExceptionsType = ExceptionHandling::DwarfCFI;
28 Data16bitsDirective = "\t.half\t";
29 Data32bitsDirective = "\t.word\t";
32 const MCExpr *RISCVMCAsmInfo::getExprForFDESymbol(const MCSymbol *Sym,
34 MCStreamer &Streamer) const {
35 if (!(Encoding & dwarf::DW_EH_PE_pcrel))
36 return MCAsmInfo::getExprForFDESymbol(Sym, Encoding, Streamer);
38 // The default symbol subtraction results in an ADD/SUB relocation pair.
39 // Processing this relocation pair is problematic when linker relaxation is
40 // enabled, so we follow binutils in using the R_RISCV_32_PCREL relocation
41 // for the FDE initial location.
42 MCContext &Ctx = Streamer.getContext();
44 MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_None, Ctx);
45 assert(Encoding & dwarf::DW_EH_PE_sdata4 && "Unexpected encoding");
46 return RISCVMCExpr::create(ME, RISCVMCExpr::VK_RISCV_32_PCREL, Ctx);