2010-07-29 04:55:35 +08:00
|
|
|
//===- lib/MC/MCDwarf.cpp - MCDwarf implementation ------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/MC/MCDwarf.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/ADT/Hashing.h"
|
2014-04-13 00:15:53 +08:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
|
|
|
#include "llvm/ADT/Twine.h"
|
|
|
|
#include "llvm/Config/config.h"
|
2011-07-20 13:58:47 +08:00
|
|
|
#include "llvm/MC/MCAsmInfo.h"
|
|
|
|
#include "llvm/MC/MCContext.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/MC/MCExpr.h"
|
2011-07-20 13:58:47 +08:00
|
|
|
#include "llvm/MC/MCObjectFileInfo.h"
|
2014-05-12 22:28:48 +08:00
|
|
|
#include "llvm/MC/MCObjectStreamer.h"
|
2011-07-20 13:58:47 +08:00
|
|
|
#include "llvm/MC/MCRegisterInfo.h"
|
2014-06-19 23:52:37 +08:00
|
|
|
#include "llvm/MC/MCSection.h"
|
2010-10-01 00:52:03 +08:00
|
|
|
#include "llvm/MC/MCSymbol.h"
|
2010-07-29 04:55:35 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
2010-12-29 02:36:23 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2012-08-09 07:56:06 +08:00
|
|
|
#include "llvm/Support/LEB128.h"
|
2011-12-10 02:09:40 +08:00
|
|
|
#include "llvm/Support/Path.h"
|
|
|
|
#include "llvm/Support/SourceMgr.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2015-10-07 07:24:35 +08:00
|
|
|
|
2010-07-29 04:55:35 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
2013-06-12 22:46:54 +08:00
|
|
|
static inline uint64_t ScaleAddrDelta(MCContext &Context, uint64_t AddrDelta) {
|
2013-06-18 15:20:20 +08:00
|
|
|
unsigned MinInsnLength = Context.getAsmInfo()->getMinInstAlignment();
|
2013-06-12 22:46:54 +08:00
|
|
|
if (MinInsnLength == 1)
|
2010-10-01 00:52:03 +08:00
|
|
|
return AddrDelta;
|
2013-06-12 22:46:54 +08:00
|
|
|
if (AddrDelta % MinInsnLength != 0) {
|
2010-10-01 00:52:03 +08:00
|
|
|
// TODO: report this error, but really only once.
|
|
|
|
;
|
|
|
|
}
|
2013-06-12 22:46:54 +08:00
|
|
|
return AddrDelta / MinInsnLength;
|
2010-10-01 00:52:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// This is called when an instruction is assembled into the specified section
|
|
|
|
// and if there is information from the last .loc directive that has yet to have
|
|
|
|
// a line entry made for it is made.
|
|
|
|
//
|
2016-01-21 09:59:03 +08:00
|
|
|
void MCDwarfLineEntry::Make(MCObjectStreamer *MCOS, MCSection *Section) {
|
2010-10-01 00:52:03 +08:00
|
|
|
if (!MCOS->getContext().getDwarfLocSeen())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Create a symbol at in the current section for use in the line entry.
|
2015-05-19 02:43:14 +08:00
|
|
|
MCSymbol *LineSym = MCOS->getContext().createTempSymbol();
|
2016-01-21 09:59:03 +08:00
|
|
|
// Set the value of the symbol to use for the MCDwarfLineEntry.
|
2010-10-01 00:52:03 +08:00
|
|
|
MCOS->EmitLabel(LineSym);
|
|
|
|
|
|
|
|
// Get the current .loc info saved in the context.
|
|
|
|
const MCDwarfLoc &DwarfLoc = MCOS->getContext().getCurrentDwarfLoc();
|
|
|
|
|
|
|
|
// Create a (local) line entry with the symbol and the current .loc info.
|
2016-01-21 09:59:03 +08:00
|
|
|
MCDwarfLineEntry LineEntry(LineSym, DwarfLoc);
|
2010-10-01 00:52:03 +08:00
|
|
|
|
|
|
|
// clear DwarfLocSeen saying the current .loc info is now used.
|
2015-05-19 02:43:14 +08:00
|
|
|
MCOS->getContext().clearDwarfLocSeen();
|
2010-10-01 00:52:03 +08:00
|
|
|
|
|
|
|
// Add the line entry to this section's entries.
|
2014-03-13 06:28:56 +08:00
|
|
|
MCOS->getContext()
|
2014-03-14 05:59:51 +08:00
|
|
|
.getMCDwarfLineTable(MCOS->getContext().getDwarfCompileUnitID())
|
2014-03-14 01:55:28 +08:00
|
|
|
.getMCLineSections()
|
2014-03-13 06:28:56 +08:00
|
|
|
.addLineEntry(LineEntry, Section);
|
2010-10-01 00:52:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// This helper routine returns an expression of End - Start + IntVal .
|
2012-05-11 09:41:30 +08:00
|
|
|
//
|
2010-12-10 07:08:35 +08:00
|
|
|
static inline const MCExpr *MakeStartMinusEndExpr(const MCStreamer &MCOS,
|
|
|
|
const MCSymbol &Start,
|
|
|
|
const MCSymbol &End,
|
|
|
|
int IntVal) {
|
2010-10-01 00:52:03 +08:00
|
|
|
MCSymbolRefExpr::VariantKind Variant = MCSymbolRefExpr::VK_None;
|
|
|
|
const MCExpr *Res =
|
2015-05-30 09:25:56 +08:00
|
|
|
MCSymbolRefExpr::create(&End, Variant, MCOS.getContext());
|
2010-10-01 00:52:03 +08:00
|
|
|
const MCExpr *RHS =
|
2015-05-30 09:25:56 +08:00
|
|
|
MCSymbolRefExpr::create(&Start, Variant, MCOS.getContext());
|
2010-10-01 00:52:03 +08:00
|
|
|
const MCExpr *Res1 =
|
2015-05-30 09:25:56 +08:00
|
|
|
MCBinaryExpr::create(MCBinaryExpr::Sub, Res, RHS, MCOS.getContext());
|
2010-10-01 00:52:03 +08:00
|
|
|
const MCExpr *Res2 =
|
2015-05-30 09:25:56 +08:00
|
|
|
MCConstantExpr::create(IntVal, MCOS.getContext());
|
2010-10-01 00:52:03 +08:00
|
|
|
const MCExpr *Res3 =
|
2015-05-30 09:25:56 +08:00
|
|
|
MCBinaryExpr::create(MCBinaryExpr::Sub, Res1, Res2, MCOS.getContext());
|
2010-10-01 00:52:03 +08:00
|
|
|
return Res3;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// This emits the Dwarf line table for the specified section from the entries
|
|
|
|
// in the LineSection.
|
|
|
|
//
|
2014-03-13 06:35:23 +08:00
|
|
|
static inline void
|
2015-05-22 03:20:38 +08:00
|
|
|
EmitDwarfLineTable(MCObjectStreamer *MCOS, MCSection *Section,
|
2016-01-21 09:59:03 +08:00
|
|
|
const MCLineSection::MCDwarfLineEntryCollection &LineEntries) {
|
2010-10-01 00:52:03 +08:00
|
|
|
unsigned FileNum = 1;
|
|
|
|
unsigned LastLine = 1;
|
|
|
|
unsigned Column = 0;
|
|
|
|
unsigned Flags = DWARF2_LINE_DEFAULT_IS_STMT ? DWARF2_FLAG_IS_STMT : 0;
|
|
|
|
unsigned Isa = 0;
|
2014-02-15 03:27:53 +08:00
|
|
|
unsigned Discriminator = 0;
|
2014-04-13 12:57:38 +08:00
|
|
|
MCSymbol *LastLabel = nullptr;
|
2010-10-01 00:52:03 +08:00
|
|
|
|
2016-01-21 09:59:03 +08:00
|
|
|
// Loop through each MCDwarfLineEntry and encode the dwarf line number table.
|
2014-03-13 06:28:56 +08:00
|
|
|
for (auto it = LineEntries.begin(),
|
|
|
|
ie = LineEntries.end();
|
|
|
|
it != ie; ++it) {
|
2010-10-01 00:52:03 +08:00
|
|
|
|
2016-04-23 05:31:18 +08:00
|
|
|
int64_t LineDelta = static_cast<int64_t>(it->getLine()) - LastLine;
|
|
|
|
|
2010-10-01 00:52:03 +08:00
|
|
|
if (FileNum != it->getFileNum()) {
|
|
|
|
FileNum = it->getFileNum();
|
|
|
|
MCOS->EmitIntValue(dwarf::DW_LNS_set_file, 1);
|
2010-11-03 01:22:24 +08:00
|
|
|
MCOS->EmitULEB128IntValue(FileNum);
|
2010-10-01 00:52:03 +08:00
|
|
|
}
|
|
|
|
if (Column != it->getColumn()) {
|
|
|
|
Column = it->getColumn();
|
|
|
|
MCOS->EmitIntValue(dwarf::DW_LNS_set_column, 1);
|
2010-11-03 01:22:24 +08:00
|
|
|
MCOS->EmitULEB128IntValue(Column);
|
2010-10-01 00:52:03 +08:00
|
|
|
}
|
2014-02-15 03:27:53 +08:00
|
|
|
if (Discriminator != it->getDiscriminator()) {
|
|
|
|
Discriminator = it->getDiscriminator();
|
2014-02-22 22:00:39 +08:00
|
|
|
unsigned Size = getULEB128Size(Discriminator);
|
2014-02-15 03:27:53 +08:00
|
|
|
MCOS->EmitIntValue(dwarf::DW_LNS_extended_op, 1);
|
|
|
|
MCOS->EmitULEB128IntValue(Size + 1);
|
|
|
|
MCOS->EmitIntValue(dwarf::DW_LNE_set_discriminator, 1);
|
|
|
|
MCOS->EmitULEB128IntValue(Discriminator);
|
|
|
|
}
|
2010-10-01 00:52:03 +08:00
|
|
|
if (Isa != it->getIsa()) {
|
|
|
|
Isa = it->getIsa();
|
|
|
|
MCOS->EmitIntValue(dwarf::DW_LNS_set_isa, 1);
|
2010-11-03 01:22:24 +08:00
|
|
|
MCOS->EmitULEB128IntValue(Isa);
|
2010-10-01 00:52:03 +08:00
|
|
|
}
|
|
|
|
if ((it->getFlags() ^ Flags) & DWARF2_FLAG_IS_STMT) {
|
|
|
|
Flags = it->getFlags();
|
|
|
|
MCOS->EmitIntValue(dwarf::DW_LNS_negate_stmt, 1);
|
|
|
|
}
|
|
|
|
if (it->getFlags() & DWARF2_FLAG_BASIC_BLOCK)
|
|
|
|
MCOS->EmitIntValue(dwarf::DW_LNS_set_basic_block, 1);
|
|
|
|
if (it->getFlags() & DWARF2_FLAG_PROLOGUE_END)
|
|
|
|
MCOS->EmitIntValue(dwarf::DW_LNS_set_prologue_end, 1);
|
|
|
|
if (it->getFlags() & DWARF2_FLAG_EPILOGUE_BEGIN)
|
|
|
|
MCOS->EmitIntValue(dwarf::DW_LNS_set_epilogue_begin, 1);
|
|
|
|
|
|
|
|
MCSymbol *Label = it->getLabel();
|
|
|
|
|
|
|
|
// At this point we want to emit/create the sequence to encode the delta in
|
|
|
|
// line numbers and the increment of the address from the previous Label
|
|
|
|
// and the current Label.
|
2013-06-18 15:20:20 +08:00
|
|
|
const MCAsmInfo *asmInfo = MCOS->getContext().getAsmInfo();
|
2011-07-14 13:43:07 +08:00
|
|
|
MCOS->EmitDwarfAdvanceLineAddr(LineDelta, LastLabel, Label,
|
2013-06-18 15:20:20 +08:00
|
|
|
asmInfo->getPointerSize());
|
2010-10-01 00:52:03 +08:00
|
|
|
|
2016-04-29 06:09:37 +08:00
|
|
|
Discriminator = 0;
|
2010-10-01 00:52:03 +08:00
|
|
|
LastLine = it->getLine();
|
|
|
|
LastLabel = Label;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Emit a DW_LNE_end_sequence for the end of the section.
|
2015-03-24 05:22:04 +08:00
|
|
|
// Use the section end label to compute the address delta and use INT64_MAX
|
|
|
|
// as the line delta which is the signal that this is actually a
|
|
|
|
// DW_LNE_end_sequence.
|
|
|
|
MCSymbol *SectionEnd = MCOS->endSection(Section);
|
2010-12-10 15:39:47 +08:00
|
|
|
|
2015-03-24 05:22:04 +08:00
|
|
|
// Switch back the dwarf line section, in case endSection had to switch the
|
|
|
|
// section.
|
2015-03-24 04:25:31 +08:00
|
|
|
MCContext &Ctx = MCOS->getContext();
|
|
|
|
MCOS->SwitchSection(Ctx.getObjectFileInfo()->getDwarfLineSection());
|
2010-11-19 10:26:16 +08:00
|
|
|
|
2015-03-24 04:25:31 +08:00
|
|
|
const MCAsmInfo *AsmInfo = Ctx.getAsmInfo();
|
2011-07-14 13:43:07 +08:00
|
|
|
MCOS->EmitDwarfAdvanceLineAddr(INT64_MAX, LastLabel, SectionEnd,
|
2015-03-24 04:25:31 +08:00
|
|
|
AsmInfo->getPointerSize());
|
2010-10-01 00:52:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// This emits the Dwarf file and the line tables.
|
|
|
|
//
|
2015-08-07 23:14:08 +08:00
|
|
|
void MCDwarfLineTable::Emit(MCObjectStreamer *MCOS,
|
|
|
|
MCDwarfLineTableParams Params) {
|
2010-12-10 15:39:47 +08:00
|
|
|
MCContext &context = MCOS->getContext();
|
2010-10-01 00:52:03 +08:00
|
|
|
|
2014-04-01 15:35:52 +08:00
|
|
|
auto &LineTables = context.getMCDwarfLineTables();
|
|
|
|
|
|
|
|
// Bail out early so we don't switch to the debug_line section needlessly and
|
|
|
|
// in doing so create an unnecessary (if empty) section.
|
|
|
|
if (LineTables.empty())
|
|
|
|
return;
|
2014-03-14 01:55:28 +08:00
|
|
|
|
|
|
|
// Switch to the section where the table will be emitted into.
|
|
|
|
MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfLineSection());
|
|
|
|
|
2013-02-06 05:52:47 +08:00
|
|
|
// Handle the rest of the Compile Units.
|
2014-04-01 15:35:52 +08:00
|
|
|
for (const auto &CUIDTablePair : LineTables)
|
2015-08-07 23:14:08 +08:00
|
|
|
CUIDTablePair.second.EmitCU(MCOS, Params);
|
2013-02-06 05:52:47 +08:00
|
|
|
}
|
|
|
|
|
2015-08-07 23:14:08 +08:00
|
|
|
void MCDwarfDwoLineTable::Emit(MCStreamer &MCOS,
|
|
|
|
MCDwarfLineTableParams Params) const {
|
|
|
|
MCOS.EmitLabel(Header.Emit(&MCOS, Params, None).second);
|
2014-03-18 10:13:23 +08:00
|
|
|
}
|
|
|
|
|
2015-08-07 23:14:08 +08:00
|
|
|
std::pair<MCSymbol *, MCSymbol *>
|
|
|
|
MCDwarfLineTableHeader::Emit(MCStreamer *MCOS,
|
|
|
|
MCDwarfLineTableParams Params) const {
|
2014-03-18 10:13:23 +08:00
|
|
|
static const char StandardOpcodeLengths[] = {
|
|
|
|
0, // length of DW_LNS_copy
|
|
|
|
1, // length of DW_LNS_advance_pc
|
|
|
|
1, // length of DW_LNS_advance_line
|
|
|
|
1, // length of DW_LNS_set_file
|
|
|
|
1, // length of DW_LNS_set_column
|
|
|
|
0, // length of DW_LNS_negate_stmt
|
|
|
|
0, // length of DW_LNS_set_basic_block
|
|
|
|
0, // length of DW_LNS_const_add_pc
|
|
|
|
1, // length of DW_LNS_fixed_advance_pc
|
|
|
|
0, // length of DW_LNS_set_prologue_end
|
|
|
|
0, // length of DW_LNS_set_epilogue_begin
|
|
|
|
1 // DW_LNS_set_isa
|
|
|
|
};
|
2015-08-07 23:14:08 +08:00
|
|
|
assert(array_lengthof(StandardOpcodeLengths) >=
|
2015-08-10 23:22:39 +08:00
|
|
|
(Params.DWARF2LineOpcodeBase - 1U));
|
2015-09-21 13:32:41 +08:00
|
|
|
return Emit(MCOS, Params, makeArrayRef(StandardOpcodeLengths,
|
|
|
|
Params.DWARF2LineOpcodeBase - 1));
|
2014-03-18 10:13:23 +08:00
|
|
|
}
|
|
|
|
|
2014-08-15 23:12:13 +08:00
|
|
|
static const MCExpr *forceExpAbs(MCStreamer &OS, const MCExpr* Expr) {
|
|
|
|
MCContext &Context = OS.getContext();
|
|
|
|
assert(!isa<MCSymbolRefExpr>(Expr));
|
|
|
|
if (Context.getAsmInfo()->hasAggressiveSymbolFolding())
|
|
|
|
return Expr;
|
|
|
|
|
2015-05-19 02:43:14 +08:00
|
|
|
MCSymbol *ABS = Context.createTempSymbol();
|
2014-08-15 23:12:13 +08:00
|
|
|
OS.EmitAssignment(ABS, Expr);
|
2015-05-30 09:25:56 +08:00
|
|
|
return MCSymbolRefExpr::create(ABS, Context);
|
2014-08-15 23:12:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void emitAbsValue(MCStreamer &OS, const MCExpr *Value, unsigned Size) {
|
|
|
|
const MCExpr *ABS = forceExpAbs(OS, Value);
|
|
|
|
OS.EmitValue(ABS, Size);
|
|
|
|
}
|
|
|
|
|
2014-03-18 10:13:23 +08:00
|
|
|
std::pair<MCSymbol *, MCSymbol *>
|
2015-08-07 23:14:08 +08:00
|
|
|
MCDwarfLineTableHeader::Emit(MCStreamer *MCOS, MCDwarfLineTableParams Params,
|
2014-03-18 10:13:23 +08:00
|
|
|
ArrayRef<char> StandardOpcodeLengths) const {
|
2013-02-06 05:52:47 +08:00
|
|
|
MCContext &context = MCOS->getContext();
|
|
|
|
|
|
|
|
// Create a symbol at the beginning of the line table.
|
2014-03-14 01:55:28 +08:00
|
|
|
MCSymbol *LineStartSym = Label;
|
2013-02-06 05:52:47 +08:00
|
|
|
if (!LineStartSym)
|
2015-05-19 02:43:14 +08:00
|
|
|
LineStartSym = context.createTempSymbol();
|
2013-02-06 05:52:47 +08:00
|
|
|
// Set the value of the symbol, as we are at the start of the line table.
|
2010-10-01 00:52:03 +08:00
|
|
|
MCOS->EmitLabel(LineStartSym);
|
|
|
|
|
|
|
|
// Create a symbol for the end of the section (to be set when we get there).
|
2015-05-19 02:43:14 +08:00
|
|
|
MCSymbol *LineEndSym = context.createTempSymbol();
|
2010-10-01 00:52:03 +08:00
|
|
|
|
|
|
|
// The first 4 bytes is the total length of the information for this
|
|
|
|
// compilation unit (not including these 4 bytes for the length).
|
2014-08-15 23:12:13 +08:00
|
|
|
emitAbsValue(*MCOS,
|
|
|
|
MakeStartMinusEndExpr(*MCOS, *LineStartSym, *LineEndSym, 4), 4);
|
2010-10-01 00:52:03 +08:00
|
|
|
|
|
|
|
// Next 2 bytes is the Version, which is Dwarf 2.
|
|
|
|
MCOS->EmitIntValue(2, 2);
|
|
|
|
|
|
|
|
// Create a symbol for the end of the prologue (to be set when we get there).
|
2015-05-19 02:43:14 +08:00
|
|
|
MCSymbol *ProEndSym = context.createTempSymbol(); // Lprologue_end
|
2010-10-01 00:52:03 +08:00
|
|
|
|
|
|
|
// Length of the prologue, is the next 4 bytes. Which is the start of the
|
|
|
|
// section to the end of the prologue. Not including the 4 bytes for the
|
|
|
|
// total length, the 2 bytes for the version, and these 4 bytes for the
|
|
|
|
// length of the prologue.
|
2014-08-15 23:12:13 +08:00
|
|
|
emitAbsValue(
|
|
|
|
*MCOS,
|
|
|
|
MakeStartMinusEndExpr(*MCOS, *LineStartSym, *ProEndSym, (4 + 2 + 4)), 4);
|
2010-10-01 00:52:03 +08:00
|
|
|
|
|
|
|
// Parameters of the state machine, are next.
|
2013-06-18 15:20:20 +08:00
|
|
|
MCOS->EmitIntValue(context.getAsmInfo()->getMinInstAlignment(), 1);
|
2010-10-01 00:52:03 +08:00
|
|
|
MCOS->EmitIntValue(DWARF2_LINE_DEFAULT_IS_STMT, 1);
|
2015-08-07 23:14:08 +08:00
|
|
|
MCOS->EmitIntValue(Params.DWARF2LineBase, 1);
|
|
|
|
MCOS->EmitIntValue(Params.DWARF2LineRange, 1);
|
2014-03-18 10:13:23 +08:00
|
|
|
MCOS->EmitIntValue(StandardOpcodeLengths.size() + 1, 1);
|
2010-10-01 00:52:03 +08:00
|
|
|
|
|
|
|
// Standard opcode lengths
|
2014-03-18 10:13:23 +08:00
|
|
|
for (char Length : StandardOpcodeLengths)
|
|
|
|
MCOS->EmitIntValue(Length, 1);
|
2010-10-01 00:52:03 +08:00
|
|
|
|
|
|
|
// Put out the directory and file tables.
|
|
|
|
|
|
|
|
// First the directory table.
|
|
|
|
for (unsigned i = 0; i < MCDwarfDirs.size(); i++) {
|
2013-01-09 09:57:54 +08:00
|
|
|
MCOS->EmitBytes(MCDwarfDirs[i]); // the DirectoryName
|
|
|
|
MCOS->EmitBytes(StringRef("\0", 1)); // the null term. of the string
|
2010-10-01 00:52:03 +08:00
|
|
|
}
|
|
|
|
MCOS->EmitIntValue(0, 1); // Terminate the directory list
|
|
|
|
|
|
|
|
// Second the file table.
|
|
|
|
for (unsigned i = 1; i < MCDwarfFiles.size(); i++) {
|
2014-03-18 02:13:58 +08:00
|
|
|
assert(!MCDwarfFiles[i].Name.empty());
|
2014-03-14 02:55:04 +08:00
|
|
|
MCOS->EmitBytes(MCDwarfFiles[i].Name); // FileName
|
2013-01-09 09:57:54 +08:00
|
|
|
MCOS->EmitBytes(StringRef("\0", 1)); // the null term. of the string
|
2010-11-03 01:22:24 +08:00
|
|
|
// the Directory num
|
2014-03-14 02:55:04 +08:00
|
|
|
MCOS->EmitULEB128IntValue(MCDwarfFiles[i].DirIndex);
|
2010-10-01 00:52:03 +08:00
|
|
|
MCOS->EmitIntValue(0, 1); // last modification timestamp (always 0)
|
|
|
|
MCOS->EmitIntValue(0, 1); // filesize (always 0)
|
|
|
|
}
|
|
|
|
MCOS->EmitIntValue(0, 1); // Terminate the file list
|
|
|
|
|
|
|
|
// This is the end of the prologue, so set the value of the symbol at the
|
|
|
|
// end of the prologue (that was used in a previous expression).
|
|
|
|
MCOS->EmitLabel(ProEndSym);
|
|
|
|
|
2014-03-14 05:47:12 +08:00
|
|
|
return std::make_pair(LineStartSym, LineEndSym);
|
|
|
|
}
|
|
|
|
|
2015-08-07 23:14:08 +08:00
|
|
|
void MCDwarfLineTable::EmitCU(MCObjectStreamer *MCOS,
|
|
|
|
MCDwarfLineTableParams Params) const {
|
|
|
|
MCSymbol *LineEndSym = Header.Emit(MCOS, Params).second;
|
2014-03-14 05:47:12 +08:00
|
|
|
|
2010-10-01 00:52:03 +08:00
|
|
|
// Put out the line tables.
|
2014-03-14 01:55:28 +08:00
|
|
|
for (const auto &LineSec : MCLineSections.getMCLineEntries())
|
|
|
|
EmitDwarfLineTable(MCOS, LineSec.first, LineSec.second);
|
2010-10-01 00:52:03 +08:00
|
|
|
|
|
|
|
// This is the end of the section, so set the value of the symbol at the end
|
|
|
|
// of this section (that was used in a previous expression).
|
|
|
|
MCOS->EmitLabel(LineEndSym);
|
|
|
|
}
|
|
|
|
|
2014-03-18 02:13:58 +08:00
|
|
|
unsigned MCDwarfLineTable::getFile(StringRef &Directory, StringRef &FileName,
|
2014-03-14 05:59:51 +08:00
|
|
|
unsigned FileNumber) {
|
2014-03-14 05:47:12 +08:00
|
|
|
return Header.getFile(Directory, FileName, FileNumber);
|
|
|
|
}
|
|
|
|
|
2014-03-18 02:13:58 +08:00
|
|
|
unsigned MCDwarfLineTableHeader::getFile(StringRef &Directory,
|
|
|
|
StringRef &FileName,
|
2014-03-17 09:52:11 +08:00
|
|
|
unsigned FileNumber) {
|
2014-03-18 07:29:40 +08:00
|
|
|
if (Directory == CompilationDir)
|
|
|
|
Directory = "";
|
2014-03-18 02:13:58 +08:00
|
|
|
if (FileName.empty()) {
|
|
|
|
FileName = "<stdin>";
|
|
|
|
Directory = "";
|
|
|
|
}
|
|
|
|
assert(!FileName.empty());
|
2014-03-17 09:52:11 +08:00
|
|
|
if (FileNumber == 0) {
|
2016-03-10 01:32:56 +08:00
|
|
|
// File numbers start with 1 and/or after any file numbers
|
|
|
|
// allocated by inline-assembler .file directives.
|
|
|
|
FileNumber = MCDwarfFiles.empty() ? 1 : MCDwarfFiles.size();
|
2015-05-21 03:12:14 +08:00
|
|
|
SmallString<256> Buffer;
|
2014-11-19 13:49:42 +08:00
|
|
|
auto IterBool = SourceIdMap.insert(
|
2015-05-21 03:12:14 +08:00
|
|
|
std::make_pair((Directory + Twine('\0') + FileName).toStringRef(Buffer),
|
|
|
|
FileNumber));
|
2014-11-19 13:49:42 +08:00
|
|
|
if (!IterBool.second)
|
|
|
|
return IterBool.first->second;
|
2014-03-17 09:52:11 +08:00
|
|
|
}
|
2014-03-14 03:15:04 +08:00
|
|
|
// Make space for this FileNumber in the MCDwarfFiles vector if needed.
|
|
|
|
MCDwarfFiles.resize(FileNumber + 1);
|
|
|
|
|
|
|
|
// Get the new MCDwarfFile slot for this FileNumber.
|
|
|
|
MCDwarfFile &File = MCDwarfFiles[FileNumber];
|
|
|
|
|
|
|
|
// It is an error to use see the same number more than once.
|
|
|
|
if (!File.Name.empty())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (Directory.empty()) {
|
|
|
|
// Separate the directory part from the basename of the FileName.
|
|
|
|
StringRef tFileName = sys::path::filename(FileName);
|
|
|
|
if (!tFileName.empty()) {
|
|
|
|
Directory = sys::path::parent_path(FileName);
|
|
|
|
if (!Directory.empty())
|
|
|
|
FileName = tFileName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find or make an entry in the MCDwarfDirs vector for this Directory.
|
|
|
|
// Capture directory name.
|
|
|
|
unsigned DirIndex;
|
|
|
|
if (Directory.empty()) {
|
|
|
|
// For FileNames with no directories a DirIndex of 0 is used.
|
|
|
|
DirIndex = 0;
|
|
|
|
} else {
|
|
|
|
DirIndex = 0;
|
|
|
|
for (unsigned End = MCDwarfDirs.size(); DirIndex < End; DirIndex++) {
|
|
|
|
if (Directory == MCDwarfDirs[DirIndex])
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (DirIndex >= MCDwarfDirs.size())
|
|
|
|
MCDwarfDirs.push_back(Directory);
|
|
|
|
// The DirIndex is one based, as DirIndex of 0 is used for FileNames with
|
|
|
|
// no directories. MCDwarfDirs[] is unlike MCDwarfFiles[] in that the
|
|
|
|
// directory names are stored at MCDwarfDirs[DirIndex-1] where FileNames
|
|
|
|
// are stored at MCDwarfFiles[FileNumber].Name .
|
|
|
|
DirIndex++;
|
|
|
|
}
|
|
|
|
|
|
|
|
File.Name = FileName;
|
|
|
|
File.DirIndex = DirIndex;
|
|
|
|
|
|
|
|
// return the allocated FileNumber.
|
|
|
|
return FileNumber;
|
|
|
|
}
|
|
|
|
|
2010-10-01 00:52:03 +08:00
|
|
|
/// Utility function to emit the encoding to a streamer.
|
2015-08-07 23:14:08 +08:00
|
|
|
void MCDwarfLineAddr::Emit(MCStreamer *MCOS, MCDwarfLineTableParams Params,
|
|
|
|
int64_t LineDelta, uint64_t AddrDelta) {
|
2013-06-12 22:46:54 +08:00
|
|
|
MCContext &Context = MCOS->getContext();
|
2014-06-27 06:52:05 +08:00
|
|
|
SmallString<256> Tmp;
|
|
|
|
raw_svector_ostream OS(Tmp);
|
2015-08-07 23:14:08 +08:00
|
|
|
MCDwarfLineAddr::Encode(Context, Params, LineDelta, AddrDelta, OS);
|
2013-01-09 09:57:54 +08:00
|
|
|
MCOS->EmitBytes(OS.str());
|
2010-10-01 00:52:03 +08:00
|
|
|
}
|
|
|
|
|
2015-08-07 23:14:08 +08:00
|
|
|
/// Given a special op, return the address skip amount (in units of
|
|
|
|
/// DWARF2_LINE_MIN_INSN_LENGTH).
|
|
|
|
static uint64_t SpecialAddr(MCDwarfLineTableParams Params, uint64_t op) {
|
|
|
|
return (op - Params.DWARF2LineOpcodeBase) / Params.DWARF2LineRange;
|
|
|
|
}
|
|
|
|
|
2010-10-01 00:52:03 +08:00
|
|
|
/// Utility function to encode a Dwarf pair of LineDelta and AddrDeltas.
|
2015-08-07 23:14:08 +08:00
|
|
|
void MCDwarfLineAddr::Encode(MCContext &Context, MCDwarfLineTableParams Params,
|
|
|
|
int64_t LineDelta, uint64_t AddrDelta,
|
|
|
|
raw_ostream &OS) {
|
2010-10-01 00:52:03 +08:00
|
|
|
uint64_t Temp, Opcode;
|
|
|
|
bool NeedCopy = false;
|
|
|
|
|
2015-08-07 23:14:08 +08:00
|
|
|
// The maximum address skip amount that can be encoded with a special op.
|
|
|
|
uint64_t MaxSpecialAddrDelta = SpecialAddr(Params, 255);
|
|
|
|
|
2010-10-01 00:52:03 +08:00
|
|
|
// Scale the address delta by the minimum instruction length.
|
2013-06-12 22:46:54 +08:00
|
|
|
AddrDelta = ScaleAddrDelta(Context, AddrDelta);
|
2010-10-01 00:52:03 +08:00
|
|
|
|
|
|
|
// A LineDelta of INT64_MAX is a signal that this is actually a
|
2012-05-11 09:41:30 +08:00
|
|
|
// DW_LNE_end_sequence. We cannot use special opcodes here, since we want the
|
2010-10-01 00:52:03 +08:00
|
|
|
// end_sequence to emit the matrix entry.
|
|
|
|
if (LineDelta == INT64_MAX) {
|
2015-08-07 23:14:08 +08:00
|
|
|
if (AddrDelta == MaxSpecialAddrDelta)
|
2010-10-01 00:52:03 +08:00
|
|
|
OS << char(dwarf::DW_LNS_const_add_pc);
|
2015-03-16 04:45:39 +08:00
|
|
|
else if (AddrDelta) {
|
2010-10-01 00:52:03 +08:00
|
|
|
OS << char(dwarf::DW_LNS_advance_pc);
|
2012-08-09 07:56:06 +08:00
|
|
|
encodeULEB128(AddrDelta, OS);
|
2010-10-01 00:52:03 +08:00
|
|
|
}
|
|
|
|
OS << char(dwarf::DW_LNS_extended_op);
|
|
|
|
OS << char(1);
|
|
|
|
OS << char(dwarf::DW_LNE_end_sequence);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Bias the line delta by the base.
|
2015-08-07 23:14:08 +08:00
|
|
|
Temp = LineDelta - Params.DWARF2LineBase;
|
2010-10-01 00:52:03 +08:00
|
|
|
|
|
|
|
// If the line increment is out of range of a special opcode, we must encode
|
|
|
|
// it with DW_LNS_advance_line.
|
2016-02-01 06:06:35 +08:00
|
|
|
if (Temp >= Params.DWARF2LineRange ||
|
|
|
|
Temp + Params.DWARF2LineOpcodeBase > 255) {
|
2010-10-01 00:52:03 +08:00
|
|
|
OS << char(dwarf::DW_LNS_advance_line);
|
2012-08-09 07:56:06 +08:00
|
|
|
encodeSLEB128(LineDelta, OS);
|
2010-10-01 00:52:03 +08:00
|
|
|
|
|
|
|
LineDelta = 0;
|
2015-08-07 23:14:08 +08:00
|
|
|
Temp = 0 - Params.DWARF2LineBase;
|
2010-10-01 00:52:03 +08:00
|
|
|
NeedCopy = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Use DW_LNS_copy instead of a "line +0, addr +0" special opcode.
|
|
|
|
if (LineDelta == 0 && AddrDelta == 0) {
|
|
|
|
OS << char(dwarf::DW_LNS_copy);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Bias the opcode by the special opcode base.
|
2015-08-07 23:14:08 +08:00
|
|
|
Temp += Params.DWARF2LineOpcodeBase;
|
2010-10-01 00:52:03 +08:00
|
|
|
|
|
|
|
// Avoid overflow when addr_delta is large.
|
2015-08-07 23:14:08 +08:00
|
|
|
if (AddrDelta < 256 + MaxSpecialAddrDelta) {
|
2010-10-01 00:52:03 +08:00
|
|
|
// Try using a special opcode.
|
2015-08-07 23:14:08 +08:00
|
|
|
Opcode = Temp + AddrDelta * Params.DWARF2LineRange;
|
2010-10-01 00:52:03 +08:00
|
|
|
if (Opcode <= 255) {
|
|
|
|
OS << char(Opcode);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try using DW_LNS_const_add_pc followed by special op.
|
2015-08-07 23:14:08 +08:00
|
|
|
Opcode = Temp + (AddrDelta - MaxSpecialAddrDelta) * Params.DWARF2LineRange;
|
2010-10-01 00:52:03 +08:00
|
|
|
if (Opcode <= 255) {
|
|
|
|
OS << char(dwarf::DW_LNS_const_add_pc);
|
|
|
|
OS << char(Opcode);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise use DW_LNS_advance_pc.
|
|
|
|
OS << char(dwarf::DW_LNS_advance_pc);
|
2012-08-09 07:56:06 +08:00
|
|
|
encodeULEB128(AddrDelta, OS);
|
2010-10-01 00:52:03 +08:00
|
|
|
|
|
|
|
if (NeedCopy)
|
|
|
|
OS << char(dwarf::DW_LNS_copy);
|
2016-02-01 06:06:35 +08:00
|
|
|
else {
|
|
|
|
assert(Temp <= 255 && "Buggy special opcode encoding.");
|
2010-10-01 00:52:03 +08:00
|
|
|
OS << char(Temp);
|
2016-02-01 06:06:35 +08:00
|
|
|
}
|
2010-10-01 00:52:03 +08:00
|
|
|
}
|
|
|
|
|
2011-12-10 02:09:40 +08:00
|
|
|
// Utility function to write a tuple for .debug_abbrev.
|
|
|
|
static void EmitAbbrev(MCStreamer *MCOS, uint64_t Name, uint64_t Form) {
|
|
|
|
MCOS->EmitULEB128IntValue(Name);
|
|
|
|
MCOS->EmitULEB128IntValue(Form);
|
|
|
|
}
|
|
|
|
|
|
|
|
// When generating dwarf for assembly source files this emits
|
|
|
|
// the data for .debug_abbrev section which contains three DIEs.
|
|
|
|
static void EmitGenDwarfAbbrev(MCStreamer *MCOS) {
|
|
|
|
MCContext &context = MCOS->getContext();
|
|
|
|
MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfAbbrevSection());
|
|
|
|
|
|
|
|
// DW_TAG_compile_unit DIE abbrev (1).
|
|
|
|
MCOS->EmitULEB128IntValue(1);
|
|
|
|
MCOS->EmitULEB128IntValue(dwarf::DW_TAG_compile_unit);
|
|
|
|
MCOS->EmitIntValue(dwarf::DW_CHILDREN_yes, 1);
|
2016-01-05 02:49:15 +08:00
|
|
|
EmitAbbrev(MCOS, dwarf::DW_AT_stmt_list, context.getDwarfVersion() >= 4
|
|
|
|
? dwarf::DW_FORM_sec_offset
|
|
|
|
: dwarf::DW_FORM_data4);
|
2015-12-23 09:57:31 +08:00
|
|
|
if (context.getGenDwarfSectionSyms().size() > 1 &&
|
|
|
|
context.getDwarfVersion() >= 3) {
|
2016-01-05 02:49:15 +08:00
|
|
|
EmitAbbrev(MCOS, dwarf::DW_AT_ranges, context.getDwarfVersion() >= 4
|
|
|
|
? dwarf::DW_FORM_sec_offset
|
2015-12-23 09:57:31 +08:00
|
|
|
: dwarf::DW_FORM_data4);
|
2014-06-19 23:52:37 +08:00
|
|
|
} else {
|
|
|
|
EmitAbbrev(MCOS, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr);
|
|
|
|
EmitAbbrev(MCOS, dwarf::DW_AT_high_pc, dwarf::DW_FORM_addr);
|
|
|
|
}
|
2011-12-10 02:09:40 +08:00
|
|
|
EmitAbbrev(MCOS, dwarf::DW_AT_name, dwarf::DW_FORM_string);
|
2013-12-10 12:39:09 +08:00
|
|
|
if (!context.getCompilationDir().empty())
|
|
|
|
EmitAbbrev(MCOS, dwarf::DW_AT_comp_dir, dwarf::DW_FORM_string);
|
2011-12-10 02:09:40 +08:00
|
|
|
StringRef DwarfDebugFlags = context.getDwarfDebugFlags();
|
|
|
|
if (!DwarfDebugFlags.empty())
|
|
|
|
EmitAbbrev(MCOS, dwarf::DW_AT_APPLE_flags, dwarf::DW_FORM_string);
|
|
|
|
EmitAbbrev(MCOS, dwarf::DW_AT_producer, dwarf::DW_FORM_string);
|
|
|
|
EmitAbbrev(MCOS, dwarf::DW_AT_language, dwarf::DW_FORM_data2);
|
|
|
|
EmitAbbrev(MCOS, 0, 0);
|
|
|
|
|
2012-01-11 01:52:29 +08:00
|
|
|
// DW_TAG_label DIE abbrev (2).
|
2011-12-10 02:09:40 +08:00
|
|
|
MCOS->EmitULEB128IntValue(2);
|
2012-01-11 01:52:29 +08:00
|
|
|
MCOS->EmitULEB128IntValue(dwarf::DW_TAG_label);
|
2011-12-10 02:09:40 +08:00
|
|
|
MCOS->EmitIntValue(dwarf::DW_CHILDREN_yes, 1);
|
|
|
|
EmitAbbrev(MCOS, dwarf::DW_AT_name, dwarf::DW_FORM_string);
|
|
|
|
EmitAbbrev(MCOS, dwarf::DW_AT_decl_file, dwarf::DW_FORM_data4);
|
|
|
|
EmitAbbrev(MCOS, dwarf::DW_AT_decl_line, dwarf::DW_FORM_data4);
|
|
|
|
EmitAbbrev(MCOS, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr);
|
|
|
|
EmitAbbrev(MCOS, dwarf::DW_AT_prototyped, dwarf::DW_FORM_flag);
|
|
|
|
EmitAbbrev(MCOS, 0, 0);
|
|
|
|
|
|
|
|
// DW_TAG_unspecified_parameters DIE abbrev (3).
|
|
|
|
MCOS->EmitULEB128IntValue(3);
|
|
|
|
MCOS->EmitULEB128IntValue(dwarf::DW_TAG_unspecified_parameters);
|
|
|
|
MCOS->EmitIntValue(dwarf::DW_CHILDREN_no, 1);
|
|
|
|
EmitAbbrev(MCOS, 0, 0);
|
|
|
|
|
|
|
|
// Terminate the abbreviations for this compilation unit.
|
|
|
|
MCOS->EmitIntValue(0, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// When generating dwarf for assembly source files this emits the data for
|
2014-06-19 23:52:37 +08:00
|
|
|
// .debug_aranges section. This section contains a header and a table of pairs
|
|
|
|
// of PointerSize'ed values for the address and size of section(s) with line
|
|
|
|
// table entries.
|
2012-11-14 17:55:38 +08:00
|
|
|
static void EmitGenDwarfAranges(MCStreamer *MCOS,
|
|
|
|
const MCSymbol *InfoSectionSymbol) {
|
2011-12-10 02:09:40 +08:00
|
|
|
MCContext &context = MCOS->getContext();
|
|
|
|
|
2014-06-19 23:52:37 +08:00
|
|
|
auto &Sections = context.getGenDwarfSectionSyms();
|
2011-12-10 02:09:40 +08:00
|
|
|
|
|
|
|
MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfARangesSection());
|
|
|
|
|
|
|
|
// This will be the length of the .debug_aranges section, first account for
|
|
|
|
// the size of each item in the header (see below where we emit these items).
|
|
|
|
int Length = 4 + 2 + 4 + 1 + 1;
|
|
|
|
|
|
|
|
// Figure the padding after the header before the table of address and size
|
|
|
|
// pairs who's values are PointerSize'ed.
|
2013-06-18 15:20:20 +08:00
|
|
|
const MCAsmInfo *asmInfo = context.getAsmInfo();
|
|
|
|
int AddrSize = asmInfo->getPointerSize();
|
2011-12-10 02:09:40 +08:00
|
|
|
int Pad = 2 * AddrSize - (Length & (2 * AddrSize - 1));
|
|
|
|
if (Pad == 2 * AddrSize)
|
|
|
|
Pad = 0;
|
|
|
|
Length += Pad;
|
|
|
|
|
|
|
|
// Add the size of the pair of PointerSize'ed values for the address and size
|
2014-06-19 23:52:37 +08:00
|
|
|
// of each section we have in the table.
|
|
|
|
Length += 2 * AddrSize * Sections.size();
|
2011-12-10 02:09:40 +08:00
|
|
|
// And the pair of terminating zeros.
|
|
|
|
Length += 2 * AddrSize;
|
|
|
|
|
|
|
|
|
|
|
|
// Emit the header for this section.
|
|
|
|
// The 4 byte length not including the 4 byte value for the length.
|
|
|
|
MCOS->EmitIntValue(Length - 4, 4);
|
|
|
|
// The 2 byte version, which is 2.
|
|
|
|
MCOS->EmitIntValue(2, 2);
|
|
|
|
// The 4 byte offset to the compile unit in the .debug_info from the start
|
2012-11-14 17:55:38 +08:00
|
|
|
// of the .debug_info.
|
|
|
|
if (InfoSectionSymbol)
|
2014-09-07 03:57:48 +08:00
|
|
|
MCOS->EmitSymbolValue(InfoSectionSymbol, 4,
|
|
|
|
asmInfo->needsDwarfSectionOffsetDirective());
|
2012-11-14 17:55:38 +08:00
|
|
|
else
|
|
|
|
MCOS->EmitIntValue(0, 4);
|
2011-12-10 02:09:40 +08:00
|
|
|
// The 1 byte size of an address.
|
|
|
|
MCOS->EmitIntValue(AddrSize, 1);
|
|
|
|
// The 1 byte size of a segment descriptor, we use a value of zero.
|
|
|
|
MCOS->EmitIntValue(0, 1);
|
|
|
|
// Align the header with the padding if needed, before we put out the table.
|
|
|
|
for(int i = 0; i < Pad; i++)
|
|
|
|
MCOS->EmitIntValue(0, 1);
|
|
|
|
|
2014-06-19 23:52:37 +08:00
|
|
|
// Now emit the table of pairs of PointerSize'ed values for the section
|
|
|
|
// addresses and sizes.
|
2015-05-22 03:20:38 +08:00
|
|
|
for (MCSection *Sec : Sections) {
|
|
|
|
const MCSymbol *StartSymbol = Sec->getBeginSymbol();
|
2015-05-22 00:52:32 +08:00
|
|
|
MCSymbol *EndSymbol = Sec->getEndSymbol(context);
|
2014-06-19 23:52:37 +08:00
|
|
|
assert(StartSymbol && "StartSymbol must not be NULL");
|
|
|
|
assert(EndSymbol && "EndSymbol must not be NULL");
|
|
|
|
|
2015-05-30 09:25:56 +08:00
|
|
|
const MCExpr *Addr = MCSymbolRefExpr::create(
|
2014-06-19 23:52:37 +08:00
|
|
|
StartSymbol, MCSymbolRefExpr::VK_None, context);
|
|
|
|
const MCExpr *Size = MakeStartMinusEndExpr(*MCOS,
|
|
|
|
*StartSymbol, *EndSymbol, 0);
|
|
|
|
MCOS->EmitValue(Addr, AddrSize);
|
2014-08-15 23:12:13 +08:00
|
|
|
emitAbsValue(*MCOS, Size, AddrSize);
|
2014-06-19 23:52:37 +08:00
|
|
|
}
|
2011-12-10 02:09:40 +08:00
|
|
|
|
|
|
|
// And finally the pair of terminating zeros.
|
|
|
|
MCOS->EmitIntValue(0, AddrSize);
|
|
|
|
MCOS->EmitIntValue(0, AddrSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
// When generating dwarf for assembly source files this emits the data for
|
|
|
|
// .debug_info section which contains three parts. The header, the compile_unit
|
2012-01-11 01:52:29 +08:00
|
|
|
// DIE and a list of label DIEs.
|
2012-02-29 05:13:05 +08:00
|
|
|
static void EmitGenDwarfInfo(MCStreamer *MCOS,
|
|
|
|
const MCSymbol *AbbrevSectionSymbol,
|
2014-06-19 23:52:37 +08:00
|
|
|
const MCSymbol *LineSectionSymbol,
|
|
|
|
const MCSymbol *RangesSectionSymbol) {
|
2011-12-10 02:09:40 +08:00
|
|
|
MCContext &context = MCOS->getContext();
|
|
|
|
|
2012-05-11 09:41:30 +08:00
|
|
|
MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfInfoSection());
|
2011-12-10 02:09:40 +08:00
|
|
|
|
|
|
|
// Create a symbol at the start and end of this section used in here for the
|
|
|
|
// expression to calculate the length in the header.
|
2015-05-19 02:43:14 +08:00
|
|
|
MCSymbol *InfoStart = context.createTempSymbol();
|
2011-12-10 02:09:40 +08:00
|
|
|
MCOS->EmitLabel(InfoStart);
|
2015-05-19 02:43:14 +08:00
|
|
|
MCSymbol *InfoEnd = context.createTempSymbol();
|
2011-12-10 02:09:40 +08:00
|
|
|
|
|
|
|
// First part: the header.
|
|
|
|
|
|
|
|
// The 4 byte total length of the information for this compilation unit, not
|
|
|
|
// including these 4 bytes.
|
|
|
|
const MCExpr *Length = MakeStartMinusEndExpr(*MCOS, *InfoStart, *InfoEnd, 4);
|
2014-08-15 23:12:13 +08:00
|
|
|
emitAbsValue(*MCOS, Length, 4);
|
2011-12-10 02:09:40 +08:00
|
|
|
|
2014-05-01 16:46:02 +08:00
|
|
|
// The 2 byte DWARF version.
|
|
|
|
MCOS->EmitIntValue(context.getDwarfVersion(), 2);
|
2011-12-10 02:09:40 +08:00
|
|
|
|
2014-07-20 05:01:58 +08:00
|
|
|
const MCAsmInfo &AsmInfo = *context.getAsmInfo();
|
2011-12-10 02:09:40 +08:00
|
|
|
// The 4 byte offset to the debug abbrevs from the start of the .debug_abbrev,
|
|
|
|
// it is at the start of that section so this is zero.
|
2014-07-18 00:27:44 +08:00
|
|
|
if (AbbrevSectionSymbol == nullptr)
|
2012-02-29 05:13:05 +08:00
|
|
|
MCOS->EmitIntValue(0, 4);
|
2014-07-18 00:27:44 +08:00
|
|
|
else
|
2014-07-20 05:01:58 +08:00
|
|
|
MCOS->EmitSymbolValue(AbbrevSectionSymbol, 4,
|
|
|
|
AsmInfo.needsDwarfSectionOffsetDirective());
|
2011-12-10 02:09:40 +08:00
|
|
|
|
2013-06-18 15:20:20 +08:00
|
|
|
const MCAsmInfo *asmInfo = context.getAsmInfo();
|
|
|
|
int AddrSize = asmInfo->getPointerSize();
|
2011-12-10 02:09:40 +08:00
|
|
|
// The 1 byte size of an address.
|
|
|
|
MCOS->EmitIntValue(AddrSize, 1);
|
|
|
|
|
|
|
|
// Second part: the compile_unit DIE.
|
|
|
|
|
|
|
|
// The DW_TAG_compile_unit DIE abbrev (1).
|
|
|
|
MCOS->EmitULEB128IntValue(1);
|
|
|
|
|
|
|
|
// DW_AT_stmt_list, a 4 byte offset from the start of the .debug_line section,
|
|
|
|
// which is at the start of that section so this is zero.
|
2014-09-05 12:15:00 +08:00
|
|
|
if (LineSectionSymbol)
|
|
|
|
MCOS->EmitSymbolValue(LineSectionSymbol, 4,
|
|
|
|
AsmInfo.needsDwarfSectionOffsetDirective());
|
|
|
|
else
|
2012-02-29 05:13:05 +08:00
|
|
|
MCOS->EmitIntValue(0, 4);
|
2011-12-10 02:09:40 +08:00
|
|
|
|
2014-06-19 23:52:37 +08:00
|
|
|
if (RangesSectionSymbol) {
|
|
|
|
// There are multiple sections containing code, so we must use the
|
|
|
|
// .debug_ranges sections.
|
2011-12-10 02:09:40 +08:00
|
|
|
|
2014-06-19 23:52:37 +08:00
|
|
|
// AT_ranges, the 4 byte offset from the start of the .debug_ranges section
|
|
|
|
// to the address range list for this compilation unit.
|
|
|
|
MCOS->EmitSymbolValue(RangesSectionSymbol, 4);
|
|
|
|
} else {
|
|
|
|
// If we only have one non-empty code section, we can use the simpler
|
|
|
|
// AT_low_pc and AT_high_pc attributes.
|
|
|
|
|
|
|
|
// Find the first (and only) non-empty text section
|
|
|
|
auto &Sections = context.getGenDwarfSectionSyms();
|
|
|
|
const auto TextSection = Sections.begin();
|
|
|
|
assert(TextSection != Sections.end() && "No text section found");
|
|
|
|
|
2015-05-22 00:52:32 +08:00
|
|
|
MCSymbol *StartSymbol = (*TextSection)->getBeginSymbol();
|
|
|
|
MCSymbol *EndSymbol = (*TextSection)->getEndSymbol(context);
|
2014-06-19 23:52:37 +08:00
|
|
|
assert(StartSymbol && "StartSymbol must not be NULL");
|
|
|
|
assert(EndSymbol && "EndSymbol must not be NULL");
|
|
|
|
|
|
|
|
// AT_low_pc, the first address of the default .text section.
|
2015-05-30 09:25:56 +08:00
|
|
|
const MCExpr *Start = MCSymbolRefExpr::create(
|
2014-06-19 23:52:37 +08:00
|
|
|
StartSymbol, MCSymbolRefExpr::VK_None, context);
|
|
|
|
MCOS->EmitValue(Start, AddrSize);
|
|
|
|
|
|
|
|
// AT_high_pc, the last address of the default .text section.
|
2015-05-30 09:25:56 +08:00
|
|
|
const MCExpr *End = MCSymbolRefExpr::create(
|
2014-06-19 23:52:37 +08:00
|
|
|
EndSymbol, MCSymbolRefExpr::VK_None, context);
|
|
|
|
MCOS->EmitValue(End, AddrSize);
|
|
|
|
}
|
2011-12-10 02:09:40 +08:00
|
|
|
|
|
|
|
// AT_name, the name of the source file. Reconstruct from the first directory
|
|
|
|
// and file table entries.
|
2014-03-14 03:05:33 +08:00
|
|
|
const SmallVectorImpl<std::string> &MCDwarfDirs = context.getMCDwarfDirs();
|
2011-12-10 02:09:40 +08:00
|
|
|
if (MCDwarfDirs.size() > 0) {
|
2013-01-09 09:57:54 +08:00
|
|
|
MCOS->EmitBytes(MCDwarfDirs[0]);
|
2014-05-16 21:16:30 +08:00
|
|
|
MCOS->EmitBytes(sys::path::get_separator());
|
2011-12-10 02:09:40 +08:00
|
|
|
}
|
2014-03-14 02:55:04 +08:00
|
|
|
const SmallVectorImpl<MCDwarfFile> &MCDwarfFiles =
|
2011-12-10 02:09:40 +08:00
|
|
|
MCOS->getContext().getMCDwarfFiles();
|
2014-03-14 02:55:04 +08:00
|
|
|
MCOS->EmitBytes(MCDwarfFiles[1].Name);
|
2011-12-10 02:09:40 +08:00
|
|
|
MCOS->EmitIntValue(0, 1); // NULL byte to terminate the string.
|
|
|
|
|
|
|
|
// AT_comp_dir, the working directory the assembly was done in.
|
2013-12-10 12:39:09 +08:00
|
|
|
if (!context.getCompilationDir().empty()) {
|
|
|
|
MCOS->EmitBytes(context.getCompilationDir());
|
|
|
|
MCOS->EmitIntValue(0, 1); // NULL byte to terminate the string.
|
|
|
|
}
|
2011-12-10 02:09:40 +08:00
|
|
|
|
|
|
|
// AT_APPLE_flags, the command line arguments of the assembler tool.
|
|
|
|
StringRef DwarfDebugFlags = context.getDwarfDebugFlags();
|
|
|
|
if (!DwarfDebugFlags.empty()){
|
2013-01-09 09:57:54 +08:00
|
|
|
MCOS->EmitBytes(DwarfDebugFlags);
|
2011-12-10 02:09:40 +08:00
|
|
|
MCOS->EmitIntValue(0, 1); // NULL byte to terminate the string.
|
|
|
|
}
|
|
|
|
|
|
|
|
// AT_producer, the version of the assembler tool.
|
2013-01-17 01:46:23 +08:00
|
|
|
StringRef DwarfDebugProducer = context.getDwarfDebugProducer();
|
2014-07-18 00:27:35 +08:00
|
|
|
if (!DwarfDebugProducer.empty())
|
2013-01-17 01:46:23 +08:00
|
|
|
MCOS->EmitBytes(DwarfDebugProducer);
|
2014-07-18 00:27:35 +08:00
|
|
|
else
|
|
|
|
MCOS->EmitBytes(StringRef("llvm-mc (based on LLVM " PACKAGE_VERSION ")"));
|
2011-12-10 02:09:40 +08:00
|
|
|
MCOS->EmitIntValue(0, 1); // NULL byte to terminate the string.
|
|
|
|
|
|
|
|
// AT_language, a 4 byte value. We use DW_LANG_Mips_Assembler as the dwarf2
|
|
|
|
// draft has no standard code for assembler.
|
|
|
|
MCOS->EmitIntValue(dwarf::DW_LANG_Mips_Assembler, 2);
|
|
|
|
|
2012-01-11 01:52:29 +08:00
|
|
|
// Third part: the list of label DIEs.
|
2011-12-10 02:09:40 +08:00
|
|
|
|
2012-01-11 05:12:34 +08:00
|
|
|
// Loop on saved info for dwarf labels and create the DIEs for them.
|
2014-04-11 08:43:52 +08:00
|
|
|
const std::vector<MCGenDwarfLabelEntry> &Entries =
|
|
|
|
MCOS->getContext().getMCGenDwarfLabelEntries();
|
|
|
|
for (const auto &Entry : Entries) {
|
2012-01-11 01:52:29 +08:00
|
|
|
// The DW_TAG_label DIE abbrev (2).
|
2011-12-10 02:09:40 +08:00
|
|
|
MCOS->EmitULEB128IntValue(2);
|
|
|
|
|
|
|
|
// AT_name, of the label without any leading underbar.
|
2014-04-11 08:43:52 +08:00
|
|
|
MCOS->EmitBytes(Entry.getName());
|
2011-12-10 02:09:40 +08:00
|
|
|
MCOS->EmitIntValue(0, 1); // NULL byte to terminate the string.
|
|
|
|
|
|
|
|
// AT_decl_file, index into the file table.
|
2014-04-11 08:43:52 +08:00
|
|
|
MCOS->EmitIntValue(Entry.getFileNumber(), 4);
|
2011-12-10 02:09:40 +08:00
|
|
|
|
|
|
|
// AT_decl_line, source line number.
|
2014-04-11 08:43:52 +08:00
|
|
|
MCOS->EmitIntValue(Entry.getLineNumber(), 4);
|
2011-12-10 02:09:40 +08:00
|
|
|
|
|
|
|
// AT_low_pc, start address of the label.
|
2015-05-30 09:25:56 +08:00
|
|
|
const MCExpr *AT_low_pc = MCSymbolRefExpr::create(Entry.getLabel(),
|
2011-12-10 02:09:40 +08:00
|
|
|
MCSymbolRefExpr::VK_None, context);
|
2014-03-21 05:26:38 +08:00
|
|
|
MCOS->EmitValue(AT_low_pc, AddrSize);
|
2011-12-10 02:09:40 +08:00
|
|
|
|
|
|
|
// DW_AT_prototyped, a one byte flag value of 0 saying we have no prototype.
|
|
|
|
MCOS->EmitIntValue(0, 1);
|
|
|
|
|
|
|
|
// The DW_TAG_unspecified_parameters DIE abbrev (3).
|
|
|
|
MCOS->EmitULEB128IntValue(3);
|
|
|
|
|
|
|
|
// Add the NULL DIE terminating the DW_TAG_unspecified_parameters DIE's.
|
|
|
|
MCOS->EmitIntValue(0, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the NULL DIE terminating the Compile Unit DIE's.
|
|
|
|
MCOS->EmitIntValue(0, 1);
|
|
|
|
|
|
|
|
// Now set the value of the symbol at the end of the info section.
|
|
|
|
MCOS->EmitLabel(InfoEnd);
|
|
|
|
}
|
|
|
|
|
2014-06-19 23:52:37 +08:00
|
|
|
// When generating dwarf for assembly source files this emits the data for
|
|
|
|
// .debug_ranges section. We only emit one range list, which spans all of the
|
|
|
|
// executable sections of this file.
|
|
|
|
static void EmitGenDwarfRanges(MCStreamer *MCOS) {
|
|
|
|
MCContext &context = MCOS->getContext();
|
|
|
|
auto &Sections = context.getGenDwarfSectionSyms();
|
|
|
|
|
|
|
|
const MCAsmInfo *AsmInfo = context.getAsmInfo();
|
|
|
|
int AddrSize = AsmInfo->getPointerSize();
|
|
|
|
|
|
|
|
MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfRangesSection());
|
|
|
|
|
2015-05-22 03:20:38 +08:00
|
|
|
for (MCSection *Sec : Sections) {
|
|
|
|
const MCSymbol *StartSymbol = Sec->getBeginSymbol();
|
2015-05-22 00:52:32 +08:00
|
|
|
MCSymbol *EndSymbol = Sec->getEndSymbol(context);
|
2014-06-19 23:52:37 +08:00
|
|
|
assert(StartSymbol && "StartSymbol must not be NULL");
|
|
|
|
assert(EndSymbol && "EndSymbol must not be NULL");
|
|
|
|
|
|
|
|
// Emit a base address selection entry for the start of this section
|
2015-05-30 09:25:56 +08:00
|
|
|
const MCExpr *SectionStartAddr = MCSymbolRefExpr::create(
|
2014-06-19 23:52:37 +08:00
|
|
|
StartSymbol, MCSymbolRefExpr::VK_None, context);
|
2016-06-01 09:59:58 +08:00
|
|
|
MCOS->emitFill(AddrSize, 0xFF);
|
2014-06-19 23:52:37 +08:00
|
|
|
MCOS->EmitValue(SectionStartAddr, AddrSize);
|
|
|
|
|
|
|
|
// Emit a range list entry spanning this section
|
|
|
|
const MCExpr *SectionSize = MakeStartMinusEndExpr(*MCOS,
|
|
|
|
*StartSymbol, *EndSymbol, 0);
|
|
|
|
MCOS->EmitIntValue(0, AddrSize);
|
2014-08-15 23:12:13 +08:00
|
|
|
emitAbsValue(*MCOS, SectionSize, AddrSize);
|
2014-06-19 23:52:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Emit end of list entry
|
|
|
|
MCOS->EmitIntValue(0, AddrSize);
|
|
|
|
MCOS->EmitIntValue(0, AddrSize);
|
|
|
|
}
|
|
|
|
|
2011-12-10 02:09:40 +08:00
|
|
|
//
|
|
|
|
// When generating dwarf for assembly source files this emits the Dwarf
|
|
|
|
// sections.
|
|
|
|
//
|
2014-04-01 15:35:52 +08:00
|
|
|
void MCGenDwarfInfo::Emit(MCStreamer *MCOS) {
|
2011-12-10 02:09:40 +08:00
|
|
|
MCContext &context = MCOS->getContext();
|
2014-06-19 23:52:37 +08:00
|
|
|
|
|
|
|
// Create the dwarf sections in this order (.debug_line already created).
|
2013-06-18 15:20:20 +08:00
|
|
|
const MCAsmInfo *AsmInfo = context.getAsmInfo();
|
2012-11-14 17:55:38 +08:00
|
|
|
bool CreateDwarfSectionSymbols =
|
2013-06-18 15:20:20 +08:00
|
|
|
AsmInfo->doesDwarfUseRelocationsAcrossSections();
|
2014-04-01 15:35:52 +08:00
|
|
|
MCSymbol *LineSectionSymbol = nullptr;
|
2014-04-01 16:07:52 +08:00
|
|
|
if (CreateDwarfSectionSymbols)
|
|
|
|
LineSectionSymbol = MCOS->getDwarfLineTableSymbol(0);
|
2014-04-13 12:57:38 +08:00
|
|
|
MCSymbol *AbbrevSectionSymbol = nullptr;
|
|
|
|
MCSymbol *InfoSectionSymbol = nullptr;
|
2015-10-07 07:24:35 +08:00
|
|
|
MCSymbol *RangesSectionSymbol = nullptr;
|
2014-06-19 23:52:37 +08:00
|
|
|
|
|
|
|
// Create end symbols for each section, and remove empty sections
|
|
|
|
MCOS->getContext().finalizeDwarfSections(*MCOS);
|
|
|
|
|
|
|
|
// If there are no sections to generate debug info for, we don't need
|
|
|
|
// to do anything
|
|
|
|
if (MCOS->getContext().getGenDwarfSectionSyms().empty())
|
|
|
|
return;
|
|
|
|
|
2014-09-22 18:45:16 +08:00
|
|
|
// We only use the .debug_ranges section if we have multiple code sections,
|
|
|
|
// and we are emitting a DWARF version which supports it.
|
2014-06-19 23:52:37 +08:00
|
|
|
const bool UseRangesSection =
|
2014-09-22 18:45:16 +08:00
|
|
|
MCOS->getContext().getGenDwarfSectionSyms().size() > 1 &&
|
|
|
|
MCOS->getContext().getDwarfVersion() >= 3;
|
2014-06-19 23:52:37 +08:00
|
|
|
CreateDwarfSectionSymbols |= UseRangesSection;
|
|
|
|
|
2011-12-10 02:09:40 +08:00
|
|
|
MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfInfoSection());
|
2012-11-14 17:55:38 +08:00
|
|
|
if (CreateDwarfSectionSymbols) {
|
2015-05-19 02:43:14 +08:00
|
|
|
InfoSectionSymbol = context.createTempSymbol();
|
2012-11-14 17:55:38 +08:00
|
|
|
MCOS->EmitLabel(InfoSectionSymbol);
|
|
|
|
}
|
2011-12-10 02:09:40 +08:00
|
|
|
MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfAbbrevSection());
|
2012-11-14 17:55:38 +08:00
|
|
|
if (CreateDwarfSectionSymbols) {
|
2015-05-19 02:43:14 +08:00
|
|
|
AbbrevSectionSymbol = context.createTempSymbol();
|
2012-02-29 05:13:05 +08:00
|
|
|
MCOS->EmitLabel(AbbrevSectionSymbol);
|
|
|
|
}
|
2014-06-19 23:52:37 +08:00
|
|
|
if (UseRangesSection) {
|
|
|
|
MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfRangesSection());
|
|
|
|
if (CreateDwarfSectionSymbols) {
|
2015-05-19 02:43:14 +08:00
|
|
|
RangesSectionSymbol = context.createTempSymbol();
|
2014-06-19 23:52:37 +08:00
|
|
|
MCOS->EmitLabel(RangesSectionSymbol);
|
|
|
|
}
|
|
|
|
}
|
2011-12-10 02:09:40 +08:00
|
|
|
|
2014-06-19 23:52:37 +08:00
|
|
|
assert((RangesSectionSymbol != NULL) || !UseRangesSection);
|
|
|
|
|
|
|
|
MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfARangesSection());
|
2011-12-10 02:09:40 +08:00
|
|
|
|
|
|
|
// Output the data for .debug_aranges section.
|
2012-11-14 17:55:38 +08:00
|
|
|
EmitGenDwarfAranges(MCOS, InfoSectionSymbol);
|
2011-12-10 02:09:40 +08:00
|
|
|
|
2014-06-19 23:52:37 +08:00
|
|
|
if (UseRangesSection)
|
|
|
|
EmitGenDwarfRanges(MCOS);
|
|
|
|
|
2011-12-10 02:09:40 +08:00
|
|
|
// Output the data for .debug_abbrev section.
|
|
|
|
EmitGenDwarfAbbrev(MCOS);
|
|
|
|
|
|
|
|
// Output the data for .debug_info section.
|
2014-06-19 23:52:37 +08:00
|
|
|
EmitGenDwarfInfo(MCOS, AbbrevSectionSymbol, LineSectionSymbol,
|
|
|
|
RangesSectionSymbol);
|
2011-12-10 02:09:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// When generating dwarf for assembly source files this is called when symbol
|
|
|
|
// for a label is created. If this symbol is not a temporary and is in the
|
|
|
|
// section that dwarf is being generated for, save the needed info to create
|
2012-01-11 05:12:34 +08:00
|
|
|
// a dwarf label.
|
2011-12-10 02:09:40 +08:00
|
|
|
//
|
2012-01-11 05:12:34 +08:00
|
|
|
void MCGenDwarfLabelEntry::Make(MCSymbol *Symbol, MCStreamer *MCOS,
|
2011-12-10 02:09:40 +08:00
|
|
|
SourceMgr &SrcMgr, SMLoc &Loc) {
|
2014-06-19 23:52:37 +08:00
|
|
|
// We won't create dwarf labels for temporary symbols.
|
2011-12-10 02:09:40 +08:00
|
|
|
if (Symbol->isTemporary())
|
|
|
|
return;
|
|
|
|
MCContext &context = MCOS->getContext();
|
2014-06-19 23:52:37 +08:00
|
|
|
// We won't create dwarf labels for symbols in sections that we are not
|
|
|
|
// generating debug info for.
|
|
|
|
if (!context.getGenDwarfSectionSyms().count(MCOS->getCurrentSection().first))
|
2011-12-10 02:09:40 +08:00
|
|
|
return;
|
|
|
|
|
2012-01-11 05:12:34 +08:00
|
|
|
// The dwarf label's name does not have the symbol name's leading
|
2011-12-10 02:09:40 +08:00
|
|
|
// underbar if any.
|
|
|
|
StringRef Name = Symbol->getName();
|
|
|
|
if (Name.startswith("_"))
|
|
|
|
Name = Name.substr(1, Name.size()-1);
|
|
|
|
|
2012-01-11 05:12:34 +08:00
|
|
|
// Get the dwarf file number to be used for the dwarf label.
|
2011-12-10 02:09:40 +08:00
|
|
|
unsigned FileNumber = context.getGenDwarfFileNumber();
|
|
|
|
|
|
|
|
// Finding the line number is the expensive part which is why we just don't
|
2012-01-11 05:12:34 +08:00
|
|
|
// pass it in as for some symbols we won't create a dwarf label.
|
2014-07-06 18:33:31 +08:00
|
|
|
unsigned CurBuffer = SrcMgr.FindBufferContainingLoc(Loc);
|
2011-12-10 02:09:40 +08:00
|
|
|
unsigned LineNumber = SrcMgr.FindLineNumber(Loc, CurBuffer);
|
|
|
|
|
|
|
|
// We create a temporary symbol for use for the AT_high_pc and AT_low_pc
|
|
|
|
// values so that they don't have things like an ARM thumb bit from the
|
|
|
|
// original symbol. So when used they won't get a low bit set after
|
|
|
|
// relocation.
|
2015-05-19 02:43:14 +08:00
|
|
|
MCSymbol *Label = context.createTempSymbol();
|
2011-12-10 02:09:40 +08:00
|
|
|
MCOS->EmitLabel(Label);
|
|
|
|
|
|
|
|
// Create and entry for the info and add it to the other entries.
|
2014-04-11 08:43:52 +08:00
|
|
|
MCOS->getContext().addMCGenDwarfLabelEntry(
|
|
|
|
MCGenDwarfLabelEntry(Name, FileNumber, LineNumber, Label));
|
2011-12-10 02:09:40 +08:00
|
|
|
}
|
|
|
|
|
2010-12-10 15:39:47 +08:00
|
|
|
static int getDataAlignmentFactor(MCStreamer &streamer) {
|
|
|
|
MCContext &context = streamer.getContext();
|
2013-06-18 15:20:20 +08:00
|
|
|
const MCAsmInfo *asmInfo = context.getAsmInfo();
|
|
|
|
int size = asmInfo->getCalleeSaveStackSlotSize();
|
|
|
|
if (asmInfo->isStackGrowthDirectionUp())
|
2010-12-10 15:39:47 +08:00
|
|
|
return size;
|
2011-07-15 10:09:41 +08:00
|
|
|
else
|
|
|
|
return -size;
|
2010-12-10 15:39:47 +08:00
|
|
|
}
|
|
|
|
|
2011-04-22 08:08:43 +08:00
|
|
|
static unsigned getSizeForEncoding(MCStreamer &streamer,
|
|
|
|
unsigned symbolEncoding) {
|
2011-04-13 00:12:03 +08:00
|
|
|
MCContext &context = streamer.getContext();
|
|
|
|
unsigned format = symbolEncoding & 0x0f;
|
|
|
|
switch (format) {
|
2012-02-07 13:05:23 +08:00
|
|
|
default: llvm_unreachable("Unknown Encoding");
|
2011-04-13 00:12:03 +08:00
|
|
|
case dwarf::DW_EH_PE_absptr:
|
|
|
|
case dwarf::DW_EH_PE_signed:
|
2013-06-18 15:20:20 +08:00
|
|
|
return context.getAsmInfo()->getPointerSize();
|
2011-04-13 00:12:03 +08:00
|
|
|
case dwarf::DW_EH_PE_udata2:
|
|
|
|
case dwarf::DW_EH_PE_sdata2:
|
2011-04-22 08:08:43 +08:00
|
|
|
return 2;
|
2011-04-13 00:12:03 +08:00
|
|
|
case dwarf::DW_EH_PE_udata4:
|
|
|
|
case dwarf::DW_EH_PE_sdata4:
|
2011-04-22 08:08:43 +08:00
|
|
|
return 4;
|
2011-04-13 00:12:03 +08:00
|
|
|
case dwarf::DW_EH_PE_udata8:
|
|
|
|
case dwarf::DW_EH_PE_sdata8:
|
2011-04-22 08:08:43 +08:00
|
|
|
return 8;
|
2011-04-13 00:12:03 +08:00
|
|
|
}
|
2011-04-22 08:08:43 +08:00
|
|
|
}
|
|
|
|
|
2014-08-15 11:07:13 +08:00
|
|
|
static void emitFDESymbol(MCObjectStreamer &streamer, const MCSymbol &symbol,
|
|
|
|
unsigned symbolEncoding, bool isEH) {
|
2011-04-29 05:04:39 +08:00
|
|
|
MCContext &context = streamer.getContext();
|
2013-06-18 15:20:20 +08:00
|
|
|
const MCAsmInfo *asmInfo = context.getAsmInfo();
|
|
|
|
const MCExpr *v = asmInfo->getExprForFDESymbol(&symbol,
|
|
|
|
symbolEncoding,
|
|
|
|
streamer);
|
2011-04-22 08:08:43 +08:00
|
|
|
unsigned size = getSizeForEncoding(streamer, symbolEncoding);
|
2014-01-08 18:22:54 +08:00
|
|
|
if (asmInfo->doDwarfFDESymbolsUseAbsDiff() && isEH)
|
2014-08-15 23:12:13 +08:00
|
|
|
emitAbsValue(streamer, v, size);
|
2014-01-08 18:22:54 +08:00
|
|
|
else
|
|
|
|
streamer.EmitValue(v, size);
|
2011-04-13 00:12:03 +08:00
|
|
|
}
|
|
|
|
|
2011-04-29 00:09:09 +08:00
|
|
|
static void EmitPersonality(MCStreamer &streamer, const MCSymbol &symbol,
|
|
|
|
unsigned symbolEncoding) {
|
|
|
|
MCContext &context = streamer.getContext();
|
2013-06-18 15:20:20 +08:00
|
|
|
const MCAsmInfo *asmInfo = context.getAsmInfo();
|
|
|
|
const MCExpr *v = asmInfo->getExprForPersonalitySymbol(&symbol,
|
|
|
|
symbolEncoding,
|
|
|
|
streamer);
|
2011-04-29 00:09:09 +08:00
|
|
|
unsigned size = getSizeForEncoding(streamer, symbolEncoding);
|
2011-05-01 11:50:49 +08:00
|
|
|
streamer.EmitValue(v, size);
|
2011-04-29 00:09:09 +08:00
|
|
|
}
|
|
|
|
|
2011-04-13 00:12:03 +08:00
|
|
|
namespace {
|
2015-11-06 07:54:18 +08:00
|
|
|
class FrameEmitterImpl {
|
2015-11-06 07:55:51 +08:00
|
|
|
int CFAOffset = 0;
|
|
|
|
int InitialCFAOffset = 0;
|
2015-11-06 07:54:18 +08:00
|
|
|
bool IsEH;
|
2015-11-06 08:05:57 +08:00
|
|
|
MCObjectStreamer &Streamer;
|
2015-11-06 07:54:18 +08:00
|
|
|
|
|
|
|
public:
|
2015-11-06 08:05:57 +08:00
|
|
|
FrameEmitterImpl(bool IsEH, MCObjectStreamer &Streamer)
|
|
|
|
: IsEH(IsEH), Streamer(Streamer) {}
|
2015-11-06 07:54:18 +08:00
|
|
|
|
|
|
|
/// Emit the unwind information in a compact way.
|
2015-11-06 08:05:57 +08:00
|
|
|
void EmitCompactUnwind(const MCDwarfFrameInfo &frame);
|
2015-11-06 07:54:18 +08:00
|
|
|
|
2015-11-06 08:05:57 +08:00
|
|
|
const MCSymbol &EmitCIE(const MCSymbol *personality,
|
2015-11-06 07:54:18 +08:00
|
|
|
unsigned personalityEncoding, const MCSymbol *lsda,
|
|
|
|
bool IsSignalFrame, unsigned lsdaEncoding,
|
|
|
|
bool IsSimple);
|
2015-11-06 11:02:51 +08:00
|
|
|
void EmitFDE(const MCSymbol &cieStart, const MCDwarfFrameInfo &frame,
|
2015-11-06 21:14:59 +08:00
|
|
|
bool LastInSection, const MCSymbol &SectionStart);
|
2015-11-06 08:05:57 +08:00
|
|
|
void EmitCFIInstructions(ArrayRef<MCCFIInstruction> Instrs,
|
2015-11-06 07:54:18 +08:00
|
|
|
MCSymbol *BaseLabel);
|
2015-11-06 08:05:57 +08:00
|
|
|
void EmitCFIInstruction(const MCCFIInstruction &Instr);
|
2015-11-06 07:54:18 +08:00
|
|
|
};
|
2011-07-01 05:25:51 +08:00
|
|
|
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
2014-08-15 11:07:13 +08:00
|
|
|
static void emitEncodingByte(MCObjectStreamer &Streamer, unsigned Encoding) {
|
2011-07-01 05:25:51 +08:00
|
|
|
Streamer.EmitIntValue(Encoding, 1);
|
2011-04-13 00:12:03 +08:00
|
|
|
}
|
|
|
|
|
2015-11-06 08:05:57 +08:00
|
|
|
void FrameEmitterImpl::EmitCFIInstruction(const MCCFIInstruction &Instr) {
|
2010-12-29 02:36:23 +08:00
|
|
|
int dataAlignmentFactor = getDataAlignmentFactor(Streamer);
|
2015-02-27 03:48:07 +08:00
|
|
|
auto *MRI = Streamer.getContext().getRegisterInfo();
|
2010-12-10 15:39:47 +08:00
|
|
|
|
2010-12-29 02:36:23 +08:00
|
|
|
switch (Instr.getOperation()) {
|
2012-11-25 23:14:49 +08:00
|
|
|
case MCCFIInstruction::OpRegister: {
|
|
|
|
unsigned Reg1 = Instr.getRegister();
|
|
|
|
unsigned Reg2 = Instr.getRegister2();
|
2015-02-27 03:48:07 +08:00
|
|
|
if (!IsEH) {
|
|
|
|
Reg1 = MRI->getDwarfRegNum(MRI->getLLVMRegNum(Reg1, true), false);
|
|
|
|
Reg2 = MRI->getDwarfRegNum(MRI->getLLVMRegNum(Reg2, true), false);
|
|
|
|
}
|
2012-11-25 23:14:49 +08:00
|
|
|
Streamer.EmitIntValue(dwarf::DW_CFA_register, 1);
|
|
|
|
Streamer.EmitULEB128IntValue(Reg1);
|
|
|
|
Streamer.EmitULEB128IntValue(Reg2);
|
|
|
|
return;
|
|
|
|
}
|
2013-09-26 22:49:40 +08:00
|
|
|
case MCCFIInstruction::OpWindowSave: {
|
|
|
|
Streamer.EmitIntValue(dwarf::DW_CFA_GNU_window_save, 1);
|
|
|
|
return;
|
|
|
|
}
|
2012-11-24 11:10:54 +08:00
|
|
|
case MCCFIInstruction::OpUndefined: {
|
2012-11-24 12:33:48 +08:00
|
|
|
unsigned Reg = Instr.getRegister();
|
2012-11-24 00:59:41 +08:00
|
|
|
Streamer.EmitIntValue(dwarf::DW_CFA_undefined, 1);
|
|
|
|
Streamer.EmitULEB128IntValue(Reg);
|
|
|
|
return;
|
|
|
|
}
|
2012-11-24 11:10:54 +08:00
|
|
|
case MCCFIInstruction::OpAdjustCfaOffset:
|
|
|
|
case MCCFIInstruction::OpDefCfaOffset: {
|
|
|
|
const bool IsRelative =
|
|
|
|
Instr.getOperation() == MCCFIInstruction::OpAdjustCfaOffset;
|
2010-12-10 15:39:47 +08:00
|
|
|
|
2012-11-24 11:10:54 +08:00
|
|
|
Streamer.EmitIntValue(dwarf::DW_CFA_def_cfa_offset, 1);
|
2011-04-13 02:53:30 +08:00
|
|
|
|
2012-11-24 11:10:54 +08:00
|
|
|
if (IsRelative)
|
2012-11-24 12:33:48 +08:00
|
|
|
CFAOffset += Instr.getOffset();
|
2012-11-24 11:10:54 +08:00
|
|
|
else
|
2012-11-24 12:33:48 +08:00
|
|
|
CFAOffset = -Instr.getOffset();
|
2010-12-10 15:39:47 +08:00
|
|
|
|
2012-11-24 11:10:54 +08:00
|
|
|
Streamer.EmitULEB128IntValue(CFAOffset);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case MCCFIInstruction::OpDefCfa: {
|
2015-02-27 03:48:07 +08:00
|
|
|
unsigned Reg = Instr.getRegister();
|
|
|
|
if (!IsEH)
|
|
|
|
Reg = MRI->getDwarfRegNum(MRI->getLLVMRegNum(Reg, true), false);
|
2012-11-24 11:10:54 +08:00
|
|
|
Streamer.EmitIntValue(dwarf::DW_CFA_def_cfa, 1);
|
2015-02-27 03:48:07 +08:00
|
|
|
Streamer.EmitULEB128IntValue(Reg);
|
2012-11-24 12:33:48 +08:00
|
|
|
CFAOffset = -Instr.getOffset();
|
2012-11-24 11:10:54 +08:00
|
|
|
Streamer.EmitULEB128IntValue(CFAOffset);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
case MCCFIInstruction::OpDefCfaRegister: {
|
2015-02-27 03:48:07 +08:00
|
|
|
unsigned Reg = Instr.getRegister();
|
|
|
|
if (!IsEH)
|
|
|
|
Reg = MRI->getDwarfRegNum(MRI->getLLVMRegNum(Reg, true), false);
|
2012-11-24 11:10:54 +08:00
|
|
|
Streamer.EmitIntValue(dwarf::DW_CFA_def_cfa_register, 1);
|
2015-02-27 03:48:07 +08:00
|
|
|
Streamer.EmitULEB128IntValue(Reg);
|
2012-11-24 11:10:54 +08:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
case MCCFIInstruction::OpOffset:
|
|
|
|
case MCCFIInstruction::OpRelOffset: {
|
|
|
|
const bool IsRelative =
|
|
|
|
Instr.getOperation() == MCCFIInstruction::OpRelOffset;
|
2010-12-10 15:39:47 +08:00
|
|
|
|
2012-11-24 12:33:48 +08:00
|
|
|
unsigned Reg = Instr.getRegister();
|
2015-02-27 03:48:07 +08:00
|
|
|
if (!IsEH)
|
|
|
|
Reg = MRI->getDwarfRegNum(MRI->getLLVMRegNum(Reg, true), false);
|
|
|
|
|
2012-11-24 12:33:48 +08:00
|
|
|
int Offset = Instr.getOffset();
|
2011-04-13 00:12:03 +08:00
|
|
|
if (IsRelative)
|
|
|
|
Offset -= CFAOffset;
|
|
|
|
Offset = Offset / dataAlignmentFactor;
|
2010-12-10 15:39:47 +08:00
|
|
|
|
|
|
|
if (Offset < 0) {
|
2010-12-29 02:36:23 +08:00
|
|
|
Streamer.EmitIntValue(dwarf::DW_CFA_offset_extended_sf, 1);
|
|
|
|
Streamer.EmitULEB128IntValue(Reg);
|
|
|
|
Streamer.EmitSLEB128IntValue(Offset);
|
2010-12-10 15:39:47 +08:00
|
|
|
} else if (Reg < 64) {
|
2010-12-29 02:36:23 +08:00
|
|
|
Streamer.EmitIntValue(dwarf::DW_CFA_offset + Reg, 1);
|
2011-04-22 07:26:40 +08:00
|
|
|
Streamer.EmitULEB128IntValue(Offset);
|
2010-12-10 15:39:47 +08:00
|
|
|
} else {
|
2010-12-29 02:36:23 +08:00
|
|
|
Streamer.EmitIntValue(dwarf::DW_CFA_offset_extended, 1);
|
2011-04-22 07:26:40 +08:00
|
|
|
Streamer.EmitULEB128IntValue(Reg);
|
|
|
|
Streamer.EmitULEB128IntValue(Offset);
|
2010-12-29 02:36:23 +08:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2012-11-24 11:10:54 +08:00
|
|
|
case MCCFIInstruction::OpRememberState:
|
2010-12-29 02:36:23 +08:00
|
|
|
Streamer.EmitIntValue(dwarf::DW_CFA_remember_state, 1);
|
|
|
|
return;
|
2012-11-24 11:10:54 +08:00
|
|
|
case MCCFIInstruction::OpRestoreState:
|
2010-12-29 02:36:23 +08:00
|
|
|
Streamer.EmitIntValue(dwarf::DW_CFA_restore_state, 1);
|
|
|
|
return;
|
2012-11-24 11:10:54 +08:00
|
|
|
case MCCFIInstruction::OpSameValue: {
|
2012-11-24 12:33:48 +08:00
|
|
|
unsigned Reg = Instr.getRegister();
|
2011-04-12 23:31:05 +08:00
|
|
|
Streamer.EmitIntValue(dwarf::DW_CFA_same_value, 1);
|
2011-04-22 07:39:26 +08:00
|
|
|
Streamer.EmitULEB128IntValue(Reg);
|
2011-04-12 23:31:05 +08:00
|
|
|
return;
|
|
|
|
}
|
2012-11-24 11:10:54 +08:00
|
|
|
case MCCFIInstruction::OpRestore: {
|
2012-11-24 12:33:48 +08:00
|
|
|
unsigned Reg = Instr.getRegister();
|
2015-02-27 03:48:07 +08:00
|
|
|
if (!IsEH)
|
|
|
|
Reg = MRI->getDwarfRegNum(MRI->getLLVMRegNum(Reg, true), false);
|
2011-12-30 05:43:03 +08:00
|
|
|
Streamer.EmitIntValue(dwarf::DW_CFA_restore | Reg, 1);
|
|
|
|
return;
|
|
|
|
}
|
2015-10-07 15:01:31 +08:00
|
|
|
case MCCFIInstruction::OpGnuArgsSize: {
|
|
|
|
Streamer.EmitIntValue(dwarf::DW_CFA_GNU_args_size, 1);
|
|
|
|
Streamer.EmitULEB128IntValue(Instr.getOffset());
|
|
|
|
return;
|
|
|
|
}
|
2012-11-24 11:10:54 +08:00
|
|
|
case MCCFIInstruction::OpEscape:
|
2013-01-09 09:57:54 +08:00
|
|
|
Streamer.EmitBytes(Instr.getValues());
|
2011-12-30 04:24:47 +08:00
|
|
|
return;
|
2010-12-29 02:36:23 +08:00
|
|
|
}
|
|
|
|
llvm_unreachable("Unhandled case in switch");
|
|
|
|
}
|
|
|
|
|
2014-08-15 11:07:13 +08:00
|
|
|
/// Emit frame instructions to describe the layout of the frame.
|
2015-11-06 08:05:57 +08:00
|
|
|
void FrameEmitterImpl::EmitCFIInstructions(ArrayRef<MCCFIInstruction> Instrs,
|
2011-04-13 00:12:03 +08:00
|
|
|
MCSymbol *BaseLabel) {
|
2010-12-29 02:36:23 +08:00
|
|
|
for (unsigned i = 0, N = Instrs.size(); i < N; ++i) {
|
|
|
|
const MCCFIInstruction &Instr = Instrs[i];
|
|
|
|
MCSymbol *Label = Instr.getLabel();
|
|
|
|
// Throw out move if the label is invalid.
|
|
|
|
if (Label && !Label->isDefined()) continue; // Not emitted, in dead code.
|
|
|
|
|
|
|
|
// Advance row if new location.
|
|
|
|
if (BaseLabel && Label) {
|
|
|
|
MCSymbol *ThisSym = Label;
|
|
|
|
if (ThisSym != BaseLabel) {
|
2015-11-06 08:05:57 +08:00
|
|
|
Streamer.EmitDwarfAdvanceFrameAddr(BaseLabel, ThisSym);
|
2010-12-29 02:36:23 +08:00
|
|
|
BaseLabel = ThisSym;
|
|
|
|
}
|
2010-12-10 15:39:47 +08:00
|
|
|
}
|
2010-12-29 02:36:23 +08:00
|
|
|
|
2015-11-06 08:05:57 +08:00
|
|
|
EmitCFIInstruction(Instr);
|
2010-12-10 15:39:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-15 11:07:13 +08:00
|
|
|
/// Emit the unwind information in a compact way.
|
2015-11-06 08:05:57 +08:00
|
|
|
void FrameEmitterImpl::EmitCompactUnwind(const MCDwarfFrameInfo &Frame) {
|
2011-06-23 09:06:23 +08:00
|
|
|
MCContext &Context = Streamer.getContext();
|
2011-07-20 13:58:47 +08:00
|
|
|
const MCObjectFileInfo *MOFI = Context.getObjectFileInfo();
|
2011-06-23 09:06:23 +08:00
|
|
|
|
|
|
|
// range-start range-length compact-unwind-enc personality-func lsda
|
|
|
|
// _foo LfooEnd-_foo 0x00000023 0 0
|
|
|
|
// _bar LbarEnd-_bar 0x00000025 __gxx_personality except_tab1
|
|
|
|
//
|
|
|
|
// .section __LD,__compact_unwind,regular,debug
|
|
|
|
//
|
|
|
|
// # compact unwind for _foo
|
|
|
|
// .quad _foo
|
|
|
|
// .set L1,LfooEnd-_foo
|
|
|
|
// .long L1
|
|
|
|
// .long 0x01010001
|
|
|
|
// .quad 0
|
|
|
|
// .quad 0
|
|
|
|
//
|
|
|
|
// # compact unwind for _bar
|
|
|
|
// .quad _bar
|
|
|
|
// .set L2,LbarEnd-_bar
|
|
|
|
// .long L2
|
|
|
|
// .long 0x01020011
|
|
|
|
// .quad __gxx_personality
|
|
|
|
// .quad except_tab1
|
|
|
|
|
2011-07-19 08:06:12 +08:00
|
|
|
uint32_t Encoding = Frame.CompactUnwindEncoding;
|
2013-04-19 07:16:46 +08:00
|
|
|
if (!Encoding) return;
|
2013-04-11 05:42:06 +08:00
|
|
|
bool DwarfEHFrameOnly = (Encoding == MOFI->getCompactUnwindDwarfEHFrameOnly());
|
2011-07-07 08:54:13 +08:00
|
|
|
|
2011-07-15 07:34:45 +08:00
|
|
|
// The encoding needs to know we have an LSDA.
|
2013-04-11 05:42:06 +08:00
|
|
|
if (!DwarfEHFrameOnly && Frame.Lsda)
|
2011-07-15 07:34:45 +08:00
|
|
|
Encoding |= 0x40000000;
|
|
|
|
|
2011-06-23 09:06:23 +08:00
|
|
|
// Range Start
|
2014-05-12 21:47:05 +08:00
|
|
|
unsigned FDEEncoding = MOFI->getFDEEncoding();
|
2011-06-30 07:49:12 +08:00
|
|
|
unsigned Size = getSizeForEncoding(Streamer, FDEEncoding);
|
2014-06-23 23:34:32 +08:00
|
|
|
Streamer.EmitSymbolValue(Frame.Begin, Size);
|
2011-06-23 09:06:23 +08:00
|
|
|
|
|
|
|
// Range Length
|
|
|
|
const MCExpr *Range = MakeStartMinusEndExpr(Streamer, *Frame.Begin,
|
|
|
|
*Frame.End, 0);
|
2014-08-15 23:12:13 +08:00
|
|
|
emitAbsValue(Streamer, Range, 4);
|
2011-06-30 08:30:52 +08:00
|
|
|
|
|
|
|
// Compact Encoding
|
|
|
|
Size = getSizeForEncoding(Streamer, dwarf::DW_EH_PE_udata4);
|
|
|
|
Streamer.EmitIntValue(Encoding, Size);
|
|
|
|
|
2011-06-30 07:49:12 +08:00
|
|
|
// Personality Function
|
2011-07-15 07:34:45 +08:00
|
|
|
Size = getSizeForEncoding(Streamer, dwarf::DW_EH_PE_absptr);
|
2013-04-11 05:42:06 +08:00
|
|
|
if (!DwarfEHFrameOnly && Frame.Personality)
|
2011-06-30 07:49:12 +08:00
|
|
|
Streamer.EmitSymbolValue(Frame.Personality, Size);
|
2011-06-30 07:53:16 +08:00
|
|
|
else
|
|
|
|
Streamer.EmitIntValue(0, Size); // No personality fn
|
2011-06-30 07:49:12 +08:00
|
|
|
|
|
|
|
// LSDA
|
2011-06-30 07:53:16 +08:00
|
|
|
Size = getSizeForEncoding(Streamer, Frame.LsdaEncoding);
|
2013-04-11 05:42:06 +08:00
|
|
|
if (!DwarfEHFrameOnly && Frame.Lsda)
|
2011-06-30 07:49:12 +08:00
|
|
|
Streamer.EmitSymbolValue(Frame.Lsda, Size);
|
2011-06-30 07:53:16 +08:00
|
|
|
else
|
|
|
|
Streamer.EmitIntValue(0, Size); // No LSDA
|
2011-06-23 09:06:23 +08:00
|
|
|
}
|
|
|
|
|
2015-04-28 21:55:31 +08:00
|
|
|
static unsigned getCIEVersion(bool IsEH, unsigned DwarfVersion) {
|
|
|
|
if (IsEH)
|
|
|
|
return 1;
|
|
|
|
switch (DwarfVersion) {
|
|
|
|
case 2:
|
|
|
|
return 1;
|
|
|
|
case 3:
|
|
|
|
return 3;
|
|
|
|
case 4:
|
2015-12-29 07:02:42 +08:00
|
|
|
case 5:
|
2015-04-28 21:55:31 +08:00
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
llvm_unreachable("Unknown version");
|
|
|
|
}
|
|
|
|
|
2015-11-06 08:05:57 +08:00
|
|
|
const MCSymbol &FrameEmitterImpl::EmitCIE(const MCSymbol *personality,
|
2011-04-13 00:12:03 +08:00
|
|
|
unsigned personalityEncoding,
|
|
|
|
const MCSymbol *lsda,
|
2012-01-24 05:51:52 +08:00
|
|
|
bool IsSignalFrame,
|
2014-01-28 01:20:25 +08:00
|
|
|
unsigned lsdaEncoding,
|
|
|
|
bool IsSimple) {
|
2015-11-06 08:05:57 +08:00
|
|
|
MCContext &context = Streamer.getContext();
|
2013-06-18 15:20:20 +08:00
|
|
|
const MCRegisterInfo *MRI = context.getRegisterInfo();
|
2011-07-20 13:58:47 +08:00
|
|
|
const MCObjectFileInfo *MOFI = context.getObjectFileInfo();
|
2011-04-28 11:26:11 +08:00
|
|
|
|
2015-05-19 02:43:14 +08:00
|
|
|
MCSymbol *sectionStart = context.createTempSymbol();
|
2015-11-06 08:05:57 +08:00
|
|
|
Streamer.EmitLabel(sectionStart);
|
2011-04-28 11:26:11 +08:00
|
|
|
|
2015-05-19 02:43:14 +08:00
|
|
|
MCSymbol *sectionEnd = context.createTempSymbol();
|
2010-12-10 15:39:47 +08:00
|
|
|
|
|
|
|
// Length
|
2015-11-06 08:05:57 +08:00
|
|
|
const MCExpr *Length =
|
|
|
|
MakeStartMinusEndExpr(Streamer, *sectionStart, *sectionEnd, 4);
|
|
|
|
emitAbsValue(Streamer, Length, 4);
|
2010-12-10 15:39:47 +08:00
|
|
|
|
|
|
|
// CIE ID
|
2011-05-10 11:54:12 +08:00
|
|
|
unsigned CIE_ID = IsEH ? 0 : -1;
|
2015-11-06 08:05:57 +08:00
|
|
|
Streamer.EmitIntValue(CIE_ID, 4);
|
2010-12-10 15:39:47 +08:00
|
|
|
|
|
|
|
// Version
|
2015-04-28 21:55:31 +08:00
|
|
|
uint8_t CIEVersion = getCIEVersion(IsEH, context.getDwarfVersion());
|
2015-11-06 08:05:57 +08:00
|
|
|
Streamer.EmitIntValue(CIEVersion, 1);
|
2010-12-10 15:39:47 +08:00
|
|
|
|
|
|
|
// Augmentation String
|
|
|
|
SmallString<8> Augmentation;
|
2011-05-10 11:54:12 +08:00
|
|
|
if (IsEH) {
|
|
|
|
Augmentation += "z";
|
|
|
|
if (personality)
|
|
|
|
Augmentation += "P";
|
|
|
|
if (lsda)
|
|
|
|
Augmentation += "L";
|
|
|
|
Augmentation += "R";
|
2012-01-24 05:51:52 +08:00
|
|
|
if (IsSignalFrame)
|
|
|
|
Augmentation += "S";
|
2015-11-06 08:05:57 +08:00
|
|
|
Streamer.EmitBytes(Augmentation);
|
2011-05-10 11:54:12 +08:00
|
|
|
}
|
2015-11-06 08:05:57 +08:00
|
|
|
Streamer.EmitIntValue(0, 1);
|
2010-12-10 15:39:47 +08:00
|
|
|
|
2015-05-12 23:25:08 +08:00
|
|
|
if (CIEVersion >= 4) {
|
|
|
|
// Address Size
|
2015-11-06 08:05:57 +08:00
|
|
|
Streamer.EmitIntValue(context.getAsmInfo()->getPointerSize(), 1);
|
2015-05-12 23:25:08 +08:00
|
|
|
|
|
|
|
// Segment Descriptor Size
|
2015-11-06 08:05:57 +08:00
|
|
|
Streamer.EmitIntValue(0, 1);
|
2015-05-12 23:25:08 +08:00
|
|
|
}
|
|
|
|
|
2010-12-10 15:39:47 +08:00
|
|
|
// Code Alignment Factor
|
2015-11-06 08:05:57 +08:00
|
|
|
Streamer.EmitULEB128IntValue(context.getAsmInfo()->getMinInstAlignment());
|
2010-12-10 15:39:47 +08:00
|
|
|
|
|
|
|
// Data Alignment Factor
|
2015-11-06 08:05:57 +08:00
|
|
|
Streamer.EmitSLEB128IntValue(getDataAlignmentFactor(Streamer));
|
2010-12-10 15:39:47 +08:00
|
|
|
|
|
|
|
// Return Address Register
|
2014-06-19 23:39:33 +08:00
|
|
|
if (CIEVersion == 1) {
|
|
|
|
assert(MRI->getRARegister() <= 255 &&
|
|
|
|
"DWARF 2 encodes return_address_register in one byte");
|
2015-11-06 08:05:57 +08:00
|
|
|
Streamer.EmitIntValue(MRI->getDwarfRegNum(MRI->getRARegister(), IsEH), 1);
|
2014-06-19 23:39:33 +08:00
|
|
|
} else {
|
2015-11-06 08:05:57 +08:00
|
|
|
Streamer.EmitULEB128IntValue(
|
2015-02-27 03:48:07 +08:00
|
|
|
MRI->getDwarfRegNum(MRI->getRARegister(), IsEH));
|
2014-06-19 23:39:33 +08:00
|
|
|
}
|
2010-12-10 15:39:47 +08:00
|
|
|
|
|
|
|
// Augmentation Data Length (optional)
|
2011-04-30 05:50:57 +08:00
|
|
|
|
|
|
|
unsigned augmentationLength = 0;
|
2011-05-10 11:54:12 +08:00
|
|
|
if (IsEH) {
|
|
|
|
if (personality) {
|
|
|
|
// Personality Encoding
|
|
|
|
augmentationLength += 1;
|
|
|
|
// Personality
|
2015-11-06 08:05:57 +08:00
|
|
|
augmentationLength += getSizeForEncoding(Streamer, personalityEncoding);
|
2011-05-10 11:54:12 +08:00
|
|
|
}
|
|
|
|
if (lsda)
|
|
|
|
augmentationLength += 1;
|
|
|
|
// Encoding of the FDE pointers
|
2011-04-30 05:50:57 +08:00
|
|
|
augmentationLength += 1;
|
|
|
|
|
2015-11-06 08:05:57 +08:00
|
|
|
Streamer.EmitULEB128IntValue(augmentationLength);
|
2010-12-10 15:39:47 +08:00
|
|
|
|
2011-05-10 11:54:12 +08:00
|
|
|
// Augmentation Data (optional)
|
|
|
|
if (personality) {
|
|
|
|
// Personality Encoding
|
2015-11-06 08:05:57 +08:00
|
|
|
emitEncodingByte(Streamer, personalityEncoding);
|
2011-05-10 11:54:12 +08:00
|
|
|
// Personality
|
2015-11-06 08:05:57 +08:00
|
|
|
EmitPersonality(Streamer, *personality, personalityEncoding);
|
2011-05-10 11:54:12 +08:00
|
|
|
}
|
2011-07-01 05:25:51 +08:00
|
|
|
|
2011-05-10 11:54:12 +08:00
|
|
|
if (lsda)
|
2015-11-06 08:05:57 +08:00
|
|
|
emitEncodingByte(Streamer, lsdaEncoding);
|
2011-07-01 05:25:51 +08:00
|
|
|
|
2011-05-10 11:54:12 +08:00
|
|
|
// Encoding of the FDE pointers
|
2015-11-06 08:05:57 +08:00
|
|
|
emitEncodingByte(Streamer, MOFI->getFDEEncoding());
|
2010-12-27 23:56:22 +08:00
|
|
|
}
|
2010-12-10 15:39:47 +08:00
|
|
|
|
|
|
|
// Initial Instructions
|
|
|
|
|
2013-06-18 15:20:20 +08:00
|
|
|
const MCAsmInfo *MAI = context.getAsmInfo();
|
2014-01-28 01:20:25 +08:00
|
|
|
if (!IsSimple) {
|
|
|
|
const std::vector<MCCFIInstruction> &Instructions =
|
|
|
|
MAI->getInitialFrameState();
|
2015-11-06 08:05:57 +08:00
|
|
|
EmitCFIInstructions(Instructions, nullptr);
|
2014-01-28 01:20:25 +08:00
|
|
|
}
|
2010-12-10 15:39:47 +08:00
|
|
|
|
2015-03-25 05:47:31 +08:00
|
|
|
InitialCFAOffset = CFAOffset;
|
|
|
|
|
2010-12-10 15:39:47 +08:00
|
|
|
// Padding
|
2015-11-06 08:05:57 +08:00
|
|
|
Streamer.EmitValueToAlignment(IsEH ? 4 : MAI->getPointerSize());
|
2010-12-10 15:39:47 +08:00
|
|
|
|
2015-11-06 08:05:57 +08:00
|
|
|
Streamer.EmitLabel(sectionEnd);
|
2010-12-10 15:39:47 +08:00
|
|
|
return *sectionStart;
|
|
|
|
}
|
|
|
|
|
2015-11-06 11:02:51 +08:00
|
|
|
void FrameEmitterImpl::EmitFDE(const MCSymbol &cieStart,
|
|
|
|
const MCDwarfFrameInfo &frame,
|
2015-11-06 21:14:59 +08:00
|
|
|
bool LastInSection,
|
|
|
|
const MCSymbol &SectionStart) {
|
2015-11-06 08:05:57 +08:00
|
|
|
MCContext &context = Streamer.getContext();
|
2015-05-19 02:43:14 +08:00
|
|
|
MCSymbol *fdeStart = context.createTempSymbol();
|
|
|
|
MCSymbol *fdeEnd = context.createTempSymbol();
|
2011-07-20 13:58:47 +08:00
|
|
|
const MCObjectFileInfo *MOFI = context.getObjectFileInfo();
|
2010-12-10 15:39:47 +08:00
|
|
|
|
2015-03-25 05:47:31 +08:00
|
|
|
CFAOffset = InitialCFAOffset;
|
|
|
|
|
2010-12-10 15:39:47 +08:00
|
|
|
// Length
|
2015-11-06 08:05:57 +08:00
|
|
|
const MCExpr *Length = MakeStartMinusEndExpr(Streamer, *fdeStart, *fdeEnd, 0);
|
|
|
|
emitAbsValue(Streamer, Length, 4);
|
2010-12-10 15:39:47 +08:00
|
|
|
|
2015-11-06 08:05:57 +08:00
|
|
|
Streamer.EmitLabel(fdeStart);
|
2011-05-11 04:59:42 +08:00
|
|
|
|
2010-12-10 15:39:47 +08:00
|
|
|
// CIE Pointer
|
2013-06-18 15:20:20 +08:00
|
|
|
const MCAsmInfo *asmInfo = context.getAsmInfo();
|
2011-05-10 23:20:23 +08:00
|
|
|
if (IsEH) {
|
2015-11-06 08:05:57 +08:00
|
|
|
const MCExpr *offset =
|
|
|
|
MakeStartMinusEndExpr(Streamer, cieStart, *fdeStart, 0);
|
|
|
|
emitAbsValue(Streamer, offset, 4);
|
2013-06-18 15:20:20 +08:00
|
|
|
} else if (!asmInfo->doesDwarfUseRelocationsAcrossSections()) {
|
2015-11-06 08:05:57 +08:00
|
|
|
const MCExpr *offset =
|
2015-11-06 21:14:59 +08:00
|
|
|
MakeStartMinusEndExpr(Streamer, SectionStart, cieStart, 0);
|
2015-11-06 08:05:57 +08:00
|
|
|
emitAbsValue(Streamer, offset, 4);
|
2011-05-10 23:20:23 +08:00
|
|
|
} else {
|
2015-11-06 08:05:57 +08:00
|
|
|
Streamer.EmitSymbolValue(&cieStart, 4);
|
2011-05-10 23:20:23 +08:00
|
|
|
}
|
2011-07-01 06:02:20 +08:00
|
|
|
|
2010-12-10 15:39:47 +08:00
|
|
|
// PC Begin
|
2014-05-12 21:40:49 +08:00
|
|
|
unsigned PCEncoding =
|
2014-05-12 21:47:05 +08:00
|
|
|
IsEH ? MOFI->getFDEEncoding() : (unsigned)dwarf::DW_EH_PE_absptr;
|
2015-11-06 08:05:57 +08:00
|
|
|
unsigned PCSize = getSizeForEncoding(Streamer, PCEncoding);
|
|
|
|
emitFDESymbol(Streamer, *frame.Begin, PCEncoding, IsEH);
|
2010-12-10 15:39:47 +08:00
|
|
|
|
|
|
|
// PC Range
|
2015-11-06 08:05:57 +08:00
|
|
|
const MCExpr *Range =
|
|
|
|
MakeStartMinusEndExpr(Streamer, *frame.Begin, *frame.End, 0);
|
|
|
|
emitAbsValue(Streamer, Range, PCSize);
|
2010-12-10 15:39:47 +08:00
|
|
|
|
2011-05-10 11:54:12 +08:00
|
|
|
if (IsEH) {
|
|
|
|
// Augmentation Data Length
|
|
|
|
unsigned augmentationLength = 0;
|
2011-04-30 05:50:57 +08:00
|
|
|
|
2011-05-10 11:54:12 +08:00
|
|
|
if (frame.Lsda)
|
2015-11-06 08:05:57 +08:00
|
|
|
augmentationLength += getSizeForEncoding(Streamer, frame.LsdaEncoding);
|
2011-04-30 05:50:57 +08:00
|
|
|
|
2015-11-06 08:05:57 +08:00
|
|
|
Streamer.EmitULEB128IntValue(augmentationLength);
|
2010-12-10 15:39:47 +08:00
|
|
|
|
2011-05-10 11:54:12 +08:00
|
|
|
// Augmentation Data
|
|
|
|
if (frame.Lsda)
|
2015-11-06 08:05:57 +08:00
|
|
|
emitFDESymbol(Streamer, *frame.Lsda, frame.LsdaEncoding, true);
|
2011-05-10 11:54:12 +08:00
|
|
|
}
|
2011-04-29 11:06:29 +08:00
|
|
|
|
2010-12-10 15:39:47 +08:00
|
|
|
// Call Frame Instructions
|
2015-11-06 08:05:57 +08:00
|
|
|
EmitCFIInstructions(frame.Instructions, frame.Begin);
|
2010-12-28 12:15:37 +08:00
|
|
|
|
2010-12-10 15:39:47 +08:00
|
|
|
// Padding
|
2015-11-06 11:02:51 +08:00
|
|
|
// The size of a .eh_frame section has to be a multiple of the alignment
|
|
|
|
// since a null CIE is interpreted as the end. Old systems overaligned
|
|
|
|
// .eh_frame, so we do too and account for it in the last FDE.
|
|
|
|
unsigned Align = LastInSection ? asmInfo->getPointerSize() : PCSize;
|
|
|
|
Streamer.EmitValueToAlignment(Align);
|
2010-12-17 08:28:02 +08:00
|
|
|
|
2015-11-06 11:02:51 +08:00
|
|
|
Streamer.EmitLabel(fdeEnd);
|
2010-12-10 15:39:47 +08:00
|
|
|
}
|
|
|
|
|
2010-12-31 06:34:44 +08:00
|
|
|
namespace {
|
2015-11-06 22:12:17 +08:00
|
|
|
struct CIEKey {
|
|
|
|
static const CIEKey getEmptyKey() {
|
|
|
|
return CIEKey(nullptr, 0, -1, false, false);
|
|
|
|
}
|
|
|
|
static const CIEKey getTombstoneKey() {
|
|
|
|
return CIEKey(nullptr, -1, 0, false, false);
|
|
|
|
}
|
2010-12-31 06:34:44 +08:00
|
|
|
|
2015-11-06 22:12:17 +08:00
|
|
|
CIEKey(const MCSymbol *Personality, unsigned PersonalityEncoding,
|
|
|
|
unsigned LsdaEncoding, bool IsSignalFrame, bool IsSimple)
|
|
|
|
: Personality(Personality), PersonalityEncoding(PersonalityEncoding),
|
|
|
|
LsdaEncoding(LsdaEncoding), IsSignalFrame(IsSignalFrame),
|
|
|
|
IsSimple(IsSimple) {}
|
|
|
|
const MCSymbol *Personality;
|
|
|
|
unsigned PersonalityEncoding;
|
|
|
|
unsigned LsdaEncoding;
|
|
|
|
bool IsSignalFrame;
|
|
|
|
bool IsSimple;
|
|
|
|
};
|
2015-10-07 07:24:35 +08:00
|
|
|
} // anonymous namespace
|
2010-12-27 23:56:22 +08:00
|
|
|
|
|
|
|
namespace llvm {
|
2015-11-06 22:12:17 +08:00
|
|
|
template <> struct DenseMapInfo<CIEKey> {
|
|
|
|
static CIEKey getEmptyKey() { return CIEKey::getEmptyKey(); }
|
|
|
|
static CIEKey getTombstoneKey() { return CIEKey::getTombstoneKey(); }
|
|
|
|
static unsigned getHashValue(const CIEKey &Key) {
|
|
|
|
return static_cast<unsigned>(
|
|
|
|
hash_combine(Key.Personality, Key.PersonalityEncoding, Key.LsdaEncoding,
|
|
|
|
Key.IsSignalFrame, Key.IsSimple));
|
|
|
|
}
|
|
|
|
static bool isEqual(const CIEKey &LHS, const CIEKey &RHS) {
|
|
|
|
return LHS.Personality == RHS.Personality &&
|
|
|
|
LHS.PersonalityEncoding == RHS.PersonalityEncoding &&
|
|
|
|
LHS.LsdaEncoding == RHS.LsdaEncoding &&
|
|
|
|
LHS.IsSignalFrame == RHS.IsSignalFrame &&
|
|
|
|
LHS.IsSimple == RHS.IsSimple;
|
|
|
|
}
|
|
|
|
};
|
2015-10-07 07:24:35 +08:00
|
|
|
} // namespace llvm
|
2010-12-27 23:56:22 +08:00
|
|
|
|
2014-05-12 22:28:48 +08:00
|
|
|
void MCDwarfFrameEmitter::Emit(MCObjectStreamer &Streamer, MCAsmBackend *MAB,
|
2014-05-12 21:34:25 +08:00
|
|
|
bool IsEH) {
|
2013-09-10 03:48:37 +08:00
|
|
|
Streamer.generateCompactUnwindEncodings(MAB);
|
|
|
|
|
2011-06-23 15:44:54 +08:00
|
|
|
MCContext &Context = Streamer.getContext();
|
2013-05-31 02:52:57 +08:00
|
|
|
const MCObjectFileInfo *MOFI = Context.getObjectFileInfo();
|
2015-11-06 08:05:57 +08:00
|
|
|
FrameEmitterImpl Emitter(IsEH, Streamer);
|
2014-07-14 03:03:36 +08:00
|
|
|
ArrayRef<MCDwarfFrameInfo> FrameArray = Streamer.getDwarfFrameInfos();
|
2011-07-23 05:18:59 +08:00
|
|
|
|
2011-09-07 02:37:11 +08:00
|
|
|
// Emit the compact unwind info if available.
|
2014-03-29 17:03:13 +08:00
|
|
|
bool NeedsEHFrameSection = !MOFI->getSupportsCompactUnwindWithoutEHFrame();
|
2013-04-24 11:11:14 +08:00
|
|
|
if (IsEH && MOFI->getCompactUnwindSection()) {
|
|
|
|
bool SectionEmitted = false;
|
2013-05-08 04:56:33 +08:00
|
|
|
for (unsigned i = 0, n = FrameArray.size(); i < n; ++i) {
|
|
|
|
const MCDwarfFrameInfo &Frame = FrameArray[i];
|
|
|
|
if (Frame.CompactUnwindEncoding == 0) continue;
|
|
|
|
if (!SectionEmitted) {
|
|
|
|
Streamer.SwitchSection(MOFI->getCompactUnwindSection());
|
2013-06-18 15:20:20 +08:00
|
|
|
Streamer.EmitValueToAlignment(Context.getAsmInfo()->getPointerSize());
|
2013-05-08 04:56:33 +08:00
|
|
|
SectionEmitted = true;
|
2013-04-24 11:11:14 +08:00
|
|
|
}
|
2014-03-29 17:03:13 +08:00
|
|
|
NeedsEHFrameSection |=
|
|
|
|
Frame.CompactUnwindEncoding ==
|
|
|
|
MOFI->getCompactUnwindDwarfEHFrameOnly();
|
2015-11-06 08:05:57 +08:00
|
|
|
Emitter.EmitCompactUnwind(Frame);
|
2011-07-23 05:18:59 +08:00
|
|
|
}
|
2013-04-24 11:11:14 +08:00
|
|
|
}
|
2011-07-23 05:18:59 +08:00
|
|
|
|
2014-03-29 17:03:13 +08:00
|
|
|
if (!NeedsEHFrameSection) return;
|
|
|
|
|
2015-05-22 03:20:38 +08:00
|
|
|
MCSection &Section =
|
|
|
|
IsEH ? *const_cast<MCObjectFileInfo *>(MOFI)->getEHFrameSection()
|
|
|
|
: *MOFI->getDwarfFrameSection();
|
2014-03-29 17:03:13 +08:00
|
|
|
|
2011-06-23 15:44:54 +08:00
|
|
|
Streamer.SwitchSection(&Section);
|
2015-05-19 02:43:14 +08:00
|
|
|
MCSymbol *SectionStart = Context.createTempSymbol();
|
2011-06-23 15:44:54 +08:00
|
|
|
Streamer.EmitLabel(SectionStart);
|
|
|
|
|
2014-06-20 04:00:09 +08:00
|
|
|
DenseMap<CIEKey, const MCSymbol *> CIEStarts;
|
2010-12-27 04:20:31 +08:00
|
|
|
|
2014-04-13 12:57:38 +08:00
|
|
|
const MCSymbol *DummyDebugKey = nullptr;
|
2015-10-29 06:56:36 +08:00
|
|
|
bool CanOmitDwarf = MOFI->getOmitDwarfIfHaveCompactUnwind();
|
2015-11-06 11:02:51 +08:00
|
|
|
for (auto I = FrameArray.begin(), E = FrameArray.end(); I != E;) {
|
|
|
|
const MCDwarfFrameInfo &Frame = *I;
|
|
|
|
++I;
|
2015-10-29 06:56:36 +08:00
|
|
|
if (CanOmitDwarf && Frame.CompactUnwindEncoding !=
|
2014-03-29 17:03:13 +08:00
|
|
|
MOFI->getCompactUnwindDwarfEHFrameOnly())
|
|
|
|
// Don't generate an EH frame if we don't need one. I.e., it's taken care
|
|
|
|
// of by the compact unwind encoding.
|
|
|
|
continue;
|
|
|
|
|
2011-06-23 15:44:54 +08:00
|
|
|
CIEKey Key(Frame.Personality, Frame.PersonalityEncoding,
|
2014-01-28 01:20:25 +08:00
|
|
|
Frame.LsdaEncoding, Frame.IsSignalFrame, Frame.IsSimple);
|
2011-06-23 15:44:54 +08:00
|
|
|
const MCSymbol *&CIEStart = IsEH ? CIEStarts[Key] : DummyDebugKey;
|
|
|
|
if (!CIEStart)
|
2015-11-06 08:05:57 +08:00
|
|
|
CIEStart = &Emitter.EmitCIE(Frame.Personality, Frame.PersonalityEncoding,
|
|
|
|
Frame.Lsda, Frame.IsSignalFrame,
|
|
|
|
Frame.LsdaEncoding, Frame.IsSimple);
|
2011-06-23 09:06:23 +08:00
|
|
|
|
2015-11-06 21:14:59 +08:00
|
|
|
Emitter.EmitFDE(*CIEStart, Frame, I == E, *SectionStart);
|
2010-12-17 08:28:02 +08:00
|
|
|
}
|
2010-12-10 15:39:47 +08:00
|
|
|
}
|
2010-12-28 13:39:27 +08:00
|
|
|
|
2014-05-12 22:28:48 +08:00
|
|
|
void MCDwarfFrameEmitter::EmitAdvanceLoc(MCObjectStreamer &Streamer,
|
2010-12-28 13:39:27 +08:00
|
|
|
uint64_t AddrDelta) {
|
2013-06-12 22:46:54 +08:00
|
|
|
MCContext &Context = Streamer.getContext();
|
2014-06-27 06:52:05 +08:00
|
|
|
SmallString<256> Tmp;
|
|
|
|
raw_svector_ostream OS(Tmp);
|
2013-06-12 22:46:54 +08:00
|
|
|
MCDwarfFrameEmitter::EncodeAdvanceLoc(Context, AddrDelta, OS);
|
2013-01-09 09:57:54 +08:00
|
|
|
Streamer.EmitBytes(OS.str());
|
2010-12-28 13:39:27 +08:00
|
|
|
}
|
|
|
|
|
2013-06-12 22:46:54 +08:00
|
|
|
void MCDwarfFrameEmitter::EncodeAdvanceLoc(MCContext &Context,
|
|
|
|
uint64_t AddrDelta,
|
2011-05-08 22:35:21 +08:00
|
|
|
raw_ostream &OS) {
|
2013-06-12 22:46:54 +08:00
|
|
|
// Scale the address delta by the minimum instruction length.
|
|
|
|
AddrDelta = ScaleAddrDelta(Context, AddrDelta);
|
|
|
|
|
2010-12-29 07:38:03 +08:00
|
|
|
if (AddrDelta == 0) {
|
2011-05-08 22:35:21 +08:00
|
|
|
} else if (isUIntN(6, AddrDelta)) {
|
2010-12-28 13:39:27 +08:00
|
|
|
uint8_t Opcode = dwarf::DW_CFA_advance_loc | AddrDelta;
|
|
|
|
OS << Opcode;
|
2011-05-08 22:35:21 +08:00
|
|
|
} else if (isUInt<8>(AddrDelta)) {
|
2010-12-28 13:39:27 +08:00
|
|
|
OS << uint8_t(dwarf::DW_CFA_advance_loc1);
|
|
|
|
OS << uint8_t(AddrDelta);
|
2011-05-08 22:35:21 +08:00
|
|
|
} else if (isUInt<16>(AddrDelta)) {
|
2010-12-28 13:39:27 +08:00
|
|
|
OS << uint8_t(dwarf::DW_CFA_advance_loc2);
|
2015-06-17 23:14:35 +08:00
|
|
|
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);
|
2010-12-28 13:39:27 +08:00
|
|
|
} else {
|
|
|
|
assert(isUInt<32>(AddrDelta));
|
|
|
|
OS << uint8_t(dwarf::DW_CFA_advance_loc4);
|
2015-06-17 23:14:35 +08:00
|
|
|
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);
|
2010-12-28 13:39:27 +08:00
|
|
|
}
|
|
|
|
}
|