diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2015-06-21 13:59:01 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2015-06-21 13:59:01 +0000 |
commit | 3a0822f094b578157263e04114075ad7df81db41 (patch) | |
tree | bc48361fe2cd1ca5f93ac01b38b183774468fc79 /lib/MC | |
parent | 85d8b2bbe386bcfe669575d05b61482d7be07e5d (diff) | |
download | src-test2-3a0822f094b578157263e04114075ad7df81db41.tar.gz src-test2-3a0822f094b578157263e04114075ad7df81db41.zip |
Notes
Diffstat (limited to 'lib/MC')
-rw-r--r-- | lib/MC/ELFObjectWriter.cpp | 3 | ||||
-rw-r--r-- | lib/MC/MCAsmStreamer.cpp | 5 | ||||
-rw-r--r-- | lib/MC/MCAssembler.cpp | 142 | ||||
-rw-r--r-- | lib/MC/MCContext.cpp | 30 | ||||
-rw-r--r-- | lib/MC/MCDisassembler/MCExternalSymbolizer.cpp | 2 | ||||
-rw-r--r-- | lib/MC/MCDisassembler/MCRelocationInfo.cpp | 3 | ||||
-rw-r--r-- | lib/MC/MCDwarf.cpp | 21 | ||||
-rw-r--r-- | lib/MC/MCELFStreamer.cpp | 2 | ||||
-rw-r--r-- | lib/MC/MCNullStreamer.cpp | 2 | ||||
-rw-r--r-- | lib/MC/MCObjectFileInfo.cpp | 17 | ||||
-rw-r--r-- | lib/MC/MCObjectStreamer.cpp | 15 | ||||
-rw-r--r-- | lib/MC/MCParser/AsmParser.cpp | 10 | ||||
-rw-r--r-- | lib/MC/MCParser/CMakeLists.txt | 2 | ||||
-rw-r--r-- | lib/MC/MCParser/COFFAsmParser.cpp | 2 | ||||
-rw-r--r-- | lib/MC/MCParser/ELFAsmParser.cpp | 2 | ||||
-rw-r--r-- | lib/MC/MCStreamer.cpp | 25 | ||||
-rw-r--r-- | lib/MC/MCSubtargetInfo.cpp | 17 | ||||
-rw-r--r-- | lib/MC/MCSymbol.cpp | 19 | ||||
-rw-r--r-- | lib/MC/MCSymbolELF.cpp | 18 | ||||
-rw-r--r-- | lib/MC/MCWin64EH.cpp | 2 | ||||
-rw-r--r-- | lib/MC/MCWinEH.cpp | 4 | ||||
-rw-r--r-- | lib/MC/WinCOFFObjectWriter.cpp | 11 | ||||
-rw-r--r-- | lib/MC/WinCOFFStreamer.cpp | 12 |
23 files changed, 218 insertions, 148 deletions
diff --git a/lib/MC/ELFObjectWriter.cpp b/lib/MC/ELFObjectWriter.cpp index 0765937d0ea8..c9df8fcf441c 100644 --- a/lib/MC/ELFObjectWriter.cpp +++ b/lib/MC/ELFObjectWriter.cpp @@ -144,6 +144,7 @@ class ELFObjectWriter : public MCObjectWriter { Renames.clear(); Relocations.clear(); StrTabBuilder.clear(); + SymtabShndxSectionIndex = 0; SectionTable.clear(); MCObjectWriter::reset(); } @@ -231,7 +232,7 @@ class ELFObjectWriter : public MCObjectWriter { uint32_t GroupSymbolIndex, uint64_t Offset, uint64_t Size, const MCSectionELF &Section); }; -} +} // namespace void ELFObjectWriter::align(unsigned Alignment) { uint64_t Padding = OffsetToAlignment(OS.tell(), Alignment); diff --git a/lib/MC/MCAsmStreamer.cpp b/lib/MC/MCAsmStreamer.cpp index 0f405ad1193e..9a65a3158972 100644 --- a/lib/MC/MCAsmStreamer.cpp +++ b/lib/MC/MCAsmStreamer.cpp @@ -1308,7 +1308,10 @@ void MCAsmStreamer::EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &S GetCommentOS() << "\n"; } - InstPrinter->printInst(&Inst, OS, "", STI); + if(getTargetStreamer()) + getTargetStreamer()->prettyPrintAsm(*InstPrinter, OS, Inst, STI); + else + InstPrinter->printInst(&Inst, OS, "", STI); EmitEOL(); } diff --git a/lib/MC/MCAssembler.cpp b/lib/MC/MCAssembler.cpp index 55f50097744d..34211aa901fa 100644 --- a/lib/MC/MCAssembler.cpp +++ b/lib/MC/MCAssembler.cpp @@ -54,8 +54,8 @@ STATISTIC(FragmentLayouts, "Number of fragment layouts"); STATISTIC(ObjectBytes, "Number of emitted object file bytes"); STATISTIC(RelaxationSteps, "Number of assembler layout and relaxation steps"); STATISTIC(RelaxedInstructions, "Number of relaxed instructions"); -} -} +} // namespace stats +} // namespace // FIXME FIXME FIXME: There are number of places in this file where we convert // what is a 64-bit assembler value used for computation into a value in the @@ -262,26 +262,64 @@ uint64_t llvm::computeBundlePadding(const MCAssembler &Assembler, /* *** */ -MCFragment::MCFragment() : Kind(FragmentType(~0)) { +void ilist_node_traits<MCFragment>::deleteNode(MCFragment *V) { + V->destroy(); } -MCFragment::~MCFragment() { +MCFragment::MCFragment() : Kind(FragmentType(~0)), HasInstructions(false), + AlignToBundleEnd(false), BundlePadding(0) { } -MCFragment::MCFragment(FragmentType Kind, MCSection *Parent) - : Kind(Kind), Parent(Parent), Atom(nullptr), Offset(~UINT64_C(0)) { +MCFragment::~MCFragment() { } + +MCFragment::MCFragment(FragmentType Kind, bool HasInstructions, + uint8_t BundlePadding, MCSection *Parent) + : Kind(Kind), HasInstructions(HasInstructions), AlignToBundleEnd(false), + BundlePadding(BundlePadding), Parent(Parent), Atom(nullptr), + Offset(~UINT64_C(0)) { if (Parent) Parent->getFragmentList().push_back(this); } -/* *** */ - -MCEncodedFragment::~MCEncodedFragment() { -} - -/* *** */ +void MCFragment::destroy() { + // First check if we are the sentinal. + if (Kind == FragmentType(~0)) { + delete this; + return; + } -MCEncodedFragmentWithFixups::~MCEncodedFragmentWithFixups() { + switch (Kind) { + case FT_Align: + delete cast<MCAlignFragment>(this); + return; + case FT_Data: + delete cast<MCDataFragment>(this); + return; + case FT_CompactEncodedInst: + delete cast<MCCompactEncodedInstFragment>(this); + return; + case FT_Fill: + delete cast<MCFillFragment>(this); + return; + case FT_Relaxable: + delete cast<MCRelaxableFragment>(this); + return; + case FT_Org: + delete cast<MCOrgFragment>(this); + return; + case FT_Dwarf: + delete cast<MCDwarfLineAddrFragment>(this); + return; + case FT_DwarfFrame: + delete cast<MCDwarfCallFrameFragment>(this); + return; + case FT_LEB: + delete cast<MCLEBFragment>(this); + return; + case FT_SafeSEH: + delete cast<MCSafeSEHFragment>(this); + return; + } } /* *** */ @@ -345,16 +383,6 @@ bool MCAssembler::isThumbFunc(const MCSymbol *Symbol) const { return true; } -void MCAssembler::addLocalUsedInReloc(const MCSymbol &Sym) { - assert(Sym.isTemporary()); - LocalsUsedInReloc.insert(&Sym); -} - -bool MCAssembler::isLocalUsedInReloc(const MCSymbol &Sym) const { - assert(Sym.isTemporary()); - return LocalsUsedInReloc.count(&Sym); -} - bool MCAssembler::isSymbolLinkerVisible(const MCSymbol &Symbol) const { // Non-temporary labels should always be visible to the linker. if (!Symbol.isTemporary()) @@ -364,7 +392,7 @@ bool MCAssembler::isSymbolLinkerVisible(const MCSymbol &Symbol) const { if (!Symbol.isInSection()) return false; - if (isLocalUsedInReloc(Symbol)) + if (Symbol.isUsedInReloc()) return true; return false; @@ -464,9 +492,11 @@ uint64_t MCAssembler::computeFragmentSize(const MCAsmLayout &Layout, const MCFragment &F) const { switch (F.getKind()) { case MCFragment::FT_Data: + return cast<MCDataFragment>(F).getContents().size(); case MCFragment::FT_Relaxable: + return cast<MCRelaxableFragment>(F).getContents().size(); case MCFragment::FT_CompactEncodedInst: - return cast<MCEncodedFragment>(F).getContents().size(); + return cast<MCCompactEncodedInstFragment>(F).getContents().size(); case MCFragment::FT_Fill: return cast<MCFillFragment>(F).getSize(); @@ -572,13 +602,6 @@ void MCAsmLayout::layoutFragment(MCFragment *F) { } } -/// \brief Write the contents of a fragment to the given object writer. Expects -/// a MCEncodedFragment. -static void writeFragmentContents(const MCFragment &F, MCObjectWriter *OW) { - const MCEncodedFragment &EF = cast<MCEncodedFragment>(F); - OW->writeBytes(EF.getContents()); -} - void MCAssembler::registerSymbol(const MCSymbol &Symbol, bool *Created) { bool New = !Symbol.isRegistered(); if (Created) @@ -681,17 +704,17 @@ static void writeFragment(const MCAssembler &Asm, const MCAsmLayout &Layout, case MCFragment::FT_Data: ++stats::EmittedDataFragments; - writeFragmentContents(F, OW); + OW->writeBytes(cast<MCDataFragment>(F).getContents()); break; case MCFragment::FT_Relaxable: ++stats::EmittedRelaxableFragments; - writeFragmentContents(F, OW); + OW->writeBytes(cast<MCRelaxableFragment>(F).getContents()); break; case MCFragment::FT_CompactEncodedInst: ++stats::EmittedCompactEncodedInstFragments; - writeFragmentContents(F, OW); + OW->writeBytes(cast<MCCompactEncodedInstFragment>(F).getContents()); break; case MCFragment::FT_Fill: { @@ -880,18 +903,29 @@ void MCAssembler::Finish() { for (MCAssembler::iterator it = begin(), ie = end(); it != ie; ++it) { for (MCSection::iterator it2 = it->begin(), ie2 = it->end(); it2 != ie2; ++it2) { - MCEncodedFragmentWithFixups *F = - dyn_cast<MCEncodedFragmentWithFixups>(it2); - if (F) { - for (MCEncodedFragmentWithFixups::fixup_iterator it3 = F->fixup_begin(), - ie3 = F->fixup_end(); it3 != ie3; ++it3) { - MCFixup &Fixup = *it3; - uint64_t FixedValue; - bool IsPCRel; - std::tie(FixedValue, IsPCRel) = handleFixup(Layout, *F, Fixup); - getBackend().applyFixup(Fixup, F->getContents().data(), - F->getContents().size(), FixedValue, IsPCRel); - } + MCEncodedFragment *F = dyn_cast<MCEncodedFragment>(it2); + // Data and relaxable fragments both have fixups. So only process + // those here. + // FIXME: Is there a better way to do this? MCEncodedFragmentWithFixups + // being templated makes this tricky. + if (!F || isa<MCCompactEncodedInstFragment>(F)) + continue; + ArrayRef<MCFixup> Fixups; + MutableArrayRef<char> Contents; + if (auto *FragWithFixups = dyn_cast<MCDataFragment>(F)) { + Fixups = FragWithFixups->getFixups(); + Contents = FragWithFixups->getContents(); + } else if (auto *FragWithFixups = dyn_cast<MCRelaxableFragment>(F)) { + Fixups = FragWithFixups->getFixups(); + Contents = FragWithFixups->getContents(); + } else + llvm_unreachable("Unknow fragment with fixups!"); + for (const MCFixup &Fixup : Fixups) { + uint64_t FixedValue; + bool IsPCRel; + std::tie(FixedValue, IsPCRel) = handleFixup(Layout, *F, Fixup); + getBackend().applyFixup(Fixup, Contents.data(), + Contents.size(), FixedValue, IsPCRel); } } } @@ -1228,17 +1262,3 @@ void MCAssembler::dump() { OS << "]>\n"; } #endif - -// anchors for MC*Fragment vtables -void MCEncodedFragment::anchor() { } -void MCEncodedFragmentWithFixups::anchor() { } -void MCDataFragment::anchor() { } -void MCCompactEncodedInstFragment::anchor() { } -void MCRelaxableFragment::anchor() { } -void MCAlignFragment::anchor() { } -void MCFillFragment::anchor() { } -void MCOrgFragment::anchor() { } -void MCLEBFragment::anchor() { } -void MCSafeSEHFragment::anchor() { } -void MCDwarfLineAddrFragment::anchor() { } -void MCDwarfCallFrameFragment::anchor() { } diff --git a/lib/MC/MCContext.cpp b/lib/MC/MCContext.cpp index 1e52eedaf188..c601c56f3952 100644 --- a/lib/MC/MCContext.cpp +++ b/lib/MC/MCContext.cpp @@ -135,7 +135,7 @@ MCSymbolELF *MCContext::getOrCreateSectionSymbol(const MCSectionELF &Section) { } auto NameIter = UsedNames.insert(std::make_pair(Name, true)).first; - Sym = new (*this) MCSymbolELF(&*NameIter, /*isTemporary*/ false); + Sym = new (&*NameIter, *this) MCSymbolELF(&*NameIter, /*isTemporary*/ false); if (!OldSym) OldSym = Sym; @@ -164,25 +164,26 @@ MCSymbol *MCContext::createSymbolImpl(const StringMapEntry<bool> *Name, if (MOFI) { switch (MOFI->getObjectFileType()) { case MCObjectFileInfo::IsCOFF: - return new (*this) MCSymbolCOFF(Name, IsTemporary); + return new (Name, *this) MCSymbolCOFF(Name, IsTemporary); case MCObjectFileInfo::IsELF: - return new (*this) MCSymbolELF(Name, IsTemporary); + return new (Name, *this) MCSymbolELF(Name, IsTemporary); case MCObjectFileInfo::IsMachO: - return new (*this) MCSymbolMachO(Name, IsTemporary); + return new (Name, *this) MCSymbolMachO(Name, IsTemporary); } } - return new (*this) MCSymbol(MCSymbol::SymbolKindUnset, Name, IsTemporary); + return new (Name, *this) MCSymbol(MCSymbol::SymbolKindUnset, Name, + IsTemporary); } MCSymbol *MCContext::createSymbol(StringRef Name, bool AlwaysAddSuffix, - bool IsTemporary) { - if (IsTemporary && !UseNamesOnTempLabels) + bool CanBeUnnamed) { + if (CanBeUnnamed && !UseNamesOnTempLabels) return createSymbolImpl(nullptr, true); // Determine whether this is an user writter assembler temporary or normal // label, if used. - IsTemporary = false; - if (AllowTemporaryLabels) + bool IsTemporary = CanBeUnnamed; + if (AllowTemporaryLabels && !IsTemporary) IsTemporary = Name.startswith(MAI->getPrivateGlobalPrefix()); SmallString<128> NewName = Name; @@ -205,10 +206,11 @@ MCSymbol *MCContext::createSymbol(StringRef Name, bool AlwaysAddSuffix, llvm_unreachable("Infinite loop"); } -MCSymbol *MCContext::createTempSymbol(const Twine &Name, bool AlwaysAddSuffix) { +MCSymbol *MCContext::createTempSymbol(const Twine &Name, bool AlwaysAddSuffix, + bool CanBeUnnamed) { SmallString<128> NameSV; raw_svector_ostream(NameSV) << MAI->getPrivateGlobalPrefix() << Name; - return createSymbol(NameSV, AlwaysAddSuffix, true); + return createSymbol(NameSV, AlwaysAddSuffix, CanBeUnnamed); } MCSymbol *MCContext::createLinkerPrivateTempSymbol() { @@ -217,8 +219,8 @@ MCSymbol *MCContext::createLinkerPrivateTempSymbol() { return createSymbol(NameSV, true, false); } -MCSymbol *MCContext::createTempSymbol() { - return createTempSymbol("tmp", true); +MCSymbol *MCContext::createTempSymbol(bool CanBeUnnamed) { + return createTempSymbol("tmp", true, CanBeUnnamed); } unsigned MCContext::NextInstance(unsigned LocalLabelVal) { @@ -239,7 +241,7 @@ MCSymbol *MCContext::getOrCreateDirectionalLocalSymbol(unsigned LocalLabelVal, unsigned Instance) { MCSymbol *&Sym = LocalSymbols[std::make_pair(LocalLabelVal, Instance)]; if (!Sym) - Sym = createTempSymbol(); + Sym = createTempSymbol(false); return Sym; } diff --git a/lib/MC/MCDisassembler/MCExternalSymbolizer.cpp b/lib/MC/MCDisassembler/MCExternalSymbolizer.cpp index 68948d36d65c..b9aebfc617f9 100644 --- a/lib/MC/MCDisassembler/MCExternalSymbolizer.cpp +++ b/lib/MC/MCDisassembler/MCExternalSymbolizer.cpp @@ -193,4 +193,4 @@ MCSymbolizer *createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo, return new MCExternalSymbolizer(*Ctx, std::move(RelInfo), GetOpInfo, SymbolLookUp, DisInfo); } -} +} // namespace llvm diff --git a/lib/MC/MCDisassembler/MCRelocationInfo.cpp b/lib/MC/MCDisassembler/MCRelocationInfo.cpp index ff0c27f5faf3..43005e7c740c 100644 --- a/lib/MC/MCDisassembler/MCRelocationInfo.cpp +++ b/lib/MC/MCDisassembler/MCRelocationInfo.cpp @@ -34,6 +34,7 @@ MCRelocationInfo::createExprForCAPIVariantKind(const MCExpr *SubExpr, return SubExpr; } -MCRelocationInfo *llvm::createMCRelocationInfo(StringRef TT, MCContext &Ctx) { +MCRelocationInfo *llvm::createMCRelocationInfo(const Triple &TT, + MCContext &Ctx) { return new MCRelocationInfo(Ctx); } diff --git a/lib/MC/MCDwarf.cpp b/lib/MC/MCDwarf.cpp index 90f96e2cef54..4ae2bcfab72b 100644 --- a/lib/MC/MCDwarf.cpp +++ b/lib/MC/MCDwarf.cpp @@ -1461,7 +1461,7 @@ namespace { bool IsSignalFrame; bool IsSimple; }; -} +} // namespace namespace llvm { template <> @@ -1488,7 +1488,7 @@ namespace llvm { LHS.IsSimple == RHS.IsSimple; } }; -} +} // namespace llvm void MCDwarfFrameEmitter::Emit(MCObjectStreamer &Streamer, MCAsmBackend *MAB, bool IsEH) { @@ -1590,18 +1590,17 @@ void MCDwarfFrameEmitter::EncodeAdvanceLoc(MCContext &Context, OS << uint8_t(dwarf::DW_CFA_advance_loc1); OS << uint8_t(AddrDelta); } else if (isUInt<16>(AddrDelta)) { - // FIXME: check what is the correct behavior on a big endian machine. OS << uint8_t(dwarf::DW_CFA_advance_loc2); - OS << uint8_t( AddrDelta & 0xff); - OS << uint8_t((AddrDelta >> 8) & 0xff); + if (Context.getAsmInfo()->isLittleEndian()) + support::endian::Writer<support::little>(OS).write<uint16_t>(AddrDelta); + else + support::endian::Writer<support::big>(OS).write<uint16_t>(AddrDelta); } else { - // FIXME: check what is the correct behavior on a big endian machine. assert(isUInt<32>(AddrDelta)); OS << uint8_t(dwarf::DW_CFA_advance_loc4); - OS << uint8_t( AddrDelta & 0xff); - OS << uint8_t((AddrDelta >> 8) & 0xff); - OS << uint8_t((AddrDelta >> 16) & 0xff); - OS << uint8_t((AddrDelta >> 24) & 0xff); - + if (Context.getAsmInfo()->isLittleEndian()) + support::endian::Writer<support::little>(OS).write<uint32_t>(AddrDelta); + else + support::endian::Writer<support::big>(OS).write<uint32_t>(AddrDelta); } } diff --git a/lib/MC/MCELFStreamer.cpp b/lib/MC/MCELFStreamer.cpp index e0f4a2ae16a3..fe9ac21e17fc 100644 --- a/lib/MC/MCELFStreamer.cpp +++ b/lib/MC/MCELFStreamer.cpp @@ -45,7 +45,7 @@ MCELFStreamer::~MCELFStreamer() { } void MCELFStreamer::mergeFragment(MCDataFragment *DF, - MCEncodedFragmentWithFixups *EF) { + MCDataFragment *EF) { MCAssembler &Assembler = getAssembler(); if (Assembler.isBundlingEnabled() && Assembler.getRelaxAll()) { diff --git a/lib/MC/MCNullStreamer.cpp b/lib/MC/MCNullStreamer.cpp index eb2d91254b34..e0f610bf4ac4 100644 --- a/lib/MC/MCNullStreamer.cpp +++ b/lib/MC/MCNullStreamer.cpp @@ -36,7 +36,7 @@ namespace { void EmitGPRel32Value(const MCExpr *Value) override {} }; -} +} // namespace MCStreamer *llvm::createNullStreamer(MCContext &Context) { return new MCNullStreamer(Context); diff --git a/lib/MC/MCObjectFileInfo.cpp b/lib/MC/MCObjectFileInfo.cpp index 83a08e28a816..aa3d965bbce1 100644 --- a/lib/MC/MCObjectFileInfo.cpp +++ b/lib/MC/MCObjectFileInfo.cpp @@ -238,6 +238,9 @@ void MCObjectFileInfo::initMachOMCObjectFileInfo(Triple T) { StackMapSection = Ctx->getMachOSection("__LLVM_STACKMAPS", "__llvm_stackmaps", 0, SectionKind::getMetadata()); + FaultMapSection = Ctx->getMachOSection("__LLVM_FAULTMAPS", "__llvm_faultmaps", + 0, SectionKind::getMetadata()); + TLSExtraDataSection = TLSTLVSection; } @@ -518,6 +521,9 @@ void MCObjectFileInfo::initELFMCObjectFileInfo(Triple T) { StackMapSection = Ctx->getELFSection(".llvm_stackmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC); + + FaultMapSection = + Ctx->getELFSection(".llvm_faultmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC); } void MCObjectFileInfo::initCOFFMCObjectFileInfo(Triple T) { @@ -729,7 +735,8 @@ void MCObjectFileInfo::initCOFFMCObjectFileInfo(Triple T) { SectionKind::getDataRel()); } -void MCObjectFileInfo::InitMCObjectFileInfo(StringRef T, Reloc::Model relocm, +void MCObjectFileInfo::InitMCObjectFileInfo(const Triple &TheTriple, + Reloc::Model relocm, CodeModel::Model cm, MCContext &ctx) { RelocM = relocm; @@ -753,7 +760,7 @@ void MCObjectFileInfo::InitMCObjectFileInfo(StringRef T, Reloc::Model relocm, DwarfAccelNamespaceSection = nullptr; // Used only by selected targets. DwarfAccelTypesSection = nullptr; // Used only by selected targets. - TT = Triple(T); + TT = TheTriple; Triple::ArchType Arch = TT.getArch(); // FIXME: Checking for Arch here to filter out bogus triples such as @@ -777,6 +784,12 @@ void MCObjectFileInfo::InitMCObjectFileInfo(StringRef T, Reloc::Model relocm, } } +void MCObjectFileInfo::InitMCObjectFileInfo(StringRef TT, Reloc::Model RM, + CodeModel::Model CM, + MCContext &ctx) { + InitMCObjectFileInfo(Triple(TT), RM, CM, ctx); +} + MCSection *MCObjectFileInfo::getDwarfTypesSection(uint64_t Hash) const { return Ctx->getELFSection(".debug_types", ELF::SHT_PROGBITS, ELF::SHF_GROUP, 0, utostr(Hash)); diff --git a/lib/MC/MCObjectStreamer.cpp b/lib/MC/MCObjectStreamer.cpp index 6de02bcb02d8..a73c171bd1c0 100644 --- a/lib/MC/MCObjectStreamer.cpp +++ b/lib/MC/MCObjectStreamer.cpp @@ -54,21 +54,18 @@ void MCObjectStreamer::flushPendingLabels(MCFragment *F, uint64_t FOffset) { } } -bool MCObjectStreamer::emitAbsoluteSymbolDiff(const MCSymbol *Hi, +void MCObjectStreamer::emitAbsoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo, unsigned Size) { - // Must both be assigned to the same (valid) fragment. - if (!Hi->getFragment() || Hi->getFragment() != Lo->getFragment()) - return false; - - // Must be a data fragment. - if (!isa<MCDataFragment>(Hi->getFragment())) - return false; + // If not assigned to the same (valid) fragment, fallback. + if (!Hi->getFragment() || Hi->getFragment() != Lo->getFragment()) { + MCStreamer::emitAbsoluteSymbolDiff(Hi, Lo, Size); + return; + } assert(Hi->getOffset() >= Lo->getOffset() && "Expected Hi to be greater than Lo"); EmitIntValue(Hi->getOffset() - Lo->getOffset(), Size); - return true; } void MCObjectStreamer::reset() { diff --git a/lib/MC/MCParser/AsmParser.cpp b/lib/MC/MCParser/AsmParser.cpp index 20366dc4e4f5..9c1062f8f588 100644 --- a/lib/MC/MCParser/AsmParser.cpp +++ b/lib/MC/MCParser/AsmParser.cpp @@ -484,7 +484,7 @@ private: void initializeDirectiveKindMap(); }; -} +} // namespace namespace llvm { @@ -1306,8 +1306,10 @@ bool AsmParser::parseStatement(ParseStatementInfo &Info, MCSymbol *Sym; if (LocalLabelVal == -1) { if (ParsingInlineAsm && SI) { - StringRef RewrittenLabel = SI->LookupInlineAsmLabel(IDVal, getSourceManager(), IDLoc, true); - assert(RewrittenLabel.size() && "We should have an internal name here."); + StringRef RewrittenLabel = + SI->LookupInlineAsmLabel(IDVal, getSourceManager(), IDLoc, true); + assert(RewrittenLabel.size() && + "We should have an internal name here."); Info.AsmRewrites->push_back(AsmRewrite(AOK_Label, IDLoc, IDVal.size(), RewrittenLabel)); IDVal = RewrittenLabel; @@ -1942,7 +1944,7 @@ public: private: AsmLexer &Lexer; }; -} +} // namespace bool AsmParser::parseMacroArgument(MCAsmMacroArgument &MA, bool Vararg) { diff --git a/lib/MC/MCParser/CMakeLists.txt b/lib/MC/MCParser/CMakeLists.txt index 957c94edc53e..99fdd0167993 100644 --- a/lib/MC/MCParser/CMakeLists.txt +++ b/lib/MC/MCParser/CMakeLists.txt @@ -10,5 +10,5 @@ add_llvm_library(LLVMMCParser MCTargetAsmParser.cpp ADDITIONAL_HEADER_DIRS - ${LLVM_MAIN_INCLUDE_DIR}/llvm/MCParser + ${LLVM_MAIN_INCLUDE_DIR}/llvm/MC/MCParser ) diff --git a/lib/MC/MCParser/COFFAsmParser.cpp b/lib/MC/MCParser/COFFAsmParser.cpp index f09bce005d6a..1480f5b4576c 100644 --- a/lib/MC/MCParser/COFFAsmParser.cpp +++ b/lib/MC/MCParser/COFFAsmParser.cpp @@ -145,7 +145,7 @@ public: COFFAsmParser() {} }; -} // end annonomous namespace. +} // namespace static SectionKind computeSectionKind(unsigned Flags) { if (Flags & COFF::IMAGE_SCN_MEM_EXECUTE) diff --git a/lib/MC/MCParser/ELFAsmParser.cpp b/lib/MC/MCParser/ELFAsmParser.cpp index e3585bd27632..e131b238965d 100644 --- a/lib/MC/MCParser/ELFAsmParser.cpp +++ b/lib/MC/MCParser/ELFAsmParser.cpp @@ -154,7 +154,7 @@ private: unsigned parseSunStyleSectionFlags(); }; -} +} // namespace /// ParseDirectiveSymbolAttribute /// ::= { ".local", ".weak", ... } [ identifier ( , identifier )* ] diff --git a/lib/MC/MCStreamer.cpp b/lib/MC/MCStreamer.cpp index 011969a3da01..7fbbbd95b560 100644 --- a/lib/MC/MCStreamer.cpp +++ b/lib/MC/MCStreamer.cpp @@ -15,6 +15,7 @@ #include "llvm/MC/MCContext.h" #include "llvm/MC/MCExpr.h" #include "llvm/MC/MCInst.h" +#include "llvm/MC/MCInstPrinter.h" #include "llvm/MC/MCObjectFileInfo.h" #include "llvm/MC/MCObjectWriter.h" #include "llvm/MC/MCSection.h" @@ -601,6 +602,11 @@ void MCStreamer::EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) { TS->emitAssignment(Symbol, Value); } +void MCTargetStreamer::prettyPrintAsm(MCInstPrinter &InstPrinter, raw_ostream &OS, + const MCInst &Inst, const MCSubtargetInfo &STI) { + InstPrinter.printInst(&Inst, OS, "", STI); +} + void MCStreamer::visitUsedSymbol(const MCSymbol &Sym) { } @@ -638,6 +644,25 @@ void MCStreamer::EmitInstruction(const MCInst &Inst, visitUsedExpr(*Inst.getOperand(i).getExpr()); } +void MCStreamer::emitAbsoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo, + unsigned Size) { + // Get the Hi-Lo expression. + const MCExpr *Diff = + MCBinaryExpr::createSub(MCSymbolRefExpr::create(Hi, Context), + MCSymbolRefExpr::create(Lo, Context), Context); + + const MCAsmInfo *MAI = Context.getAsmInfo(); + if (!MAI->doesSetDirectiveSuppressesReloc()) { + EmitValue(Diff, Size); + return; + } + + // Otherwise, emit with .set (aka assignment). + MCSymbol *SetLabel = Context.createTempSymbol("set", true); + EmitAssignment(SetLabel, Diff); + EmitSymbolValue(SetLabel, Size); +} + void MCStreamer::EmitAssemblerFlag(MCAssemblerFlag Flag) {} void MCStreamer::EmitThumbFunc(MCSymbol *Func) {} void MCStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {} diff --git a/lib/MC/MCSubtargetInfo.cpp b/lib/MC/MCSubtargetInfo.cpp index 7954a02d83b2..ece775c4f08f 100644 --- a/lib/MC/MCSubtargetInfo.cpp +++ b/lib/MC/MCSubtargetInfo.cpp @@ -34,17 +34,12 @@ MCSubtargetInfo::InitCPUSchedModel(StringRef CPU) { CPUSchedModel = MCSchedModel::GetDefaultSchedModel(); } -void -MCSubtargetInfo::InitMCSubtargetInfo(StringRef TT, StringRef C, StringRef FS, - ArrayRef<SubtargetFeatureKV> PF, - ArrayRef<SubtargetFeatureKV> PD, - const SubtargetInfoKV *ProcSched, - const MCWriteProcResEntry *WPR, - const MCWriteLatencyEntry *WL, - const MCReadAdvanceEntry *RA, - const InstrStage *IS, - const unsigned *OC, - const unsigned *FP) { +void MCSubtargetInfo::InitMCSubtargetInfo( + const Triple &TT, StringRef C, StringRef FS, + ArrayRef<SubtargetFeatureKV> PF, ArrayRef<SubtargetFeatureKV> PD, + const SubtargetInfoKV *ProcSched, const MCWriteProcResEntry *WPR, + const MCWriteLatencyEntry *WL, const MCReadAdvanceEntry *RA, + const InstrStage *IS, const unsigned *OC, const unsigned *FP) { TargetTriple = TT; CPU = C; ProcFeatures = PF; diff --git a/lib/MC/MCSymbol.cpp b/lib/MC/MCSymbol.cpp index 8d07b7605cea..448422132808 100644 --- a/lib/MC/MCSymbol.cpp +++ b/lib/MC/MCSymbol.cpp @@ -9,6 +9,7 @@ #include "llvm/MC/MCSymbol.h" #include "llvm/MC/MCAsmInfo.h" +#include "llvm/MC/MCContext.h" #include "llvm/MC/MCExpr.h" #include "llvm/Support/Debug.h" #include "llvm/Support/ErrorHandling.h" @@ -18,6 +19,24 @@ using namespace llvm; // Sentinel value for the absolute pseudo section. MCSection *MCSymbol::AbsolutePseudoSection = reinterpret_cast<MCSection *>(1); +void *MCSymbol::operator new(size_t s, const StringMapEntry<bool> *Name, + MCContext &Ctx) { + // We may need more space for a Name to account for alignment. So allocate + // space for the storage type and not the name pointer. + size_t Size = s + (Name ? sizeof(NameEntryStorageTy) : 0); + + // For safety, ensure that the alignment of a pointer is enough for an + // MCSymbol. This also ensures we don't need padding between the name and + // symbol. + static_assert((unsigned)AlignOf<MCSymbol>::Alignment <= + AlignOf<NameEntryStorageTy>::Alignment, + "Bad alignment of MCSymbol"); + void *Storage = Ctx.allocate(Size, alignOf<NameEntryStorageTy>()); + NameEntryStorageTy *Start = static_cast<NameEntryStorageTy*>(Storage); + NameEntryStorageTy *End = Start + (Name ? 1 : 0); + return End; +} + void MCSymbol::setVariableValue(const MCExpr *Value) { assert(!IsUsed && "Cannot set a variable that has already been used."); assert(Value && "Invalid variable value!"); diff --git a/lib/MC/MCSymbolELF.cpp b/lib/MC/MCSymbolELF.cpp index c3620651f883..6ec70ed3a9fe 100644 --- a/lib/MC/MCSymbolELF.cpp +++ b/lib/MC/MCSymbolELF.cpp @@ -36,12 +36,9 @@ enum { ELF_WeakrefUsedInReloc_Shift = 11, // One bit. - ELF_UsedInReloc_Shift = 12, - - // One bit. - ELF_BindingSet_Shift = 13 + ELF_BindingSet_Shift = 12 }; -} +} // namespace void MCSymbolELF::setBinding(unsigned Binding) const { setIsBindingSet(); @@ -175,15 +172,6 @@ unsigned MCSymbolELF::getOther() const { return Other << 5; } -void MCSymbolELF::setUsedInReloc() const { - uint32_t OtherFlags = getFlags() & ~(0x1 << ELF_UsedInReloc_Shift); - setFlags(OtherFlags | (1 << ELF_UsedInReloc_Shift)); -} - -bool MCSymbolELF::isUsedInReloc() const { - return getFlags() & (0x1 << ELF_UsedInReloc_Shift); -} - void MCSymbolELF::setIsWeakrefUsedInReloc() const { uint32_t OtherFlags = getFlags() & ~(0x1 << ELF_WeakrefUsedInReloc_Shift); setFlags(OtherFlags | (1 << ELF_WeakrefUsedInReloc_Shift)); @@ -210,4 +198,4 @@ void MCSymbolELF::setIsBindingSet() const { bool MCSymbolELF::isBindingSet() const { return getFlags() & (0x1 << ELF_BindingSet_Shift); } -} +} // namespace llvm diff --git a/lib/MC/MCWin64EH.cpp b/lib/MC/MCWin64EH.cpp index 1b73b7afb6a0..d8280c7c0141 100644 --- a/lib/MC/MCWin64EH.cpp +++ b/lib/MC/MCWin64EH.cpp @@ -247,6 +247,6 @@ void UnwindEmitter::EmitUnwindInfo(MCStreamer &Streamer, llvm::EmitUnwindInfo(Streamer, info); } -} +} // namespace Win64EH } // End of namespace llvm diff --git a/lib/MC/MCWinEH.cpp b/lib/MC/MCWinEH.cpp index d5d9eadf39a0..9cf2edf2a56c 100644 --- a/lib/MC/MCWinEH.cpp +++ b/lib/MC/MCWinEH.cpp @@ -74,6 +74,6 @@ MCSection *UnwindEmitter::getXDataSection(const MCSymbol *Function, return getUnwindInfoSection(".xdata", XData, Function, Context); } -} -} +} // namespace WinEH +} // namespace llvm diff --git a/lib/MC/WinCOFFObjectWriter.cpp b/lib/MC/WinCOFFObjectWriter.cpp index 423c7dce45da..5bc1404e83aa 100644 --- a/lib/MC/WinCOFFObjectWriter.cpp +++ b/lib/MC/WinCOFFObjectWriter.cpp @@ -191,7 +191,7 @@ public: void writeObject(MCAssembler &Asm, const MCAsmLayout &Layout) override; }; -} +} // namespace static inline void write_uint32_le(void *Data, uint32_t Value) { support::endian::write<uint32_t, support::little, support::unaligned>(Data, @@ -526,13 +526,12 @@ bool WinCOFFObjectWriter::ExportSymbol(const MCSymbol &Symbol, if (!Symbol.isTemporary()) return true; - // Absolute temporary labels are never visible. - if (!Symbol.isInSection()) + // Temporary variable symbols are invisible. + if (Symbol.isVariable()) return false; - // For now, all non-variable symbols are exported, - // the linker will sort the rest out for us. - return !Symbol.isVariable(); + // Absolute temporary labels are never visible. + return !Symbol.isAbsolute(); } bool WinCOFFObjectWriter::IsPhysicalSection(COFFSection *S) { diff --git a/lib/MC/WinCOFFStreamer.cpp b/lib/MC/WinCOFFStreamer.cpp index 41fc8e4681ef..4ecdc3b79a76 100644 --- a/lib/MC/WinCOFFStreamer.cpp +++ b/lib/MC/WinCOFFStreamer.cpp @@ -164,7 +164,8 @@ void MCWinCOFFStreamer::EmitCOFFSafeSEH(MCSymbol const *Symbol) { Triple::x86) return; - if (cast<MCSymbolCOFF>(Symbol)->isSafeSEH()) + const MCSymbolCOFF *CSymbol = cast<MCSymbolCOFF>(Symbol); + if (CSymbol->isSafeSEH()) return; MCSection *SXData = getContext().getObjectFileInfo()->getSXDataSection(); @@ -175,7 +176,12 @@ void MCWinCOFFStreamer::EmitCOFFSafeSEH(MCSymbol const *Symbol) { new MCSafeSEHFragment(Symbol, SXData); getAssembler().registerSymbol(*Symbol); - cast<MCSymbolCOFF>(Symbol)->setIsSafeSEH(); + CSymbol->setIsSafeSEH(); + + // The Microsoft linker requires that the symbol type of a handler be + // function. Go ahead and oblige it here. + CSymbol->setType(COFF::IMAGE_SYM_DTYPE_FUNCTION + << COFF::SCT_COMPLEX_TYPE_SHIFT); } void MCWinCOFFStreamer::EmitCOFFSectionIndex(MCSymbol const *Symbol) { @@ -285,5 +291,5 @@ LLVM_ATTRIBUTE_NORETURN void MCWinCOFFStreamer::FatalError(const Twine &Msg) const { getContext().reportFatalError(SMLoc(), Msg); } -} +} // namespace llvm |