本文整理汇总了C++中MCStreamer::getContext方法的典型用法代码示例。如果您正苦于以下问题:C++ MCStreamer::getContext方法的具体用法?C++ MCStreamer::getContext怎么用?C++ MCStreamer::getContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MCStreamer
的用法示例。
在下文中一共展示了MCStreamer::getContext方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LowerTlsAddr
static void LowerTlsAddr(MCStreamer &OutStreamer,
X86MCInstLower &MCInstLowering,
const MachineInstr &MI) {
bool is64Bits = MI.getOpcode() == X86::TLS_addr64;
MCContext &context = OutStreamer.getContext();
if (is64Bits) {
MCInst prefix;
prefix.setOpcode(X86::DATA16_PREFIX);
OutStreamer.EmitInstruction(prefix);
}
MCSymbol *sym = MCInstLowering.GetSymbolFromOperand(MI.getOperand(3));
const MCSymbolRefExpr *symRef =
MCSymbolRefExpr::Create(sym, MCSymbolRefExpr::VK_TLSGD, context);
MCInst LEA;
if (is64Bits) {
LEA.setOpcode(X86::LEA64r);
LEA.addOperand(MCOperand::CreateReg(X86::RDI)); // dest
LEA.addOperand(MCOperand::CreateReg(X86::RIP)); // base
LEA.addOperand(MCOperand::CreateImm(1)); // scale
LEA.addOperand(MCOperand::CreateReg(0)); // index
LEA.addOperand(MCOperand::CreateExpr(symRef)); // disp
LEA.addOperand(MCOperand::CreateReg(0)); // seg
} else {
LEA.setOpcode(X86::LEA32r);
LEA.addOperand(MCOperand::CreateReg(X86::EAX)); // dest
LEA.addOperand(MCOperand::CreateReg(0)); // base
LEA.addOperand(MCOperand::CreateImm(1)); // scale
LEA.addOperand(MCOperand::CreateReg(X86::EBX)); // index
LEA.addOperand(MCOperand::CreateExpr(symRef)); // disp
LEA.addOperand(MCOperand::CreateReg(0)); // seg
}
OutStreamer.EmitInstruction(LEA);
if (is64Bits) {
MCInst prefix;
prefix.setOpcode(X86::DATA16_PREFIX);
OutStreamer.EmitInstruction(prefix);
prefix.setOpcode(X86::DATA16_PREFIX);
OutStreamer.EmitInstruction(prefix);
prefix.setOpcode(X86::REX64_PREFIX);
OutStreamer.EmitInstruction(prefix);
}
MCInst call;
if (is64Bits)
call.setOpcode(X86::CALL64pcrel32);
else
call.setOpcode(X86::CALLpcrel32);
StringRef name = is64Bits ? "__tls_get_addr" : "___tls_get_addr";
MCSymbol *tlsGetAddr = context.GetOrCreateSymbol(name);
const MCSymbolRefExpr *tlsRef =
MCSymbolRefExpr::Create(tlsGetAddr,
MCSymbolRefExpr::VK_PLT,
context);
call.addOperand(MCOperand::CreateExpr(tlsRef));
OutStreamer.EmitInstruction(call);
}
示例2: EmitLabelDiff
static void EmitLabelDiff(MCStreamer &Streamer,
const MCSymbol *From, const MCSymbol *To) {
MCSymbolRefExpr::VariantKind Variant = MCSymbolRefExpr::VK_None;
MCContext &Context = Streamer.getContext();
const MCExpr *FromRef = MCSymbolRefExpr::Create(From, Variant, Context),
*ToRef = MCSymbolRefExpr::Create(To, Variant, Context);
const MCExpr *AddrDelta =
MCBinaryExpr::Create(MCBinaryExpr::Sub, ToRef, FromRef, Context);
Streamer.EmitValue(AddrDelta, 4);
}
示例3: EmitAbsDifference
static void EmitAbsDifference(MCStreamer &streamer, MCSymbol *lhs,
MCSymbol *rhs) {
MCContext &context = streamer.getContext();
const MCExpr *diff = MCBinaryExpr::CreateSub(MCSymbolRefExpr::Create(
lhs, context),
MCSymbolRefExpr::Create(
rhs, context),
context);
streamer.EmitAbsValue(diff, 1);
}
示例4: EmitDirectCall
static void EmitDirectCall(const MCOperand &Op, bool Is64Bit,
MCStreamer &Out) {
const bool HideSandboxBase = (FlagHideSandboxBase &&
Is64Bit && !FlagUseZeroBasedSandbox);
if (HideSandboxBase) {
// For NaCl64, the sequence
// call target
// return_addr:
// is changed to
// push return_addr
// jmp target
// .align 32
// return_addr:
// This avoids exposing the sandbox base address via the return
// address on the stack.
MCContext &Context = Out.getContext();
// Generate a label for the return address.
MCSymbol *RetTarget = CreateTempLabel(Context, "DirectCallRetAddr");
const MCExpr *RetTargetExpr = MCSymbolRefExpr::Create(RetTarget, Context);
// push return_addr
MCInst PUSHInst;
PUSHInst.setOpcode(X86::PUSH64i32);
PUSHInst.addOperand(MCOperand::CreateExpr(RetTargetExpr));
Out.EmitInstruction(PUSHInst);
// jmp target
MCInst JMPInst;
JMPInst.setOpcode(X86::JMP_4);
JMPInst.addOperand(Op);
Out.EmitInstruction(JMPInst);
Out.EmitCodeAlignment(kNaClX86InstructionBundleSize);
Out.EmitLabel(RetTarget);
} else {
Out.EmitBundleLock(true);
MCInst CALLInst;
CALLInst.setOpcode(Is64Bit ? X86::CALL64pcrel32 : X86::CALLpcrel32);
CALLInst.addOperand(Op);
Out.EmitInstruction(CALLInst);
Out.EmitBundleUnlock();
}
}
示例5: finalizeDwarfSections
/// finalizeDwarfSections - Emit end symbols for each non-empty code section.
/// Also remove empty sections from SectionStartEndSyms, to avoid generating
/// useless debug info for them.
void MCContext::finalizeDwarfSections(MCStreamer &MCOS) {
MCContext &context = MCOS.getContext();
auto sec = SectionStartEndSyms.begin();
while (sec != SectionStartEndSyms.end()) {
assert(sec->second.first && "Start symbol must be set by now");
MCOS.SwitchSection(sec->first);
if (MCOS.mayHaveInstructions()) {
MCSymbol *SectionEndSym = context.CreateTempSymbol();
MCOS.EmitLabel(SectionEndSym);
sec->second.second = SectionEndSym;
++sec;
} else {
MapVector<const MCSection *, std::pair<MCSymbol *, MCSymbol *> >::iterator
to_erase = sec;
sec = SectionStartEndSyms.erase(to_erase);
}
}
}
示例6: emitLabelOffsetDifference
/// Emit something like ".long Hi+Offset-Lo" where the size in bytes of the
/// directive is specified by Size and Hi/Lo specify the labels.
static void emitLabelOffsetDifference(MCStreamer &Streamer, const MCSymbol *Hi,
uint64_t Offset, const MCSymbol *Lo,
unsigned Size) {
MCContext &Context = Streamer.getContext();
// Emit Hi+Offset - Lo
// Get the Hi+Offset expression.
const MCExpr *Plus =
MCBinaryExpr::CreateAdd(MCSymbolRefExpr::Create(Hi, Context),
MCConstantExpr::Create(Offset, Context), Context);
// Get the Hi+Offset-Lo expression.
const MCExpr *Diff = MCBinaryExpr::CreateSub(
Plus, MCSymbolRefExpr::Create(Lo, Context), Context);
// Otherwise, emit with .set (aka assignment).
MCSymbol *SetLabel = Context.CreateTempSymbol();
Streamer.EmitAssignment(SetLabel, Diff);
Streamer.EmitSymbolValue(SetLabel, Size);
}
示例7:
static void
emitNonLazySymbolPointer(MCStreamer &OutStreamer, MCSymbol *StubLabel,
MachineModuleInfoImpl::StubValueTy &MCSym) {
// L_foo$stub:
OutStreamer.EmitLabel(StubLabel);
// .indirect_symbol _foo
OutStreamer.EmitSymbolAttribute(MCSym.getPointer(), MCSA_IndirectSymbol);
if (MCSym.getInt())
// External to current translation unit.
OutStreamer.EmitIntValue(0, 4/*size*/);
else
// Internal to current translation unit.
//
// When we place the LSDA into the TEXT section, the type info
// pointers need to be indirect and pc-rel. We accomplish this by
// using NLPs; however, sometimes the types are local to the file.
// We need to fill in the value for the NLP in those cases.
OutStreamer.EmitValue(
MCSymbolRefExpr::create(MCSym.getPointer(), OutStreamer.getContext()),
4 /*size*/);
}
示例8:
static void EmitTLSAddr32(const MCInst &Inst, MCStreamer &Out) {
Out.EmitBundleLock(true);
MCInst LeaInst;
LeaInst.setOpcode(X86::LEA32r);
LeaInst.addOperand(MCOperand::CreateReg(X86::EAX)); // DestReg
LeaInst.addOperand(Inst.getOperand(0)); // BaseReg
LeaInst.addOperand(Inst.getOperand(1)); // Scale
LeaInst.addOperand(Inst.getOperand(2)); // IndexReg
LeaInst.addOperand(Inst.getOperand(3)); // Offset
LeaInst.addOperand(Inst.getOperand(4)); // SegmentReg
Out.EmitInstruction(LeaInst);
MCInst CALLInst;
CALLInst.setOpcode(X86::CALLpcrel32);
MCContext &context = Out.getContext();
const MCSymbolRefExpr *expr =
MCSymbolRefExpr::Create(
context.GetOrCreateSymbol(StringRef("___tls_get_addr")),
MCSymbolRefExpr::VK_PLT, context);
CALLInst.addOperand(MCOperand::CreateExpr(expr));
Out.EmitInstruction(CALLInst);
Out.EmitBundleUnlock();
}
示例9: LowerTlsAddr
static void LowerTlsAddr(MCStreamer &OutStreamer,
X86MCInstLower &MCInstLowering,
const MachineInstr &MI,
const MCSubtargetInfo& STI) {
bool is64Bits = MI.getOpcode() == X86::TLS_addr64 ||
MI.getOpcode() == X86::TLS_base_addr64;
bool needsPadding = MI.getOpcode() == X86::TLS_addr64;
MCContext &context = OutStreamer.getContext();
if (needsPadding)
OutStreamer.EmitInstruction(MCInstBuilder(X86::DATA16_PREFIX), STI);
MCSymbolRefExpr::VariantKind SRVK;
switch (MI.getOpcode()) {
case X86::TLS_addr32:
case X86::TLS_addr64:
SRVK = MCSymbolRefExpr::VK_TLSGD;
break;
case X86::TLS_base_addr32:
SRVK = MCSymbolRefExpr::VK_TLSLDM;
break;
case X86::TLS_base_addr64:
SRVK = MCSymbolRefExpr::VK_TLSLD;
break;
default:
llvm_unreachable("unexpected opcode");
}
MCSymbol *sym = MCInstLowering.GetSymbolFromOperand(MI.getOperand(3));
const MCSymbolRefExpr *symRef = MCSymbolRefExpr::Create(sym, SRVK, context);
MCInst LEA;
if (is64Bits) {
LEA.setOpcode(X86::LEA64r);
LEA.addOperand(MCOperand::CreateReg(X86::RDI)); // dest
LEA.addOperand(MCOperand::CreateReg(X86::RIP)); // base
LEA.addOperand(MCOperand::CreateImm(1)); // scale
LEA.addOperand(MCOperand::CreateReg(0)); // index
LEA.addOperand(MCOperand::CreateExpr(symRef)); // disp
LEA.addOperand(MCOperand::CreateReg(0)); // seg
} else if (SRVK == MCSymbolRefExpr::VK_TLSLDM) {
LEA.setOpcode(X86::LEA32r);
LEA.addOperand(MCOperand::CreateReg(X86::EAX)); // dest
LEA.addOperand(MCOperand::CreateReg(X86::EBX)); // base
LEA.addOperand(MCOperand::CreateImm(1)); // scale
LEA.addOperand(MCOperand::CreateReg(0)); // index
LEA.addOperand(MCOperand::CreateExpr(symRef)); // disp
LEA.addOperand(MCOperand::CreateReg(0)); // seg
} else {
LEA.setOpcode(X86::LEA32r);
LEA.addOperand(MCOperand::CreateReg(X86::EAX)); // dest
LEA.addOperand(MCOperand::CreateReg(0)); // base
LEA.addOperand(MCOperand::CreateImm(1)); // scale
LEA.addOperand(MCOperand::CreateReg(X86::EBX)); // index
LEA.addOperand(MCOperand::CreateExpr(symRef)); // disp
LEA.addOperand(MCOperand::CreateReg(0)); // seg
}
OutStreamer.EmitInstruction(LEA, STI);
if (needsPadding) {
OutStreamer.EmitInstruction(MCInstBuilder(X86::DATA16_PREFIX), STI);
OutStreamer.EmitInstruction(MCInstBuilder(X86::DATA16_PREFIX), STI);
OutStreamer.EmitInstruction(MCInstBuilder(X86::REX64_PREFIX), STI);
}
StringRef name = is64Bits ? "__tls_get_addr" : "___tls_get_addr";
MCSymbol *tlsGetAddr = context.GetOrCreateSymbol(name);
const MCSymbolRefExpr *tlsRef =
MCSymbolRefExpr::Create(tlsGetAddr,
MCSymbolRefExpr::VK_PLT,
context);
OutStreamer.EmitInstruction(MCInstBuilder(is64Bits ? X86::CALL64pcrel32
: X86::CALLpcrel32)
.addExpr(tlsRef), STI);
}
示例10: errorToErrorCode
static std::error_code write(MCStreamer &Out, ArrayRef<std::string> Inputs) {
const auto &MCOFI = *Out.getContext().getObjectFileInfo();
MCSection *const StrSection = MCOFI.getDwarfStrDWOSection();
MCSection *const StrOffsetSection = MCOFI.getDwarfStrOffDWOSection();
MCSection *const TypesSection = MCOFI.getDwarfTypesDWOSection();
MCSection *const CUIndexSection = MCOFI.getDwarfCUIndexSection();
MCSection *const TUIndexSection = MCOFI.getDwarfTUIndexSection();
const StringMap<std::pair<MCSection *, DWARFSectionKind>> KnownSections = {
{"debug_info.dwo", {MCOFI.getDwarfInfoDWOSection(), DW_SECT_INFO}},
{"debug_types.dwo", {MCOFI.getDwarfTypesDWOSection(), DW_SECT_TYPES}},
{"debug_str_offsets.dwo", {StrOffsetSection, DW_SECT_STR_OFFSETS}},
{"debug_str.dwo", {StrSection, static_cast<DWARFSectionKind>(0)}},
{"debug_loc.dwo", {MCOFI.getDwarfLocDWOSection(), DW_SECT_LOC}},
{"debug_line.dwo", {MCOFI.getDwarfLineDWOSection(), DW_SECT_LINE}},
{"debug_abbrev.dwo", {MCOFI.getDwarfAbbrevDWOSection(), DW_SECT_ABBREV}},
{"debug_cu_index", {CUIndexSection, static_cast<DWARFSectionKind>(0)}},
{"debug_tu_index", {TUIndexSection, static_cast<DWARFSectionKind>(0)}}};
MapVector<uint64_t, UnitIndexEntry> IndexEntries;
MapVector<uint64_t, UnitIndexEntry> TypeIndexEntries;
StringMap<uint32_t> Strings;
uint32_t StringOffset = 0;
uint32_t ContributionOffsets[8] = {};
for (const auto &Input : Inputs) {
auto ErrOrObj = object::ObjectFile::createObjectFile(Input);
if (!ErrOrObj)
return errorToErrorCode(ErrOrObj.takeError());
UnitIndexEntry CurEntry = {};
StringRef CurStrSection;
StringRef CurStrOffsetSection;
std::vector<StringRef> CurTypesSection;
StringRef InfoSection;
StringRef AbbrevSection;
StringRef CurCUIndexSection;
StringRef CurTUIndexSection;
SmallVector<SmallString<32>, 4> UncompressedSections;
for (const auto &Section : ErrOrObj->getBinary()->sections()) {
if (Section.isBSS())
continue;
if (Section.isVirtual())
continue;
StringRef Name;
if (std::error_code Err = Section.getName(Name))
return Err;
Name = Name.substr(Name.find_first_not_of("._"));
StringRef Contents;
if (auto Err = Section.getContents(Contents))
return Err;
if (Name.startswith("zdebug_")) {
uint64_t OriginalSize;
if (!zlib::isAvailable() ||
!consumeCompressedDebugSectionHeader(Contents, OriginalSize))
return make_error_code(std::errc::invalid_argument);
UncompressedSections.resize(UncompressedSections.size() + 1);
if (zlib::uncompress(Contents, UncompressedSections.back(), OriginalSize) !=
zlib::StatusOK) {
UncompressedSections.pop_back();
continue;
}
Name = Name.substr(1);
Contents = UncompressedSections.back();
}
auto SectionPair = KnownSections.find(Name);
if (SectionPair == KnownSections.end())
continue;
if (DWARFSectionKind Kind = SectionPair->second.second) {
auto Index = Kind - DW_SECT_INFO;
if (Kind != DW_SECT_TYPES) {
CurEntry.Contributions[Index].Offset = ContributionOffsets[Index];
ContributionOffsets[Index] +=
(CurEntry.Contributions[Index].Length = Contents.size());
}
switch (Kind) {
case DW_SECT_INFO:
InfoSection = Contents;
break;
case DW_SECT_ABBREV:
AbbrevSection = Contents;
break;
default:
break;
}
}
MCSection *OutSection = SectionPair->second.first;
if (OutSection == StrOffsetSection)
//.........这里部分代码省略.........
示例11: EmitIndirectBranch
static void EmitIndirectBranch(const MCOperand &Op, bool Is64Bit, bool IsCall,
MCStreamer &Out) {
const bool HideSandboxBase = (FlagHideSandboxBase &&
Is64Bit && !FlagUseZeroBasedSandbox);
const int JmpMask = FlagSfiX86JmpMask;
unsigned Reg32 = Op.getReg();
// For NaCl64, the sequence
// jmp *%rXX
// is changed to
// mov %rXX,%r11d
// and $0xffffffe0,%r11d
// add %r15,%r11
// jmpq *%r11
//
// And the sequence
// call *%rXX
// return_addr:
// is changed to
// mov %rXX,%r11d
// push return_addr
// and $0xffffffe0,%r11d
// add %r15,%r11
// jmpq *%r11
// .align 32
// return_addr:
//
// This avoids exposing the sandbox base address via the return
// address on the stack.
// For NaCl64, force an assignment of the branch target into r11,
// and subsequently use r11 as the ultimate branch target, so that
// only r11 (which will never be written to memory) exposes the
// sandbox base address. But avoid a redundant assignment if the
// original branch target is already r11 or r11d.
const unsigned SafeReg32 = X86::R11D;
const unsigned SafeReg64 = X86::R11;
if (HideSandboxBase) {
// In some cases, EmitIndirectBranch() is called with a 32-bit
// register Op (e.g. r11d), and in other cases a 64-bit register
// (e.g. r11), so we need to test both variants to avoid a
// redundant assignment. TODO(stichnot): Make callers consistent
// on 32 vs 64 bit register.
if ((Reg32 != SafeReg32) && (Reg32 != SafeReg64)) {
MCInst MOVInst;
MOVInst.setOpcode(X86::MOV32rr);
MOVInst.addOperand(MCOperand::CreateReg(SafeReg32));
MOVInst.addOperand(MCOperand::CreateReg(Reg32));
Out.EmitInstruction(MOVInst);
Reg32 = SafeReg32;
}
}
const unsigned Reg64 = getX86SubSuperRegister_(Reg32, MVT::i64);
// Explicitly push the (32-bit) return address for a NaCl64 call
// instruction.
MCSymbol *RetTarget = NULL;
if (IsCall && HideSandboxBase) {
MCContext &Context = Out.getContext();
// Generate a label for the return address.
RetTarget = CreateTempLabel(Context, "IndirectCallRetAddr");
const MCExpr *RetTargetExpr = MCSymbolRefExpr::Create(RetTarget, Context);
// push return_addr
MCInst PUSHInst;
PUSHInst.setOpcode(X86::PUSH64i32);
PUSHInst.addOperand(MCOperand::CreateExpr(RetTargetExpr));
Out.EmitInstruction(PUSHInst);
}
const bool WillEmitCallInst = IsCall && !HideSandboxBase;
Out.EmitBundleLock(WillEmitCallInst);
MCInst ANDInst;
ANDInst.setOpcode(X86::AND32ri8);
ANDInst.addOperand(MCOperand::CreateReg(Reg32));
ANDInst.addOperand(MCOperand::CreateReg(Reg32));
ANDInst.addOperand(MCOperand::CreateImm(JmpMask));
Out.EmitInstruction(ANDInst);
if (Is64Bit && !FlagUseZeroBasedSandbox) {
MCInst InstADD;
InstADD.setOpcode(X86::ADD64rr);
InstADD.addOperand(MCOperand::CreateReg(Reg64));
InstADD.addOperand(MCOperand::CreateReg(Reg64));
InstADD.addOperand(MCOperand::CreateReg(X86::R15));
Out.EmitInstruction(InstADD);
}
if (WillEmitCallInst) {
// callq *%rXX
MCInst CALLInst;
CALLInst.setOpcode(Is64Bit ? X86::CALL64r : X86::CALL32r);
CALLInst.addOperand(MCOperand::CreateReg(Is64Bit ? Reg64 : Reg32));
Out.EmitInstruction(CALLInst);
} else {
// jmpq *%rXX -or- jmpq *%r11
MCInst JMPInst;
JMPInst.setOpcode(Is64Bit ? X86::JMP64r : X86::JMP32r);
//.........这里部分代码省略.........
示例12: if
static std::error_code write(MCStreamer &Out, ArrayRef<std::string> Inputs) {
const auto &MCOFI = *Out.getContext().getObjectFileInfo();
MCSection *const StrSection = MCOFI.getDwarfStrDWOSection();
MCSection *const StrOffsetSection = MCOFI.getDwarfStrOffDWOSection();
const StringMap<std::pair<MCSection *, DWARFSectionKind>> KnownSections = {
{"debug_info.dwo", {MCOFI.getDwarfInfoDWOSection(), DW_SECT_INFO}},
{"debug_types.dwo", {MCOFI.getDwarfTypesDWOSection(), DW_SECT_TYPES}},
{"debug_str_offsets.dwo", {StrOffsetSection, DW_SECT_STR_OFFSETS}},
{"debug_str.dwo", {StrSection, static_cast<DWARFSectionKind>(0)}},
{"debug_loc.dwo", {MCOFI.getDwarfLocDWOSection(), DW_SECT_LOC}},
{"debug_abbrev.dwo", {MCOFI.getDwarfAbbrevDWOSection(), DW_SECT_ABBREV}}};
struct UnitIndexEntry {
uint64_t Signature;
DWARFUnitIndex::Entry::SectionContribution Contributions[8];
};
std::vector<UnitIndexEntry> IndexEntries;
StringMap<uint32_t> Strings;
uint32_t StringOffset = 0;
uint64_t UnitIndex = 0;
uint32_t ContributionOffsets[8] = {};
for (const auto &Input : Inputs) {
auto ErrOrObj = object::ObjectFile::createObjectFile(Input);
if (!ErrOrObj)
return ErrOrObj.getError();
IndexEntries.emplace_back();
UnitIndexEntry &CurEntry = IndexEntries.back();
CurEntry.Signature = UnitIndex++;
StringRef CurStrSection;
StringRef CurStrOffsetSection;
for (const auto &Section : ErrOrObj->getBinary()->sections()) {
StringRef Name;
if (std::error_code Err = Section.getName(Name))
return Err;
auto SectionPair =
KnownSections.find(Name.substr(Name.find_first_not_of("._")));
if (SectionPair == KnownSections.end())
continue;
StringRef Contents;
if (auto Err = Section.getContents(Contents))
return Err;
if (DWARFSectionKind Kind = SectionPair->second.second) {
auto Index = Kind - DW_SECT_INFO;
CurEntry.Contributions[Index].Offset = ContributionOffsets[Index];
ContributionOffsets[Index] +=
(CurEntry.Contributions[Index].Length = Contents.size());
}
MCSection *OutSection = SectionPair->second.first;
if (OutSection == StrOffsetSection)
CurStrOffsetSection = Contents;
else if (OutSection == StrSection)
CurStrSection = Contents;
else {
Out.SwitchSection(OutSection);
Out.EmitBytes(Contents);
}
}
if (auto Err = writeStringsAndOffsets(Out, Strings, StringOffset,
StrSection, StrOffsetSection,
CurStrSection, CurStrOffsetSection))
return Err;
}
Out.SwitchSection(MCOFI.getDwarfCUIndexSection());
Out.EmitIntValue(2, 4); // Version
Out.EmitIntValue(8, 4); // Columns
Out.EmitIntValue(IndexEntries.size(), 4); // Num Units
// FIXME: This is not the right number of buckets for a real hash.
Out.EmitIntValue(IndexEntries.size(), 4); // Num Buckets
// Write the signatures.
for (const auto &E : IndexEntries)
Out.EmitIntValue(E.Signature, 8);
// Write the indexes.
for (size_t i = 0; i != IndexEntries.size(); ++i)
Out.EmitIntValue(i + 1, 4);
// Write the column headers (which sections will appear in the table)
for (size_t i = 1; i != 9; ++i)
Out.EmitIntValue(i, 4);
// Write the offsets.
for (const auto &E : IndexEntries)
for (const auto &C : E.Contributions)
Out.EmitIntValue(C.Offset, 4);
// Write the lengths.
//.........这里部分代码省略.........
示例13: MAI
Z80TargetAsmStreamer::Z80TargetAsmStreamer(MCStreamer &S,
formatted_raw_ostream &OS)
: Z80TargetStreamer(S), MAI(S.getContext().getAsmInfo()), OS(OS) {}
示例14: if
static std::error_code write(MCStreamer &Out, ArrayRef<std::string> Inputs) {
const auto &MCOFI = *Out.getContext().getObjectFileInfo();
MCSection *const StrSection = MCOFI.getDwarfStrDWOSection();
MCSection *const StrOffsetSection = MCOFI.getDwarfStrOffDWOSection();
MCSection *const TypesSection = MCOFI.getDwarfTypesDWOSection();
MCSection *const CUIndexSection = MCOFI.getDwarfCUIndexSection();
const StringMap<std::pair<MCSection *, DWARFSectionKind>> KnownSections = {
{"debug_info.dwo", {MCOFI.getDwarfInfoDWOSection(), DW_SECT_INFO}},
{"debug_types.dwo", {MCOFI.getDwarfTypesDWOSection(), DW_SECT_TYPES}},
{"debug_str_offsets.dwo", {StrOffsetSection, DW_SECT_STR_OFFSETS}},
{"debug_str.dwo", {StrSection, static_cast<DWARFSectionKind>(0)}},
{"debug_loc.dwo", {MCOFI.getDwarfLocDWOSection(), DW_SECT_LOC}},
{"debug_line.dwo", {MCOFI.getDwarfLineDWOSection(), DW_SECT_LINE}},
{"debug_abbrev.dwo", {MCOFI.getDwarfAbbrevDWOSection(), DW_SECT_ABBREV}},
{"debug_cu_index",
{MCOFI.getDwarfCUIndexSection(), static_cast<DWARFSectionKind>(0)}}};
std::vector<UnitIndexEntry> IndexEntries;
std::vector<UnitIndexEntry> TypeIndexEntries;
StringMap<uint32_t> Strings;
uint32_t StringOffset = 0;
uint32_t ContributionOffsets[8] = {};
for (const auto &Input : Inputs) {
auto ErrOrObj = object::ObjectFile::createObjectFile(Input);
if (!ErrOrObj)
return ErrOrObj.getError();
UnitIndexEntry CurEntry = {};
StringRef CurStrSection;
StringRef CurStrOffsetSection;
StringRef CurTypesSection;
StringRef InfoSection;
StringRef AbbrevSection;
StringRef CurCUIndexSection;
for (const auto &Section : ErrOrObj->getBinary()->sections()) {
StringRef Name;
if (std::error_code Err = Section.getName(Name))
return Err;
auto SectionPair =
KnownSections.find(Name.substr(Name.find_first_not_of("._")));
if (SectionPair == KnownSections.end())
continue;
StringRef Contents;
if (auto Err = Section.getContents(Contents))
return Err;
if (DWARFSectionKind Kind = SectionPair->second.second) {
auto Index = Kind - DW_SECT_INFO;
if (Kind != DW_SECT_TYPES) {
CurEntry.Contributions[Index].Offset = ContributionOffsets[Index];
ContributionOffsets[Index] +=
(CurEntry.Contributions[Index].Length = Contents.size());
}
switch (Kind) {
case DW_SECT_INFO:
InfoSection = Contents;
break;
case DW_SECT_ABBREV:
AbbrevSection = Contents;
break;
default:
break;
}
}
MCSection *OutSection = SectionPair->second.first;
if (OutSection == StrOffsetSection)
CurStrOffsetSection = Contents;
else if (OutSection == StrSection)
CurStrSection = Contents;
else if (OutSection == TypesSection)
CurTypesSection = Contents;
else if (OutSection == CUIndexSection)
CurCUIndexSection = Contents;
else {
Out.SwitchSection(OutSection);
Out.EmitBytes(Contents);
}
}
assert(!AbbrevSection.empty());
assert(!InfoSection.empty());
if (!CurCUIndexSection.empty()) {
DWARFUnitIndex CUIndex(DW_SECT_INFO);
DataExtractor CUIndexData(CurCUIndexSection,
ErrOrObj->getBinary()->isLittleEndian(), 0);
if (!CUIndex.parse(CUIndexData))
return make_error_code(std::errc::invalid_argument);
for (const DWARFUnitIndex::Entry &E : CUIndex.getRows()) {
auto NewEntry = CurEntry;
auto *I = E.getOffsets();
//.........这里部分代码省略.........