2016-11-02 07:47:30 +08:00
|
|
|
//===-- RISCVAsmBackend.cpp - RISCV Assembler Backend ---------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-09-28 16:26:24 +08:00
|
|
|
#include "MCTargetDesc/RISCVFixupKinds.h"
|
2016-11-02 07:47:30 +08:00
|
|
|
#include "MCTargetDesc/RISCVMCTargetDesc.h"
|
2017-09-28 16:26:24 +08:00
|
|
|
#include "llvm/ADT/APInt.h"
|
2016-11-02 07:47:30 +08:00
|
|
|
#include "llvm/MC/MCAsmBackend.h"
|
|
|
|
#include "llvm/MC/MCAssembler.h"
|
2017-09-28 16:26:24 +08:00
|
|
|
#include "llvm/MC/MCContext.h"
|
2016-11-02 07:47:30 +08:00
|
|
|
#include "llvm/MC/MCDirectives.h"
|
|
|
|
#include "llvm/MC/MCELFObjectWriter.h"
|
2017-06-06 19:49:48 +08:00
|
|
|
#include "llvm/MC/MCExpr.h"
|
2016-11-02 07:47:30 +08:00
|
|
|
#include "llvm/MC/MCFixupKindInfo.h"
|
|
|
|
#include "llvm/MC/MCObjectWriter.h"
|
|
|
|
#include "llvm/MC/MCSubtargetInfo.h"
|
|
|
|
#include "llvm/MC/MCSymbol.h"
|
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
class RISCVAsmBackend : public MCAsmBackend {
|
2018-01-17 22:17:12 +08:00
|
|
|
const MCSubtargetInfo &STI;
|
2016-11-02 07:47:30 +08:00
|
|
|
uint8_t OSABI;
|
|
|
|
bool Is64Bit;
|
|
|
|
|
|
|
|
public:
|
2018-01-17 22:17:12 +08:00
|
|
|
RISCVAsmBackend(const MCSubtargetInfo &STI, uint8_t OSABI, bool Is64Bit)
|
2018-05-22 01:57:19 +08:00
|
|
|
: MCAsmBackend(support::little), STI(STI), OSABI(OSABI),
|
|
|
|
Is64Bit(Is64Bit) {}
|
2016-11-02 07:47:30 +08:00
|
|
|
~RISCVAsmBackend() override {}
|
|
|
|
|
[RISCV] Add symbol diff relocation support for RISC-V
For RISC-V it is desirable to have relaxation happen in the linker once
addresses are known, and as such the size between two instructions/byte
sequences in a section could change.
For most assembler expressions, this is fine, as the absolute address results
in the expression being converted to a fixup, and finally relocations.
However, for expressions such as .quad .L2-.L1, the assembler folds this down
to a constant once fragments are laid out, under the assumption that the
difference can no longer change, although in the case of linker relaxation the
differences can change at link time, so the constant is incorrect. One place
where this commonly appears is in debug information, where the size of a
function expression is in a form similar to the above.
This patch extends the assembler to allow an AsmBackend to declare that it
does not want the assembler to fold down this expression, and instead generate
a pair of relocations that allow the linker to carry out the calculation. In
this case, the expression is not folded, but when it comes to emitting a
fixup, the generic FK_Data_* fixups are converted into a pair, one for the
addition half, one for the subtraction, and this is passed to the relocation
generating methods as usual. I have named these FK_Data_Add_* and
FK_Data_Sub_* to indicate which half these are for.
For RISC-V, which supports this via e.g. the R_RISCV_ADD64, R_RISCV_SUB64 pair
of relocations, these are also set to always emit relocations relative to
local symbols rather than section offsets. This is to deal with the fact that
if relocations were calculated on e.g. .text+8 and .text+4, the result 12
would be stored rather than 4 as both addends are added in the linker.
Differential Revision: https://reviews.llvm.org/D45181
Patch by Simon Cook.
llvm-svn: 333079
2018-05-23 20:36:18 +08:00
|
|
|
// Generate diff expression relocations if the relax feature is enabled,
|
|
|
|
// otherwise it is safe for the assembler to calculate these internally.
|
|
|
|
bool requiresDiffExpressionRelocations() const override {
|
|
|
|
return STI.getFeatureBits()[RISCV::FeatureRelax];
|
|
|
|
}
|
2017-06-24 06:52:36 +08:00
|
|
|
void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
|
|
|
|
const MCValue &Target, MutableArrayRef<char> Data,
|
2017-07-12 07:18:25 +08:00
|
|
|
uint64_t Value, bool IsResolved) const override;
|
2016-11-02 07:47:30 +08:00
|
|
|
|
2018-05-22 03:20:29 +08:00
|
|
|
std::unique_ptr<MCObjectTargetWriter>
|
|
|
|
createObjectTargetWriter() const override;
|
2016-11-02 07:47:30 +08:00
|
|
|
|
2018-05-15 09:28:50 +08:00
|
|
|
// If linker relaxation is enabled, always emit relocations even if the fixup
|
|
|
|
// can be resolved. This is necessary for correctness as offsets may change
|
|
|
|
// during relaxation.
|
|
|
|
bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup,
|
|
|
|
const MCValue &Target) override {
|
|
|
|
return STI.getFeatureBits()[RISCV::FeatureRelax];
|
|
|
|
}
|
|
|
|
|
2016-11-02 07:47:30 +08:00
|
|
|
bool fixupNeedsRelaxation(const MCFixup &Fixup, uint64_t Value,
|
|
|
|
const MCRelaxableFragment *DF,
|
2018-05-18 14:42:21 +08:00
|
|
|
const MCAsmLayout &Layout) const override {
|
|
|
|
llvm_unreachable("Handled by fixupNeedsRelaxationAdvanced");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool fixupNeedsRelaxationAdvanced(const MCFixup &Fixup, bool Resolved,
|
|
|
|
uint64_t Value,
|
|
|
|
const MCRelaxableFragment *DF,
|
|
|
|
const MCAsmLayout &Layout,
|
|
|
|
const bool WasForced) const override;
|
2016-11-02 07:47:30 +08:00
|
|
|
|
2017-09-28 16:26:24 +08:00
|
|
|
unsigned getNumFixupKinds() const override {
|
|
|
|
return RISCV::NumTargetFixupKinds;
|
|
|
|
}
|
|
|
|
|
|
|
|
const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const override {
|
2018-05-30 09:16:36 +08:00
|
|
|
const static MCFixupKindInfo Infos[] = {
|
2017-09-28 16:26:24 +08:00
|
|
|
// This table *must* be in the order that the fixup_* kinds are defined in
|
|
|
|
// RISCVFixupKinds.h.
|
|
|
|
//
|
2018-02-06 08:55:23 +08:00
|
|
|
// name offset bits flags
|
|
|
|
{ "fixup_riscv_hi20", 12, 20, 0 },
|
|
|
|
{ "fixup_riscv_lo12_i", 20, 12, 0 },
|
|
|
|
{ "fixup_riscv_lo12_s", 0, 32, 0 },
|
|
|
|
{ "fixup_riscv_pcrel_hi20", 12, 20, MCFixupKindInfo::FKF_IsPCRel },
|
|
|
|
{ "fixup_riscv_pcrel_lo12_i", 20, 12, MCFixupKindInfo::FKF_IsPCRel },
|
|
|
|
{ "fixup_riscv_pcrel_lo12_s", 0, 32, MCFixupKindInfo::FKF_IsPCRel },
|
|
|
|
{ "fixup_riscv_jal", 12, 20, MCFixupKindInfo::FKF_IsPCRel },
|
|
|
|
{ "fixup_riscv_branch", 0, 32, MCFixupKindInfo::FKF_IsPCRel },
|
|
|
|
{ "fixup_riscv_rvc_jump", 2, 11, MCFixupKindInfo::FKF_IsPCRel },
|
2018-05-24 14:21:23 +08:00
|
|
|
{ "fixup_riscv_rvc_branch", 0, 16, MCFixupKindInfo::FKF_IsPCRel },
|
2018-05-30 09:16:36 +08:00
|
|
|
{ "fixup_riscv_call", 0, 64, MCFixupKindInfo::FKF_IsPCRel },
|
2018-05-24 14:21:23 +08:00
|
|
|
{ "fixup_riscv_relax", 0, 0, 0 }
|
2017-09-28 16:26:24 +08:00
|
|
|
};
|
2018-05-30 09:16:36 +08:00
|
|
|
static_assert((array_lengthof(Infos)) == RISCV::NumTargetFixupKinds,
|
|
|
|
"Not all fixup kinds added to Infos array");
|
2017-09-28 16:26:24 +08:00
|
|
|
|
|
|
|
if (Kind < FirstTargetFixupKind)
|
|
|
|
return MCAsmBackend::getFixupKindInfo(Kind);
|
|
|
|
|
|
|
|
assert(unsigned(Kind - FirstTargetFixupKind) < getNumFixupKinds() &&
|
|
|
|
"Invalid kind!");
|
|
|
|
return Infos[Kind - FirstTargetFixupKind];
|
|
|
|
}
|
2016-11-02 07:47:30 +08:00
|
|
|
|
2018-03-03 06:04:12 +08:00
|
|
|
bool mayNeedRelaxation(const MCInst &Inst) const override;
|
|
|
|
unsigned getRelaxedOpcode(unsigned Op) const;
|
2016-11-02 07:47:30 +08:00
|
|
|
|
|
|
|
void relaxInstruction(const MCInst &Inst, const MCSubtargetInfo &STI,
|
2018-03-03 06:04:12 +08:00
|
|
|
MCInst &Res) const override;
|
2016-11-02 07:47:30 +08:00
|
|
|
|
|
|
|
|
2018-05-22 01:57:19 +08:00
|
|
|
bool writeNopData(raw_ostream &OS, uint64_t Count) const override;
|
2016-11-02 07:47:30 +08:00
|
|
|
};
|
|
|
|
|
2018-03-03 06:04:12 +08:00
|
|
|
|
2018-05-18 14:42:21 +08:00
|
|
|
bool RISCVAsmBackend::fixupNeedsRelaxationAdvanced(const MCFixup &Fixup,
|
|
|
|
bool Resolved,
|
|
|
|
uint64_t Value,
|
|
|
|
const MCRelaxableFragment *DF,
|
|
|
|
const MCAsmLayout &Layout,
|
|
|
|
const bool WasForced) const {
|
|
|
|
// Return true if the symbol is actually unresolved.
|
|
|
|
// Resolved could be always false when shouldForceRelocation return true.
|
|
|
|
// We use !WasForced to indicate that the symbol is unresolved and not forced
|
|
|
|
// by shouldForceRelocation.
|
|
|
|
if (!Resolved && !WasForced)
|
|
|
|
return true;
|
|
|
|
|
2018-03-03 06:04:12 +08:00
|
|
|
int64_t Offset = int64_t(Value);
|
|
|
|
switch ((unsigned)Fixup.getKind()) {
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
case RISCV::fixup_riscv_rvc_branch:
|
|
|
|
// For compressed branch instructions the immediate must be
|
|
|
|
// in the range [-256, 254].
|
|
|
|
return Offset > 254 || Offset < -256;
|
|
|
|
case RISCV::fixup_riscv_rvc_jump:
|
|
|
|
// For compressed jump instructions the immediate must be
|
|
|
|
// in the range [-2048, 2046].
|
|
|
|
return Offset > 2046 || Offset < -2048;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RISCVAsmBackend::relaxInstruction(const MCInst &Inst,
|
|
|
|
const MCSubtargetInfo &STI,
|
|
|
|
MCInst &Res) const {
|
|
|
|
// TODO: replace this with call to auto generated uncompressinstr() function.
|
|
|
|
switch (Inst.getOpcode()) {
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Opcode not expected!");
|
|
|
|
case RISCV::C_BEQZ:
|
|
|
|
// c.beqz $rs1, $imm -> beq $rs1, X0, $imm.
|
|
|
|
Res.setOpcode(RISCV::BEQ);
|
|
|
|
Res.addOperand(Inst.getOperand(0));
|
|
|
|
Res.addOperand(MCOperand::createReg(RISCV::X0));
|
|
|
|
Res.addOperand(Inst.getOperand(1));
|
|
|
|
break;
|
|
|
|
case RISCV::C_BNEZ:
|
|
|
|
// c.bnez $rs1, $imm -> bne $rs1, X0, $imm.
|
|
|
|
Res.setOpcode(RISCV::BNE);
|
|
|
|
Res.addOperand(Inst.getOperand(0));
|
|
|
|
Res.addOperand(MCOperand::createReg(RISCV::X0));
|
|
|
|
Res.addOperand(Inst.getOperand(1));
|
|
|
|
break;
|
|
|
|
case RISCV::C_J:
|
|
|
|
// c.j $imm -> jal X0, $imm.
|
|
|
|
Res.setOpcode(RISCV::JAL);
|
|
|
|
Res.addOperand(MCOperand::createReg(RISCV::X0));
|
|
|
|
Res.addOperand(Inst.getOperand(0));
|
|
|
|
break;
|
|
|
|
case RISCV::C_JAL:
|
|
|
|
// c.jal $imm -> jal X1, $imm.
|
|
|
|
Res.setOpcode(RISCV::JAL);
|
|
|
|
Res.addOperand(MCOperand::createReg(RISCV::X1));
|
|
|
|
Res.addOperand(Inst.getOperand(0));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Given a compressed control flow instruction this function returns
|
|
|
|
// the expanded instruction.
|
|
|
|
unsigned RISCVAsmBackend::getRelaxedOpcode(unsigned Op) const {
|
|
|
|
switch (Op) {
|
|
|
|
default:
|
|
|
|
return Op;
|
|
|
|
case RISCV::C_BEQZ:
|
|
|
|
return RISCV::BEQ;
|
|
|
|
case RISCV::C_BNEZ:
|
|
|
|
return RISCV::BNE;
|
|
|
|
case RISCV::C_J:
|
|
|
|
case RISCV::C_JAL: // fall through.
|
|
|
|
return RISCV::JAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RISCVAsmBackend::mayNeedRelaxation(const MCInst &Inst) const {
|
|
|
|
return getRelaxedOpcode(Inst.getOpcode()) != Inst.getOpcode();
|
|
|
|
}
|
|
|
|
|
2018-05-22 01:57:19 +08:00
|
|
|
bool RISCVAsmBackend::writeNopData(raw_ostream &OS, uint64_t Count) const {
|
2018-01-17 22:17:12 +08:00
|
|
|
bool HasStdExtC = STI.getFeatureBits()[RISCV::FeatureStdExtC];
|
|
|
|
unsigned MinNopLen = HasStdExtC ? 2 : 4;
|
|
|
|
|
|
|
|
if ((Count % MinNopLen) != 0)
|
2016-11-02 07:47:30 +08:00
|
|
|
return false;
|
|
|
|
|
2018-01-17 22:17:12 +08:00
|
|
|
// The canonical nop on RISC-V is addi x0, x0, 0.
|
|
|
|
uint64_t Nop32Count = Count / 4;
|
|
|
|
for (uint64_t i = Nop32Count; i != 0; --i)
|
2018-05-22 01:57:19 +08:00
|
|
|
OS.write("\x13\0\0\0", 4);
|
2016-11-02 07:47:30 +08:00
|
|
|
|
2018-01-17 22:17:12 +08:00
|
|
|
// The canonical nop on RVC is c.nop.
|
|
|
|
if (HasStdExtC) {
|
|
|
|
uint64_t Nop16Count = (Count - Nop32Count * 4) / 2;
|
|
|
|
for (uint64_t i = Nop16Count; i != 0; --i)
|
2018-05-22 01:57:19 +08:00
|
|
|
OS.write("\x01\0", 2);
|
2018-01-17 22:17:12 +08:00
|
|
|
}
|
|
|
|
|
2016-11-02 07:47:30 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-09-28 16:26:24 +08:00
|
|
|
static uint64_t adjustFixupValue(const MCFixup &Fixup, uint64_t Value,
|
|
|
|
MCContext &Ctx) {
|
|
|
|
unsigned Kind = Fixup.getKind();
|
|
|
|
switch (Kind) {
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Unknown fixup kind!");
|
|
|
|
case FK_Data_1:
|
|
|
|
case FK_Data_2:
|
|
|
|
case FK_Data_4:
|
|
|
|
case FK_Data_8:
|
|
|
|
return Value;
|
|
|
|
case RISCV::fixup_riscv_lo12_i:
|
2018-02-06 08:55:23 +08:00
|
|
|
case RISCV::fixup_riscv_pcrel_lo12_i:
|
2017-09-28 16:26:24 +08:00
|
|
|
return Value & 0xfff;
|
|
|
|
case RISCV::fixup_riscv_lo12_s:
|
2018-02-06 08:55:23 +08:00
|
|
|
case RISCV::fixup_riscv_pcrel_lo12_s:
|
2017-09-28 16:26:24 +08:00
|
|
|
return (((Value >> 5) & 0x7f) << 25) | ((Value & 0x1f) << 7);
|
|
|
|
case RISCV::fixup_riscv_hi20:
|
|
|
|
case RISCV::fixup_riscv_pcrel_hi20:
|
|
|
|
// Add 1 if bit 11 is 1, to compensate for low 12 bits being negative.
|
|
|
|
return ((Value + 0x800) >> 12) & 0xfffff;
|
|
|
|
case RISCV::fixup_riscv_jal: {
|
|
|
|
if (!isInt<21>(Value))
|
|
|
|
Ctx.reportError(Fixup.getLoc(), "fixup value out of range");
|
|
|
|
if (Value & 0x1)
|
|
|
|
Ctx.reportError(Fixup.getLoc(), "fixup value must be 2-byte aligned");
|
|
|
|
// Need to produce imm[19|10:1|11|19:12] from the 21-bit Value.
|
|
|
|
unsigned Sbit = (Value >> 20) & 0x1;
|
|
|
|
unsigned Hi8 = (Value >> 12) & 0xff;
|
|
|
|
unsigned Mid1 = (Value >> 11) & 0x1;
|
|
|
|
unsigned Lo10 = (Value >> 1) & 0x3ff;
|
|
|
|
// Inst{31} = Sbit;
|
|
|
|
// Inst{30-21} = Lo10;
|
|
|
|
// Inst{20} = Mid1;
|
|
|
|
// Inst{19-12} = Hi8;
|
|
|
|
Value = (Sbit << 19) | (Lo10 << 9) | (Mid1 << 8) | Hi8;
|
|
|
|
return Value;
|
|
|
|
}
|
|
|
|
case RISCV::fixup_riscv_branch: {
|
|
|
|
if (!isInt<13>(Value))
|
|
|
|
Ctx.reportError(Fixup.getLoc(), "fixup value out of range");
|
|
|
|
if (Value & 0x1)
|
|
|
|
Ctx.reportError(Fixup.getLoc(), "fixup value must be 2-byte aligned");
|
|
|
|
// Need to extract imm[12], imm[10:5], imm[4:1], imm[11] from the 13-bit
|
|
|
|
// Value.
|
|
|
|
unsigned Sbit = (Value >> 12) & 0x1;
|
|
|
|
unsigned Hi1 = (Value >> 11) & 0x1;
|
|
|
|
unsigned Mid6 = (Value >> 5) & 0x3f;
|
|
|
|
unsigned Lo4 = (Value >> 1) & 0xf;
|
|
|
|
// Inst{31} = Sbit;
|
|
|
|
// Inst{30-25} = Mid6;
|
|
|
|
// Inst{11-8} = Lo4;
|
|
|
|
// Inst{7} = Hi1;
|
|
|
|
Value = (Sbit << 31) | (Mid6 << 25) | (Lo4 << 8) | (Hi1 << 7);
|
|
|
|
return Value;
|
|
|
|
}
|
2018-05-30 09:16:36 +08:00
|
|
|
case RISCV::fixup_riscv_call: {
|
|
|
|
// Jalr will add UpperImm with the sign-extended 12-bit LowerImm,
|
|
|
|
// we need to add 0x800ULL before extract upper bits to reflect the
|
|
|
|
// effect of the sign extension.
|
|
|
|
uint64_t UpperImm = (Value + 0x800ULL) & 0xfffff000ULL;
|
|
|
|
uint64_t LowerImm = Value & 0xfffULL;
|
|
|
|
return UpperImm | ((LowerImm << 20) << 32);
|
|
|
|
}
|
2017-12-07 21:19:57 +08:00
|
|
|
case RISCV::fixup_riscv_rvc_jump: {
|
|
|
|
// Need to produce offset[11|4|9:8|10|6|7|3:1|5] from the 11-bit Value.
|
|
|
|
unsigned Bit11 = (Value >> 11) & 0x1;
|
|
|
|
unsigned Bit4 = (Value >> 4) & 0x1;
|
|
|
|
unsigned Bit9_8 = (Value >> 8) & 0x3;
|
|
|
|
unsigned Bit10 = (Value >> 10) & 0x1;
|
|
|
|
unsigned Bit6 = (Value >> 6) & 0x1;
|
|
|
|
unsigned Bit7 = (Value >> 7) & 0x1;
|
|
|
|
unsigned Bit3_1 = (Value >> 1) & 0x7;
|
|
|
|
unsigned Bit5 = (Value >> 5) & 0x1;
|
|
|
|
Value = (Bit11 << 10) | (Bit4 << 9) | (Bit9_8 << 7) | (Bit10 << 6) |
|
|
|
|
(Bit6 << 5) | (Bit7 << 4) | (Bit3_1 << 1) | Bit5;
|
|
|
|
return Value;
|
|
|
|
}
|
|
|
|
case RISCV::fixup_riscv_rvc_branch: {
|
|
|
|
// Need to produce offset[8|4:3], [reg 3 bit], offset[7:6|2:1|5]
|
|
|
|
unsigned Bit8 = (Value >> 8) & 0x1;
|
|
|
|
unsigned Bit7_6 = (Value >> 6) & 0x3;
|
|
|
|
unsigned Bit5 = (Value >> 5) & 0x1;
|
|
|
|
unsigned Bit4_3 = (Value >> 3) & 0x3;
|
|
|
|
unsigned Bit2_1 = (Value >> 1) & 0x3;
|
|
|
|
Value = (Bit8 << 12) | (Bit4_3 << 10) | (Bit7_6 << 5) | (Bit2_1 << 3) |
|
|
|
|
(Bit5 << 2);
|
|
|
|
return Value;
|
|
|
|
}
|
2017-09-28 16:26:24 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-24 06:52:36 +08:00
|
|
|
void RISCVAsmBackend::applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
|
|
|
|
const MCValue &Target,
|
2017-06-22 07:06:53 +08:00
|
|
|
MutableArrayRef<char> Data, uint64_t Value,
|
2017-07-12 07:18:25 +08:00
|
|
|
bool IsResolved) const {
|
2017-09-28 16:26:24 +08:00
|
|
|
MCContext &Ctx = Asm.getContext();
|
2017-11-11 03:09:28 +08:00
|
|
|
MCFixupKindInfo Info = getFixupKindInfo(Fixup.getKind());
|
2017-09-28 16:26:24 +08:00
|
|
|
if (!Value)
|
|
|
|
return; // Doesn't change encoding.
|
|
|
|
// Apply any target-specific value adjustments.
|
|
|
|
Value = adjustFixupValue(Fixup, Value, Ctx);
|
|
|
|
|
|
|
|
// Shift the value into position.
|
|
|
|
Value <<= Info.TargetOffset;
|
|
|
|
|
|
|
|
unsigned Offset = Fixup.getOffset();
|
2018-05-23 18:53:56 +08:00
|
|
|
unsigned NumBytes = alignTo(Info.TargetSize + Info.TargetOffset, 8) / 8;
|
2017-11-11 03:09:28 +08:00
|
|
|
|
2017-09-28 16:26:24 +08:00
|
|
|
assert(Offset + NumBytes <= Data.size() && "Invalid fixup offset!");
|
|
|
|
|
|
|
|
// For each byte of the fragment that the fixup touches, mask in the
|
|
|
|
// bits from the fixup value.
|
2018-05-23 18:53:56 +08:00
|
|
|
for (unsigned i = 0; i != NumBytes; ++i) {
|
2017-09-28 16:26:24 +08:00
|
|
|
Data[Offset + i] |= uint8_t((Value >> (i * 8)) & 0xff);
|
|
|
|
}
|
2016-11-02 07:47:30 +08:00
|
|
|
}
|
|
|
|
|
2018-05-22 03:20:29 +08:00
|
|
|
std::unique_ptr<MCObjectTargetWriter>
|
|
|
|
RISCVAsmBackend::createObjectTargetWriter() const {
|
|
|
|
return createRISCVELFObjectWriter(OSABI, Is64Bit);
|
2016-11-02 07:47:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
|
|
|
MCAsmBackend *llvm::createRISCVAsmBackend(const Target &T,
|
2018-01-03 16:53:05 +08:00
|
|
|
const MCSubtargetInfo &STI,
|
2016-11-02 07:47:30 +08:00
|
|
|
const MCRegisterInfo &MRI,
|
|
|
|
const MCTargetOptions &Options) {
|
2018-01-03 16:53:05 +08:00
|
|
|
const Triple &TT = STI.getTargetTriple();
|
2016-11-02 07:47:30 +08:00
|
|
|
uint8_t OSABI = MCELFObjectTargetWriter::getOSABI(TT.getOS());
|
2018-01-17 22:17:12 +08:00
|
|
|
return new RISCVAsmBackend(STI, OSABI, TT.isArch64Bit());
|
2016-11-02 07:47:30 +08:00
|
|
|
}
|