45 ARMELFObjectWriter(uint8_t OSABI)
58 {
"fixup_t2_ldst_pcrel_12", 0, 32,
63 {
"fixup_t2_pcrel_10", 0, 32,
67 {
"fixup_t2_pcrel_9", 0, 32,
70 {
"fixup_thumb_adr_pcrel_10", 0, 8,
74 {
"fixup_t2_adr_pcrel_12", 0, 32,
86 {
"fixup_arm_thumb_blx", 0, 32,
90 {
"fixup_arm_thumb_cp", 0, 8,
96 {
"fixup_arm_movt_hi16", 0, 20, 0},
97 {
"fixup_arm_movw_lo16", 0, 20, 0},
98 {
"fixup_t2_movt_hi16", 0, 20, 0},
99 {
"fixup_t2_movw_lo16", 0, 20, 0},
100 {
"fixup_arm_mod_imm", 0, 12, 0},
101 {
"fixup_t2_so_imm", 0, 26, 0},
109 {
"fixup_t2_ldst_pcrel_12", 0, 32,
114 {
"fixup_t2_pcrel_10", 0, 32,
118 {
"fixup_t2_pcrel_9", 0, 32,
121 {
"fixup_thumb_adr_pcrel_10", 8, 8,
125 {
"fixup_t2_adr_pcrel_12", 0, 32,
137 {
"fixup_arm_thumb_blx", 0, 32,
141 {
"fixup_arm_thumb_cp", 8, 8,
147 {
"fixup_arm_movt_hi16", 12, 20, 0},
148 {
"fixup_arm_movw_lo16", 12, 20, 0},
149 {
"fixup_t2_movt_hi16", 12, 20, 0},
150 {
"fixup_t2_movw_lo16", 12, 20, 0},
151 {
"fixup_arm_mod_imm", 20, 12, 0},
152 {
"fixup_t2_so_imm", 26, 6, 0},
178 bool HasV8MBaselineOps = STI->
getFeatureBits()[ARM::HasV8MBaselineOps];
184 return HasThumb2 ? (
unsigned)ARM::t2Bcc : Op;
186 return HasThumb2 ? (
unsigned)ARM::t2LDRpci : Op;
188 return HasThumb2 ? (
unsigned)ARM::t2ADR : Op;
190 return HasV8MBaselineOps ? (
unsigned)ARM::t2B : Op;
205 uint64_t
Value)
const {
206 switch ((
unsigned)Fixup.
getKind()) {
214 int64_t
Offset = int64_t(Value) - 4;
215 if (Offset > 2046 || Offset < -2048)
216 return "out of range pc-relative fixup value";
226 int64_t
Offset = int64_t(Value) - 4;
227 if (Offset > 254 || Offset < -256)
228 return "out of range pc-relative fixup value";
235 int64_t
Offset = int64_t(Value) - 4;
237 return "misaligned pc-relative fixup value";
238 else if (Offset > 1020 || Offset < 0)
239 return "out of range pc-relative fixup value";
246 int64_t
Offset = (Value & ~1);
248 return "will be converted to nop";
280 RelaxedOp == ARM::tHINT) {
295 const uint16_t Thumb1_16bitNopEncoding = 0x46c0;
296 const uint16_t Thumb2_16bitNopEncoding = 0xbf00;
297 const uint32_t ARMv4_NopEncoding = 0xe1a00000;
298 const uint32_t ARMv6T2_NopEncoding = 0xe320f000;
300 const uint16_t nopEncoding =
301 hasNOP() ? Thumb2_16bitNopEncoding : Thumb1_16bitNopEncoding;
302 uint64_t NumNops = Count / 2;
303 for (uint64_t i = 0; i != NumNops; ++i)
311 hasNOP() ? ARMv6T2_NopEncoding : ARMv4_NopEncoding;
312 uint64_t NumNops = Count / 4;
313 for (uint64_t i = 0; i != NumNops; ++i)
336 if (IsLittleEndian) {
339 uint32_t Swapped = (Value & 0xFFFF0000) >> 16;
340 Swapped |= (Value & 0x0000FFFF) << 16;
347 bool IsLittleEndian) {
350 if (IsLittleEndian) {
351 Value = (SecondHalf & 0xFFFF) << 16;
352 Value |= (FirstHalf & 0xFFFF);
354 Value = (SecondHalf & 0xFFFF);
355 Value |= (FirstHalf & 0xFFFF) << 16;
365 bool IsLittleEndian)
const {
374 if (
A->hasSubsectionsViaSymbols() && Asm.
isThumbFunc(&
A->getSymbol()) &&
398 unsigned Hi4 = (Value & 0xF000) >> 12;
399 unsigned Lo12 = Value & 0x0FFF;
402 Value = (Hi4 << 16) | (Lo12);
410 unsigned Hi4 = (Value & 0xF000) >> 12;
411 unsigned i = (Value & 0x800) >> 11;
412 unsigned Mid3 = (Value & 0x700) >> 8;
413 unsigned Lo8 = Value & 0x0FF;
418 Value = (Hi4 << 16) | (i << 26) | (Mid3 << 12) | (Lo8);
429 if ((int64_t)Value < 0) {
437 Value |= isAdd << 23;
450 if ((int64_t)Value < 0) {
465 if ((int64_t)Value < 0) {
471 out |= (Value & 0x800) << 15;
472 out |= (Value & 0x700) << 4;
473 out |= (Value & 0x0FF);
486 dyn_cast<MCSymbolRefExpr>(Fixup.
getValue()))
489 return 0xffffff & ((Value - 8) >> 2);
495 bool I = Value & 0x800000;
496 bool J1 = Value & 0x400000;
497 bool J2 = Value & 0x200000;
504 out |= (Value & 0x1FF800) << 5;
505 out |= (Value & 0x0007FF);
514 out |= (Value & 0x80000) << 7;
515 out |= (Value & 0x40000) >> 7;
516 out |= (Value & 0x20000) >> 4;
517 out |= (Value & 0x1F800) << 5;
518 out |= (Value & 0x007FF);
525 if (!isInt<26>(Value - 4)) {
543 uint32_t signBit = (offset & 0x800000) >> 23;
544 uint32_t I1Bit = (offset & 0x400000) >> 22;
545 uint32_t J1Bit = (I1Bit ^ 0x1) ^ signBit;
546 uint32_t I2Bit = (offset & 0x200000) >> 21;
547 uint32_t J2Bit = (I2Bit ^ 0x1) ^ signBit;
548 uint32_t imm10Bits = (offset & 0x1FF800) >> 11;
549 uint32_t imm11Bits = (offset & 0x000007FF);
551 uint32_t FirstHalf = (((uint16_t)signBit << 10) | (uint16_t)imm10Bits);
552 uint32_t SecondHalf = (((uint16_t)J1Bit << 13) | ((uint16_t)J2Bit << 11) |
553 (uint16_t)imm11Bits);
569 if (Value % 4 != 0) {
576 dyn_cast<MCSymbolRefExpr>(Fixup.
getValue()))
579 uint32_t signBit = (offset & 0x400000) >> 22;
580 uint32_t I1Bit = (offset & 0x200000) >> 21;
581 uint32_t J1Bit = (I1Bit ^ 0x1) ^ signBit;
582 uint32_t I2Bit = (offset & 0x100000) >> 20;
583 uint32_t J2Bit = (I2Bit ^ 0x1) ^ signBit;
584 uint32_t imm10HBits = (offset & 0xFFC00) >> 10;
585 uint32_t imm10LBits = (offset & 0x3FF);
587 uint32_t FirstHalf = (((uint16_t)signBit << 10) | (uint16_t)imm10HBits);
588 uint32_t SecondHalf = (((uint16_t)J1Bit << 13) | ((uint16_t)J2Bit << 11) |
589 ((uint16_t)imm10LBits) << 1);
598 if (FixupDiagnostic) {
604 return ((Value - 4) >> 2) & 0xff;
616 return ((Binary & 0x20) << 4) | ((Binary & 0x1f) << 3);
623 if (FixupDiagnostic) {
628 return ((Value - 4) >> 1) & 0x7ff;
633 if (FixupDiagnostic) {
638 return ((Value - 4) >> 1) & 0xff;
643 if ((int64_t)Value < 0) {
652 Value = (Value & 0xf) | ((Value & 0xf0) << 4);
653 return Value | (isAdd << 23);
663 if ((int64_t)Value < 0) {
673 Value |= isAdd << 23;
690 if ((int64_t)Value < 0) {
704 Value |= isAdd << 23;
722 if ((int64_t)Value < 0) {
731 uint64_t EncValue = 0;
732 EncValue |= (Value & 0x800) << 15;
733 EncValue |= (Value & 0x700) << 4;
734 EncValue |= (Value & 0xff);
747 assert(Sym &&
"How did we resolve this?");
759 if (Sym && Sym->
isELF()) {
887 bool IsResolved)
const {
896 assert(Offset + NumBytes <= Data.
size() &&
"Invalid fixup offset!");
899 unsigned FullSizeBytes;
900 if (!IsLittleEndian) {
902 assert((Offset + FullSizeBytes) <= Data.
size() &&
"Invalid fixup size!");
903 assert(NumBytes <= FullSizeBytes &&
"Invalid fixup size!");
909 for (
unsigned i = 0; i != NumBytes; ++i) {
910 unsigned Idx = IsLittleEndian ? i : (FullSizeBytes - 1 - i);
911 Data[Offset + Idx] |= uint8_t((Value >> (i * 8)) & 0xff);
957 int CFARegister = ARM::SP;
958 int CFARegisterOffset = 0;
961 int FloatRegCount = 0;
963 for (
size_t i = 0, e = Instrs.
size(); i != e; ++i) {
979 if (ARMMCRegisterClasses[ARM::GPRRegClassID].
contains(Reg))
981 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].
contains(Reg)) {
986 llvm::dbgs() <<
".cfi_offset on unknown register="
998 <<
"CFI directive not compatiable with comact "
1007 if ((CFARegister == ARM::SP) && (CFARegisterOffset == 0))
1011 if (CFARegister != ARM::R7) {
1014 <<
" instead of r7\n");
1017 int StackAdjust = CFARegisterOffset - 8;
1018 if (RegOffsets.
lookup(ARM::LR) != (-4 - StackAdjust)) {
1021 <<
"LR not saved as standard frame, StackAdjust="
1023 <<
", CFARegisterOffset=" << CFARegisterOffset
1024 <<
", lr save at offset=" << RegOffsets[14] <<
"\n");
1027 if (RegOffsets.
lookup(ARM::R7) != (-8 - StackAdjust)) {
1029 llvm::dbgs() <<
"r7 not saved as standard frame\n");
1035 switch (StackAdjust) {
1039 CompactUnwindEncoding |= 0x00400000;
1042 CompactUnwindEncoding |= 0x00800000;
1045 CompactUnwindEncoding |= 0x00C00000;
1049 <<
".cfi_def_cfa stack adjust ("
1050 << StackAdjust <<
") out of range\n");
1067 int CurOffset = -8 - StackAdjust;
1068 for (
auto CSReg : GPRCSRegs) {
1073 int RegOffset =
Offset->second;
1074 if (RegOffset != CurOffset - 4) {
1077 << RegOffset <<
" but only supported at "
1078 << CurOffset <<
"\n");
1081 CompactUnwindEncoding |= CSReg.Encoding;
1086 if (FloatRegCount == 0)
1087 return CompactUnwindEncoding;
1095 if (FloatRegCount > 4) {
1097 llvm::dbgs() <<
"unsupported number of D registers saved ("
1098 << FloatRegCount <<
")\n");
1105 static unsigned FPRCSRegs[] = { ARM::D8, ARM::D10, ARM::D12, ARM::D14 };
1106 for (
int Idx = FloatRegCount - 1; Idx >= 0; --Idx) {
1107 auto Offset = RegOffsets.
find(FPRCSRegs[Idx]);
1110 llvm::dbgs() << FloatRegCount <<
" D-regs saved, but "
1111 << MRI.
getName(FPRCSRegs[Idx])
1114 }
else if (
Offset->second != CurOffset - 8) {
1116 llvm::dbgs() << FloatRegCount <<
" D-regs saved, but "
1117 << MRI.
getName(FPRCSRegs[Idx])
1118 <<
" saved at " <<
Offset->second
1119 <<
", expected at " << CurOffset - 8
1126 return CompactUnwindEncoding | ((FloatRegCount - 1) << 8);
1134 case ARM::AK_ARMV4T:
1136 case ARM::AK_ARMV5T:
1137 case ARM::AK_ARMV5TE:
1138 case ARM::AK_ARMV5TEJ:
1141 case ARM::AK_ARMV6K:
1143 case ARM::AK_ARMV7A:
1145 case ARM::AK_ARMV7S:
1147 case ARM::AK_ARMV7K:
1149 case ARM::AK_ARMV6M:
1151 case ARM::AK_ARMV7M:
1153 case ARM::AK_ARMV7EM:
1172 return new ARMAsmBackendWinCOFF(T, TheTriple);
1176 return new ARMAsmBackendELF(T, TheTriple, OSABI, isLittle);
OSType getOS() const
getOS - Get the parsed operating system type of this triple.
unsigned getNumFixupKinds() const override
Get the number of target specific fixup kinds.
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
const MCSymbol & getSymbol() const
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This represents an "assembler immediate".
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
MCAsmBackend * createARMAsmBackend(const Target &T, const MCRegisterInfo &MRI, const Triple &TT, StringRef CPU, const MCTargetOptions &Options, bool IsLittleEndian)
MCAsmBackend * createThumbLEAsmBackend(const Target &T, const MCRegisterInfo &MRI, const Triple &TT, StringRef CPU, const MCTargetOptions &Options)
A raw_ostream that writes to an SmallVector or SmallString.
const char * reasonForFixupRelaxation(const MCFixup &Fixup, uint64_t Value) const
unsigned getRelaxedOpcode(unsigned Op) const
MCContext & getContext() const
static Lanai::Fixups FixupKind(const MCExpr *Expr)
Defines the object file and target independent interfaces used by the assembler backend to write nati...
void write8(uint8_t Value)
unsigned getRegister() const
void dump_pretty(raw_ostream &OS, const MCInstPrinter *Printer=nullptr, StringRef Separator=" ") const
Dump the MCInst as prettily as possible using the additional MC structures, if given.
return AArch64::GPR64RegClass contains(Reg)
bool isOSWindows() const
Tests whether the OS is Windows.
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Is this fixup kind PCrelative? This is used by the assembler backend to evaluate fixup values in a ta...
#define DEBUG_WITH_TYPE(TYPE, X)
DEBUG_WITH_TYPE macro - This macro should be used by passes to emit debug information.
static MCOperand createReg(unsigned Reg)
static MachO::CPUSubTypeARM getMachOSubTypeFromArch(StringRef Arch)
Encapsulates the layout of an assembly file at a particular point in time.
Reg
All possible values of the reg field in the ModR/M byte.
Represent a reference to a symbol from inside an expression.
ObjectFormatType getObjectFormat() const
getFormat - Get the object format for this triple.
bool mayNeedRelaxation(const MCInst &Inst) const override
Check whether the given instruction may need relaxation.
A four-byte section relative fixup.
Context object for machine code objects.
A two-byte section relative fixup.
.code16 (X86) / .code 16 (ARM)
static int getT2SOImmVal(unsigned Arg)
getT2SOImmVal - Given a 32-bit immediate, if it is something that can fit into a Thumb-2 shifter_oper...
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
bool isThumbFunc(const MCSymbol *Func) const
Check whether a given symbol has been flagged with .thumb_func.
uint32_t getOffset() const
size_t size() const
size - Get the array size.
Instances of this class represent a single low-level machine instruction.
Flag
These should be considered private to the implementation of the MCInstrDesc class.
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
iterator find(const_arg_type_t< KeyT > Val)
A relaxable fragment holds on to its MCInst, since it may need to be relaxed during the assembler lay...
void write32(uint32_t Value)
Function Alias Analysis false
const MCExpr * getValue() const
uint32_t generateCompactUnwindEncoding(ArrayRef< MCCFIInstruction > Instrs) const override
Generate compact unwind encoding for the function based on the CFI instructions.
unsigned const MachineRegisterInfo * MRI
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
The instances of the Type class are immutable: once they are created, they are never changed...
CompactUnwindEncodings
Compact unwind encoding values.
static uint32_t swapHalfWords(uint32_t Value, bool IsLittleEndian)
MCAsmBackend * createARMBEAsmBackend(const Target &T, const MCRegisterInfo &MRI, const Triple &TT, StringRef CPU, const MCTargetOptions &Options)
bool fixupNeedsRelaxation(const MCFixup &Fixup, uint64_t Value, const MCRelaxableFragment *DF, const MCAsmLayout &Layout) const override
Simple predicate for targets where !Resolved implies requiring relaxation.
MCFixupKind
Extensible enumeration to represent the type of a fixup.
const MCFixupKindInfo & getFixupKindInfo(MCFixupKind Kind) const override
Get information on a fixup kind.
void reportError(SMLoc L, const Twine &Msg)
Should this fixup kind force a 4-byte aligned effective PC value?
MCAsmBackend * createARMLEAsmBackend(const Target &T, const MCRegisterInfo &MRI, const Triple &TT, StringRef CPU, const MCTargetOptions &Options)
bool empty() const
empty - Check if the array is empty.
int getLLVMRegNum(unsigned RegNum, bool isEH) const
Map a dwarf register back to a target register.
MCFixupKind getKind() const
static wasm::ValType getType(const TargetRegisterClass *RC)
void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup, const MCValue &Target, MutableArrayRef< char > Data, uint64_t Value, bool IsResolved) const override
Apply the Value for given Fixup into the provided data fragment, at the offset specified by the fixup...
Triple - Helper class for working with autoconf configuration names.
void write16(uint16_t Value)
OpType getOperation() const
static unsigned getFixupKindContainerSizeBytes(unsigned Kind)
getFixupKindContainerSizeBytes - The number of bytes of the container involved in big endian...
const MachO::CPUSubTypeARM Subtype
void setOpcode(unsigned Op)
const MCSymbolRefExpr * getSymA() const
bool writeNopData(uint64_t Count, MCObjectWriter *OW) const override
Write an (optimal) nop sequence of Count bytes to the given output.
void relaxInstruction(const MCInst &Inst, const MCSubtargetInfo &STI, MCInst &Res) const override
Relax the instruction in the given fragment to the next wider instruction.
StringRef str()
Return a StringRef for the vector contents.
const FeatureBitset & getFeatureBits() const
getFeatureBits - Return the feature bits.
MCAsmBackend * createThumbBEAsmBackend(const Target &T, const MCRegisterInfo &MRI, const Triple &TT, StringRef CPU, const MCTargetOptions &Options)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
unsigned getOpcode() const
Target - Wrapper for Target specific information.
static int getSOImmVal(unsigned Arg)
getSOImmVal - Given a 32-bit immediate, if it is something that can fit into an shifter_operand immed...
.code32 (X86) / .code 32 (ARM)
llvm_unreachable("Unknown RegBank!")
void handleAssemblerFlag(MCAssemblerFlag Flag) override
Handle any target-specific assembler flags. By default, do nothing.
bool isOSBinFormatELF() const
Tests whether the OS uses the ELF binary format.
StringRef getArchName() const
getArchName - Get the architecture (first) component of the triple.
MCSubtargetInfo - Generic base class for all target subtargets.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
const Triple & getTargetTriple() const
getTargetTriple - Return the target triple string.
unsigned parseArch(StringRef Arch)
Target independent information on a fixup kind.
unsigned adjustFixupValue(const MCAssembler &Asm, const MCFixup &Fixup, const MCValue &Target, uint64_t Value, bool IsResolved, MCContext &Ctx, bool IsLittleEndian) const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
Generic interface to target specific assembler backends.
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
const char * getName(unsigned RegNo) const
Return the human-readable symbolic target-specific name for the specified physical register...
void addOperand(const MCOperand &Op)
StringRef - Represent a constant reference to a string, i.e.
static unsigned getFixupKindNumBytes(unsigned Kind)
getFixupKindNumBytes - The number of bytes the fixup may change.
virtual const MCFixupKindInfo & getFixupKindInfo(MCFixupKind Kind) const
Get information on a fixup kind.
static MCOperand createImm(int64_t Val)
static uint32_t joinHalfWords(uint32_t FirstHalf, uint32_t SecondHalf, bool IsLittleEndian)
bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup, const MCValue &Target) override
Hook to check if a relocation is needed for some target specific reason.