| 1 | //===-- RISCVMCAsmInfo.cpp - RISC-V Asm properties ------------------------===// |
| 2 | // |
| 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 |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file contains the declarations of the RISCVMCAsmInfo properties. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #include "RISCVMCAsmInfo.h" |
| 14 | #include "llvm/BinaryFormat/Dwarf.h" |
| 15 | #include "llvm/BinaryFormat/ELF.h" |
| 16 | #include "llvm/MC/MCExpr.h" |
| 17 | #include "llvm/MC/MCStreamer.h" |
| 18 | #include "llvm/TargetParser/Triple.h" |
| 19 | using namespace llvm; |
| 20 | |
| 21 | void RISCVMCAsmInfo::anchor() {} |
| 22 | |
| 23 | RISCVMCAsmInfo::RISCVMCAsmInfo(const Triple &TT) { |
| 24 | CodePointerSize = CalleeSaveStackSlotSize = TT.isArch64Bit() ? 8 : 4; |
| 25 | CommentString = "#" ; |
| 26 | AlignmentIsInBytes = false; |
| 27 | SupportsDebugInformation = true; |
| 28 | ExceptionsType = ExceptionHandling::DwarfCFI; |
| 29 | UseAtForSpecifier = false; |
| 30 | Data16bitsDirective = "\t.half\t" ; |
| 31 | Data32bitsDirective = "\t.word\t" ; |
| 32 | } |
| 33 | |
| 34 | const MCExpr *RISCVMCAsmInfo::getExprForFDESymbol(const MCSymbol *Sym, |
| 35 | unsigned Encoding, |
| 36 | MCStreamer &Streamer) const { |
| 37 | if (!(Encoding & dwarf::DW_EH_PE_pcrel)) |
| 38 | return MCAsmInfo::getExprForFDESymbol(Sym, Encoding, Streamer); |
| 39 | |
| 40 | // The default symbol subtraction results in an ADD/SUB relocation pair. |
| 41 | // Processing this relocation pair is problematic when linker relaxation is |
| 42 | // enabled, so we follow binutils in using the R_RISCV_32_PCREL relocation |
| 43 | // for the FDE initial location. |
| 44 | MCContext &Ctx = Streamer.getContext(); |
| 45 | const MCExpr *ME = MCSymbolRefExpr::create(Symbol: Sym, Ctx); |
| 46 | assert(Encoding & dwarf::DW_EH_PE_sdata4 && "Unexpected encoding" ); |
| 47 | return MCSpecifierExpr::create(Expr: ME, S: ELF::R_RISCV_32_PCREL, Ctx); |
| 48 | } |
| 49 | |
| 50 | void RISCVMCAsmInfo::printSpecifierExpr(raw_ostream &OS, |
| 51 | const MCSpecifierExpr &Expr) const { |
| 52 | auto S = Expr.getSpecifier(); |
| 53 | bool HasSpecifier = S != 0 && S != ELF::R_RISCV_CALL_PLT; |
| 54 | if (HasSpecifier) |
| 55 | OS << '%' << RISCV::getSpecifierName(Kind: S) << '('; |
| 56 | printExpr(OS, *Expr.getSubExpr()); |
| 57 | if (HasSpecifier) |
| 58 | OS << ')'; |
| 59 | } |
| 60 | |