diff options
Diffstat (limited to 'llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp')
-rw-r--r-- | llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp | 147 |
1 files changed, 70 insertions, 77 deletions
diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp index f558ca8d2d9f2..876741d6c3438 100644 --- a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp +++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp @@ -93,7 +93,7 @@ class ARMTargetAsmStreamer : public ARMTargetStreamer { void emitIntTextAttribute(unsigned Attribute, unsigned IntValue, StringRef StringValue) override; void emitArch(ARM::ArchKind Arch) override; - void emitArchExtension(unsigned ArchExt) override; + void emitArchExtension(uint64_t ArchExt) override; void emitObjectArch(ARM::ArchKind Arch) override; void emitFPU(unsigned FPU) override; void emitInst(uint32_t Inst, char Suffix = '\0') override; @@ -177,7 +177,8 @@ void ARMTargetAsmStreamer::switchVendor(StringRef Vendor) {} void ARMTargetAsmStreamer::emitAttribute(unsigned Attribute, unsigned Value) { OS << "\t.eabi_attribute\t" << Attribute << ", " << Twine(Value); if (IsVerboseAsm) { - StringRef Name = ARMBuildAttrs::AttrTypeAsString(Attribute); + StringRef Name = + ELFAttrs::attrTypeAsString(Attribute, ARMBuildAttrs::ARMAttributeTags); if (!Name.empty()) OS << "\t@ " << Name; } @@ -193,7 +194,8 @@ void ARMTargetAsmStreamer::emitTextAttribute(unsigned Attribute, default: OS << "\t.eabi_attribute\t" << Attribute << ", \"" << String << "\""; if (IsVerboseAsm) { - StringRef Name = ARMBuildAttrs::AttrTypeAsString(Attribute); + StringRef Name = ELFAttrs::attrTypeAsString( + Attribute, ARMBuildAttrs::ARMAttributeTags); if (!Name.empty()) OS << "\t@ " << Name; } @@ -212,7 +214,9 @@ void ARMTargetAsmStreamer::emitIntTextAttribute(unsigned Attribute, if (!StringValue.empty()) OS << ", \"" << StringValue << "\""; if (IsVerboseAsm) - OS << "\t@ " << ARMBuildAttrs::AttrTypeAsString(Attribute); + OS << "\t@ " + << ELFAttrs::attrTypeAsString(Attribute, + ARMBuildAttrs::ARMAttributeTags); break; } OS << "\n"; @@ -222,7 +226,7 @@ void ARMTargetAsmStreamer::emitArch(ARM::ArchKind Arch) { OS << "\t.arch\t" << ARM::getArchName(Arch) << "\n"; } -void ARMTargetAsmStreamer::emitArchExtension(unsigned ArchExt) { +void ARMTargetAsmStreamer::emitArchExtension(uint64_t ArchExt) { OS << "\t.arch_extension\t" << ARM::getArchExtName(ArchExt) << "\n"; } @@ -238,7 +242,7 @@ void ARMTargetAsmStreamer::finishAttributeSection() {} void ARMTargetAsmStreamer::AnnotateTLSDescriptorSequence(const MCSymbolRefExpr *S) { - OS << "\t.tlsdescseq\t" << S->getSymbol().getName(); + OS << "\t.tlsdescseq\t" << S->getSymbol().getName() << "\n"; } void ARMTargetAsmStreamer::emitThumbSet(MCSymbol *Symbol, const MCExpr *Value) { @@ -328,12 +332,8 @@ private: } // Create new attribute item - AttributeItem Item = { - AttributeItem::NumericAttribute, - Attribute, - Value, - StringRef("") - }; + AttributeItem Item = {AttributeItem::NumericAttribute, Attribute, Value, + std::string(StringRef(""))}; Contents.push_back(Item); } @@ -344,17 +344,13 @@ private: if (!OverwriteExisting) return; Item->Type = AttributeItem::TextAttribute; - Item->StringValue = Value; + Item->StringValue = std::string(Value); return; } // Create new attribute item - AttributeItem Item = { - AttributeItem::TextAttribute, - Attribute, - 0, - Value - }; + AttributeItem Item = {AttributeItem::TextAttribute, Attribute, 0, + std::string(Value)}; Contents.push_back(Item); } @@ -366,17 +362,13 @@ private: return; Item->Type = AttributeItem::NumericAndTextAttributes; Item->IntValue = IntValue; - Item->StringValue = StringValue; + Item->StringValue = std::string(StringValue); return; } // Create new attribute item - AttributeItem Item = { - AttributeItem::NumericAndTextAttributes, - Attribute, - IntValue, - StringValue - }; + AttributeItem Item = {AttributeItem::NumericAndTextAttributes, Attribute, + IntValue, std::string(StringValue)}; Contents.push_back(Item); } @@ -452,7 +444,7 @@ public: ~ARMELFStreamer() override = default; - void FinishImpl() override; + void finishImpl() override; // ARM exception handling directives void emitFnStart(); @@ -468,13 +460,13 @@ public: void emitUnwindRaw(int64_t Offset, const SmallVectorImpl<uint8_t> &Opcodes); void emitFill(const MCExpr &NumBytes, uint64_t FillValue, SMLoc Loc) override { - EmitDataMappingSymbol(); + emitDataMappingSymbol(); MCObjectStreamer::emitFill(NumBytes, FillValue, Loc); } - void ChangeSection(MCSection *Section, const MCExpr *Subsection) override { + void changeSection(MCSection *Section, const MCExpr *Subsection) override { LastMappingSymbols[getCurrentSection().first] = std::move(LastEMSInfo); - MCELFStreamer::ChangeSection(Section, Subsection); + MCELFStreamer::changeSection(Section, Subsection); auto LastMappingSymbol = LastMappingSymbols.find(Section); if (LastMappingSymbol != LastMappingSymbols.end()) { LastEMSInfo = std::move(LastMappingSymbol->second); @@ -486,14 +478,14 @@ public: /// This function is the one used to emit instruction data into the ELF /// streamer. We override it to add the appropriate mapping symbol if /// necessary. - void EmitInstruction(const MCInst &Inst, + void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override { if (IsThumb) EmitThumbMappingSymbol(); else EmitARMMappingSymbol(); - MCELFStreamer::EmitInstruction(Inst, STI); + MCELFStreamer::emitInstruction(Inst, STI); } void emitInst(uint32_t Inst, char Suffix) { @@ -533,15 +525,15 @@ public: llvm_unreachable("Invalid Suffix"); } - MCELFStreamer::EmitBytes(StringRef(Buffer, Size)); + MCELFStreamer::emitBytes(StringRef(Buffer, Size)); } /// This is one of the functions used to emit data into an ELF section, so the /// ARM streamer overrides it to add the appropriate mapping symbol ($d) if /// necessary. - void EmitBytes(StringRef Data) override { - EmitDataMappingSymbol(); - MCELFStreamer::EmitBytes(Data); + void emitBytes(StringRef Data) override { + emitDataMappingSymbol(); + MCELFStreamer::emitBytes(Data); } void FlushPendingMappingSymbol() { @@ -555,7 +547,7 @@ public: /// This is one of the functions used to emit data into an ELF section, so the /// ARM streamer overrides it to add the appropriate mapping symbol ($d) if /// necessary. - void EmitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc) override { + void emitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc) override { if (const MCSymbolRefExpr *SRE = dyn_cast_or_null<MCSymbolRefExpr>(Value)) { if (SRE->getKind() == MCSymbolRefExpr::VK_ARM_SBREL && !(Size == 4)) { getContext().reportError(Loc, "relocated expression must be 32-bit"); @@ -564,12 +556,12 @@ public: getOrCreateDataFragment(); } - EmitDataMappingSymbol(); - MCELFStreamer::EmitValueImpl(Value, Size, Loc); + emitDataMappingSymbol(); + MCELFStreamer::emitValueImpl(Value, Size, Loc); } - void EmitAssemblerFlag(MCAssemblerFlag Flag) override { - MCELFStreamer::EmitAssemblerFlag(Flag); + void emitAssemblerFlag(MCAssemblerFlag Flag) override { + MCELFStreamer::emitAssemblerFlag(Flag); switch (Flag) { case MCAF_SyntaxUnified: @@ -609,7 +601,7 @@ private: ElfMappingSymbol State; }; - void EmitDataMappingSymbol() { + void emitDataMappingSymbol() { if (LastEMSInfo->State == EMS_Data) return; else if (LastEMSInfo->State == EMS_None) { @@ -648,7 +640,7 @@ private: void EmitMappingSymbol(StringRef Name) { auto *Symbol = cast<MCSymbolELF>(getContext().getOrCreateSymbol( Name + "." + Twine(MappingSymbolCounter++))); - EmitLabel(Symbol); + emitLabel(Symbol); Symbol->setType(ELF::STT_NOTYPE); Symbol->setBinding(ELF::STB_LOCAL); @@ -659,15 +651,15 @@ private: uint64_t Offset) { auto *Symbol = cast<MCSymbolELF>(getContext().getOrCreateSymbol( Name + "." + Twine(MappingSymbolCounter++))); - EmitLabelAtPos(Symbol, Loc, F, Offset); + emitLabelAtPos(Symbol, Loc, F, Offset); Symbol->setType(ELF::STT_NOTYPE); Symbol->setBinding(ELF::STB_LOCAL); Symbol->setExternal(false); } - void EmitThumbFunc(MCSymbol *Func) override { + void emitThumbFunc(MCSymbol *Func) override { getAssembler().setIsThumbFunc(Func); - EmitSymbolAttribute(Func, MCSA_ELF_TypeFunction); + emitSymbolAttribute(Func, MCSA_ELF_TypeFunction); } // Helper functions for ARM exception handling directives @@ -868,6 +860,7 @@ void ARMTargetELFStreamer::emitArchDefaultAttributes() { case ARM::ArchKind::ARMV8_3A: case ARM::ArchKind::ARMV8_4A: case ARM::ArchKind::ARMV8_5A: + case ARM::ArchKind::ARMV8_6A: setAttributeItem(CPU_arch_profile, ApplicationProfile, false); setAttributeItem(ARM_ISA_use, Allowed, false); setAttributeItem(THUMB_ISA_use, AllowThumb32, false); @@ -1091,7 +1084,7 @@ void ARMTargetELFStreamer::finishAttributeSection() { Streamer.SwitchSection(AttributeSection); // Format version - Streamer.EmitIntValue(0x41, 1); + Streamer.emitInt8(0x41); } // Vendor size + Vendor name + '\0' @@ -1102,31 +1095,31 @@ void ARMTargetELFStreamer::finishAttributeSection() { const size_t ContentsSize = calculateContentSize(); - Streamer.EmitIntValue(VendorHeaderSize + TagHeaderSize + ContentsSize, 4); - Streamer.EmitBytes(CurrentVendor); - Streamer.EmitIntValue(0, 1); // '\0' + Streamer.emitInt32(VendorHeaderSize + TagHeaderSize + ContentsSize); + Streamer.emitBytes(CurrentVendor); + Streamer.emitInt8(0); // '\0' - Streamer.EmitIntValue(ARMBuildAttrs::File, 1); - Streamer.EmitIntValue(TagHeaderSize + ContentsSize, 4); + Streamer.emitInt8(ARMBuildAttrs::File); + Streamer.emitInt32(TagHeaderSize + ContentsSize); // Size should have been accounted for already, now // emit each field as its type (ULEB or String) for (size_t i = 0; i < Contents.size(); ++i) { AttributeItem item = Contents[i]; - Streamer.EmitULEB128IntValue(item.Tag); + Streamer.emitULEB128IntValue(item.Tag); switch (item.Type) { default: llvm_unreachable("Invalid attribute type"); case AttributeItem::NumericAttribute: - Streamer.EmitULEB128IntValue(item.IntValue); + Streamer.emitULEB128IntValue(item.IntValue); break; case AttributeItem::TextAttribute: - Streamer.EmitBytes(item.StringValue); - Streamer.EmitIntValue(0, 1); // '\0' + Streamer.emitBytes(item.StringValue); + Streamer.emitInt8(0); // '\0' break; case AttributeItem::NumericAndTextAttributes: - Streamer.EmitULEB128IntValue(item.IntValue); - Streamer.EmitBytes(item.StringValue); - Streamer.EmitIntValue(0, 1); // '\0' + Streamer.emitULEB128IntValue(item.IntValue); + Streamer.emitBytes(item.StringValue); + Streamer.emitInt8(0); // '\0' break; } } @@ -1143,7 +1136,7 @@ void ARMTargetELFStreamer::emitLabel(MCSymbol *Symbol) { Streamer.getAssembler().registerSymbol(*Symbol); unsigned Type = cast<MCSymbolELF>(Symbol)->getType(); if (Type == ELF::STT_FUNC || Type == ELF::STT_GNU_IFUNC) - Streamer.EmitThumbFunc(Symbol); + Streamer.emitThumbFunc(Symbol); } void @@ -1155,13 +1148,13 @@ void ARMTargetELFStreamer::emitThumbSet(MCSymbol *Symbol, const MCExpr *Value) { if (const MCSymbolRefExpr *SRE = dyn_cast<MCSymbolRefExpr>(Value)) { const MCSymbol &Sym = SRE->getSymbol(); if (!Sym.isDefined()) { - getStreamer().EmitAssignment(Symbol, Value); + getStreamer().emitAssignment(Symbol, Value); return; } } - getStreamer().EmitThumbFunc(Symbol); - getStreamer().EmitAssignment(Symbol, Value); + getStreamer().emitThumbFunc(Symbol); + getStreamer().emitAssignment(Symbol, Value); } void ARMTargetELFStreamer::emitInst(uint32_t Inst, char Suffix) { @@ -1170,12 +1163,12 @@ void ARMTargetELFStreamer::emitInst(uint32_t Inst, char Suffix) { void ARMTargetELFStreamer::reset() { AttributeSection = nullptr; } -void ARMELFStreamer::FinishImpl() { +void ARMELFStreamer::finishImpl() { MCTargetStreamer &TS = *getTargetStreamer(); ARMTargetStreamer &ATS = static_cast<ARMTargetStreamer &>(TS); ATS.finishAttributeSection(); - MCELFStreamer::FinishImpl(); + MCELFStreamer::finishImpl(); } void ARMELFStreamer::reset() { @@ -1201,7 +1194,7 @@ inline void ARMELFStreamer::SwitchToEHSection(StringRef Prefix, static_cast<const MCSectionELF &>(Fn.getSection()); // Create the name for new section - StringRef FnSecName(FnSection.getSectionName()); + StringRef FnSecName(FnSection.getName()); SmallString<128> EHSecName(Prefix); if (FnSecName != ".text") { EHSecName += FnSecName; @@ -1213,13 +1206,13 @@ inline void ARMELFStreamer::SwitchToEHSection(StringRef Prefix, Flags |= ELF::SHF_GROUP; MCSectionELF *EHSection = getContext().getELFSection( EHSecName, Type, Flags, 0, Group, FnSection.getUniqueID(), - static_cast<const MCSymbolELF *>(&Fn)); + static_cast<const MCSymbolELF *>(FnSection.getBeginSymbol())); assert(EHSection && "Failed to get the required EH section"); // Switch to .ARM.extab or .ARM.exidx section SwitchSection(EHSection); - EmitCodeAlignment(4); + emitCodeAlignment(4); } inline void ARMELFStreamer::SwitchToExTabSection(const MCSymbol &FnStart) { @@ -1258,7 +1251,7 @@ void ARMELFStreamer::EHReset() { void ARMELFStreamer::emitFnStart() { assert(FnStart == nullptr); FnStart = getContext().createTempSymbol(); - EmitLabel(FnStart); + emitLabel(FnStart); } void ARMELFStreamer::emitFnEnd() { @@ -1284,17 +1277,17 @@ void ARMELFStreamer::emitFnEnd() { MCSymbolRefExpr::VK_ARM_PREL31, getContext()); - EmitValue(FnStartRef, 4); + emitValue(FnStartRef, 4); if (CantUnwind) { - EmitIntValue(ARM::EHABI::EXIDX_CANTUNWIND, 4); + emitInt32(ARM::EHABI::EXIDX_CANTUNWIND); } else if (ExTab) { // Emit a reference to the unwind opcodes in the ".ARM.extab" section. const MCSymbolRefExpr *ExTabEntryRef = MCSymbolRefExpr::create(ExTab, MCSymbolRefExpr::VK_ARM_PREL31, getContext()); - EmitValue(ExTabEntryRef, 4); + emitValue(ExTabEntryRef, 4); } else { // For the __aeabi_unwind_cpp_pr0, we have to emit the unwind opcodes in // the second word of exception index table entry. The size of the unwind @@ -1307,7 +1300,7 @@ void ARMELFStreamer::emitFnEnd() { Opcodes[1] << 8 | Opcodes[2] << 16 | Opcodes[3] << 24; - EmitIntValue(Intval, Opcodes.size()); + emitIntValue(Intval, Opcodes.size()); } // Switch to the section containing FnStart @@ -1366,7 +1359,7 @@ void ARMELFStreamer::FlushUnwindOpcodes(bool NoHandlerData) { // Create .ARM.extab label for offset in .ARM.exidx assert(!ExTab); ExTab = getContext().createTempSymbol(); - EmitLabel(ExTab); + emitLabel(ExTab); // Emit personality if (Personality) { @@ -1375,7 +1368,7 @@ void ARMELFStreamer::FlushUnwindOpcodes(bool NoHandlerData) { MCSymbolRefExpr::VK_ARM_PREL31, getContext()); - EmitValue(PersonalityRef, 4); + emitValue(PersonalityRef, 4); } // Emit unwind opcodes @@ -1386,7 +1379,7 @@ void ARMELFStreamer::FlushUnwindOpcodes(bool NoHandlerData) { Opcodes[I + 1] << 8 | Opcodes[I + 2] << 16 | Opcodes[I + 3] << 24; - EmitIntValue(Intval, 4); + emitInt32(Intval); } // According to ARM EHABI section 9.2, if the __aeabi_unwind_cpp_pr1() or @@ -1397,7 +1390,7 @@ void ARMELFStreamer::FlushUnwindOpcodes(bool NoHandlerData) { // In case that the .handlerdata directive is not specified by the // programmer, we should emit zero to terminate the handler data. if (NoHandlerData && !Personality) - EmitIntValue(0, 4); + emitInt32(0); } void ARMELFStreamer::emitHandlerData() { FlushUnwindOpcodes(false); } |