2010-07-29 04:55:35 +08:00
|
|
|
//===- lib/MC/MCDwarf.cpp - MCDwarf implementation ------------------------===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2010-07-29 04:55:35 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-06-06 19:49:48 +08:00
|
|
|
#include "llvm/MC/MCDwarf.h"
|
2017-02-14 08:33:36 +08:00
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/ADT/Hashing.h"
|
2018-02-24 07:01:06 +08:00
|
|
|
#include "llvm/ADT/Optional.h"
|
2017-06-06 19:49:48 +08:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
2017-02-14 08:33:36 +08:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/ADT/Twine.h"
|
2017-06-07 11:48:56 +08:00
|
|
|
#include "llvm/BinaryFormat/Dwarf.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#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"
|
2017-02-14 08:33:36 +08:00
|
|
|
#include "llvm/MC/MCStreamer.h"
|
2010-10-01 00:52:03 +08:00
|
|
|
#include "llvm/MC/MCSymbol.h"
|
2018-02-07 04:29:21 +08:00
|
|
|
#include "llvm/MC/StringTableBuilder.h"
|
2017-02-14 08:33:36 +08:00
|
|
|
#include "llvm/Support/Casting.h"
|
|
|
|
#include "llvm/Support/Endian.h"
|
2016-06-23 07:23:08 +08:00
|
|
|
#include "llvm/Support/EndianStream.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"
|
2017-02-14 08:33:36 +08:00
|
|
|
#include "llvm/Support/MathExtras.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"
|
2017-02-14 08:33:36 +08:00
|
|
|
#include <cassert>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
2015-10-07 07:24:35 +08:00
|
|
|
|
2010-07-29 04:55:35 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
2018-02-07 04:29:21 +08:00
|
|
|
/// Manage the .debug_line_str section contents, if we use it.
|
|
|
|
class llvm::MCDwarfLineStr {
|
|
|
|
MCSymbol *LineStrLabel = nullptr;
|
|
|
|
StringTableBuilder LineStrings{StringTableBuilder::DWARF};
|
|
|
|
bool UseRelocs = false;
|
|
|
|
|
|
|
|
public:
|
|
|
|
/// Construct an instance that can emit .debug_line_str (for use in a normal
|
|
|
|
/// v5 line table).
|
|
|
|
explicit MCDwarfLineStr(MCContext &Ctx) {
|
|
|
|
UseRelocs = Ctx.getAsmInfo()->doesDwarfUseRelocationsAcrossSections();
|
|
|
|
if (UseRelocs)
|
|
|
|
LineStrLabel =
|
|
|
|
Ctx.getObjectFileInfo()->getDwarfLineStrSection()->getBeginSymbol();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Emit a reference to the string.
|
|
|
|
void emitRef(MCStreamer *MCOS, StringRef Path);
|
|
|
|
|
|
|
|
/// Emit the .debug_line_str section if appropriate.
|
|
|
|
void emitSection(MCStreamer *MCOS);
|
|
|
|
};
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-02-07 04:29:21 +08:00
|
|
|
//
|
|
|
|
// This helper routine returns an expression of Start + IntVal .
|
|
|
|
//
|
|
|
|
static inline const MCExpr *
|
|
|
|
makeStartPlusIntExpr(MCContext &Ctx, const MCSymbol &Start, int IntVal) {
|
|
|
|
MCSymbolRefExpr::VariantKind Variant = MCSymbolRefExpr::VK_None;
|
|
|
|
const MCExpr *LHS = MCSymbolRefExpr::create(&Start, Variant, Ctx);
|
|
|
|
const MCExpr *RHS = MCConstantExpr::create(IntVal, Ctx);
|
|
|
|
const MCExpr *Res = MCBinaryExpr::create(MCBinaryExpr::Add, LHS, RHS, Ctx);
|
|
|
|
return Res;
|
|
|
|
}
|
|
|
|
|
2010-10-01 00:52:03 +08:00
|
|
|
//
|
|
|
|
// 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.
|
2016-06-26 22:49:00 +08:00
|
|
|
for (const MCDwarfLineEntry &LineEntry : LineEntries) {
|
|
|
|
int64_t LineDelta = static_cast<int64_t>(LineEntry.getLine()) - LastLine;
|
2010-10-01 00:52:03 +08:00
|
|
|
|
2016-06-26 22:49:00 +08:00
|
|
|
if (FileNum != LineEntry.getFileNum()) {
|
|
|
|
FileNum = LineEntry.getFileNum();
|
2010-10-01 00:52:03 +08:00
|
|
|
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
|
|
|
}
|
2016-06-26 22:49:00 +08:00
|
|
|
if (Column != LineEntry.getColumn()) {
|
|
|
|
Column = LineEntry.getColumn();
|
2010-10-01 00:52:03 +08:00
|
|
|
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
|
|
|
}
|
2016-10-07 23:21:31 +08:00
|
|
|
if (Discriminator != LineEntry.getDiscriminator() &&
|
|
|
|
MCOS->getContext().getDwarfVersion() >= 4) {
|
2016-06-26 22:49:00 +08:00
|
|
|
Discriminator = LineEntry.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);
|
|
|
|
}
|
2016-06-26 22:49:00 +08:00
|
|
|
if (Isa != LineEntry.getIsa()) {
|
|
|
|
Isa = LineEntry.getIsa();
|
2010-10-01 00:52:03 +08:00
|
|
|
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
|
|
|
}
|
2016-06-26 22:49:00 +08:00
|
|
|
if ((LineEntry.getFlags() ^ Flags) & DWARF2_FLAG_IS_STMT) {
|
|
|
|
Flags = LineEntry.getFlags();
|
2010-10-01 00:52:03 +08:00
|
|
|
MCOS->EmitIntValue(dwarf::DW_LNS_negate_stmt, 1);
|
|
|
|
}
|
2016-06-26 22:49:00 +08:00
|
|
|
if (LineEntry.getFlags() & DWARF2_FLAG_BASIC_BLOCK)
|
2010-10-01 00:52:03 +08:00
|
|
|
MCOS->EmitIntValue(dwarf::DW_LNS_set_basic_block, 1);
|
2016-06-26 22:49:00 +08:00
|
|
|
if (LineEntry.getFlags() & DWARF2_FLAG_PROLOGUE_END)
|
2010-10-01 00:52:03 +08:00
|
|
|
MCOS->EmitIntValue(dwarf::DW_LNS_set_prologue_end, 1);
|
2016-06-26 22:49:00 +08:00
|
|
|
if (LineEntry.getFlags() & DWARF2_FLAG_EPILOGUE_BEGIN)
|
2010-10-01 00:52:03 +08:00
|
|
|
MCOS->EmitIntValue(dwarf::DW_LNS_set_epilogue_begin, 1);
|
|
|
|
|
2016-06-26 22:49:00 +08:00
|
|
|
MCSymbol *Label = LineEntry.getLabel();
|
2010-10-01 00:52:03 +08:00
|
|
|
|
|
|
|
// 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,
|
2017-04-18 01:41:25 +08:00
|
|
|
asmInfo->getCodePointerSize());
|
2010-10-01 00:52:03 +08:00
|
|
|
|
2016-04-29 06:09:37 +08:00
|
|
|
Discriminator = 0;
|
2016-06-26 22:49:00 +08:00
|
|
|
LastLine = LineEntry.getLine();
|
2010-10-01 00:52:03 +08:00
|
|
|
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,
|
2017-04-18 01:41:25 +08:00
|
|
|
AsmInfo->getCodePointerSize());
|
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
|
|
|
|
2018-02-07 04:29:21 +08:00
|
|
|
// In a v5 non-split line table, put the strings in a separate section.
|
|
|
|
Optional<MCDwarfLineStr> LineStr;
|
|
|
|
if (context.getDwarfVersion() >= 5)
|
|
|
|
LineStr = MCDwarfLineStr(context);
|
|
|
|
|
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.
|
2018-07-10 22:41:54 +08:00
|
|
|
for (const auto &CUIDTablePair : LineTables) {
|
2018-07-11 20:30:35 +08:00
|
|
|
CUIDTablePair.second.EmitCU(MCOS, Params, LineStr);
|
2018-07-10 22:41:54 +08:00
|
|
|
}
|
2018-02-07 04:29:21 +08:00
|
|
|
|
|
|
|
if (LineStr)
|
|
|
|
LineStr->emitSection(MCOS);
|
2013-02-06 05:52:47 +08:00
|
|
|
}
|
|
|
|
|
2018-03-28 05:28:59 +08:00
|
|
|
void MCDwarfDwoLineTable::Emit(MCStreamer &MCOS, MCDwarfLineTableParams Params,
|
|
|
|
MCSection *Section) const {
|
|
|
|
if (Header.MCDwarfFiles.empty())
|
|
|
|
return;
|
2018-02-07 04:29:21 +08:00
|
|
|
Optional<MCDwarfLineStr> NoLineStr(None);
|
2018-03-28 05:28:59 +08:00
|
|
|
MCOS.SwitchSection(Section);
|
2018-02-07 04:29:21 +08:00
|
|
|
MCOS.EmitLabel(Header.Emit(&MCOS, Params, None, NoLineStr).second);
|
2014-03-18 10:13:23 +08:00
|
|
|
}
|
|
|
|
|
2015-08-07 23:14:08 +08:00
|
|
|
std::pair<MCSymbol *, MCSymbol *>
|
2018-02-07 04:29:21 +08:00
|
|
|
MCDwarfLineTableHeader::Emit(MCStreamer *MCOS, MCDwarfLineTableParams Params,
|
|
|
|
Optional<MCDwarfLineStr> &LineStr) 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));
|
2018-02-07 04:29:21 +08:00
|
|
|
return Emit(
|
|
|
|
MCOS, Params,
|
|
|
|
makeArrayRef(StandardOpcodeLengths, Params.DWARF2LineOpcodeBase - 1),
|
|
|
|
LineStr);
|
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);
|
|
|
|
}
|
|
|
|
|
2018-02-07 04:29:21 +08:00
|
|
|
void MCDwarfLineStr::emitSection(MCStreamer *MCOS) {
|
|
|
|
// Switch to the .debug_line_str section.
|
|
|
|
MCOS->SwitchSection(
|
|
|
|
MCOS->getContext().getObjectFileInfo()->getDwarfLineStrSection());
|
|
|
|
// Emit the strings without perturbing the offsets we used.
|
|
|
|
LineStrings.finalizeInOrder();
|
|
|
|
SmallString<0> Data;
|
|
|
|
Data.resize(LineStrings.getSize());
|
|
|
|
LineStrings.write((uint8_t *)Data.data());
|
|
|
|
MCOS->EmitBinaryData(Data.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
void MCDwarfLineStr::emitRef(MCStreamer *MCOS, StringRef Path) {
|
|
|
|
int RefSize = 4; // FIXME: Support DWARF-64
|
|
|
|
size_t Offset = LineStrings.add(Path);
|
|
|
|
if (UseRelocs) {
|
|
|
|
MCContext &Ctx = MCOS->getContext();
|
|
|
|
MCOS->EmitValue(makeStartPlusIntExpr(Ctx, *LineStrLabel, Offset), RefSize);
|
|
|
|
} else
|
|
|
|
MCOS->EmitIntValue(Offset, RefSize);
|
|
|
|
}
|
|
|
|
|
2018-01-31 05:39:28 +08:00
|
|
|
void MCDwarfLineTableHeader::emitV2FileDirTables(MCStreamer *MCOS) const {
|
2017-12-06 04:35:00 +08:00
|
|
|
// First the directory table.
|
2018-01-31 05:39:28 +08:00
|
|
|
for (auto &Dir : MCDwarfDirs) {
|
2017-12-06 04:35:00 +08:00
|
|
|
MCOS->EmitBytes(Dir); // The DirectoryName, and...
|
|
|
|
MCOS->EmitBytes(StringRef("\0", 1)); // its null terminator.
|
|
|
|
}
|
|
|
|
MCOS->EmitIntValue(0, 1); // Terminate the directory list.
|
|
|
|
|
|
|
|
// Second the file table.
|
|
|
|
for (unsigned i = 1; i < MCDwarfFiles.size(); i++) {
|
|
|
|
assert(!MCDwarfFiles[i].Name.empty());
|
|
|
|
MCOS->EmitBytes(MCDwarfFiles[i].Name); // FileName and...
|
|
|
|
MCOS->EmitBytes(StringRef("\0", 1)); // its null terminator.
|
|
|
|
MCOS->EmitULEB128IntValue(MCDwarfFiles[i].DirIndex); // Directory number.
|
|
|
|
MCOS->EmitIntValue(0, 1); // Last modification timestamp (always 0).
|
|
|
|
MCOS->EmitIntValue(0, 1); // File size (always 0).
|
|
|
|
}
|
|
|
|
MCOS->EmitIntValue(0, 1); // Terminate the file list.
|
|
|
|
}
|
|
|
|
|
2018-03-30 01:16:41 +08:00
|
|
|
static void emitOneV5FileEntry(MCStreamer *MCOS, const MCDwarfFile &DwarfFile,
|
2018-06-14 21:38:20 +08:00
|
|
|
bool EmitMD5, bool HasSource,
|
2018-03-30 01:16:41 +08:00
|
|
|
Optional<MCDwarfLineStr> &LineStr) {
|
|
|
|
assert(!DwarfFile.Name.empty());
|
|
|
|
if (LineStr)
|
|
|
|
LineStr->emitRef(MCOS, DwarfFile.Name);
|
|
|
|
else {
|
|
|
|
MCOS->EmitBytes(DwarfFile.Name); // FileName and...
|
|
|
|
MCOS->EmitBytes(StringRef("\0", 1)); // its null terminator.
|
|
|
|
}
|
|
|
|
MCOS->EmitULEB128IntValue(DwarfFile.DirIndex); // Directory number.
|
2018-06-14 21:38:20 +08:00
|
|
|
if (EmitMD5) {
|
2018-03-30 01:16:41 +08:00
|
|
|
MD5::MD5Result *Cksum = DwarfFile.Checksum;
|
|
|
|
MCOS->EmitBinaryData(
|
|
|
|
StringRef(reinterpret_cast<const char *>(Cksum->Bytes.data()),
|
|
|
|
Cksum->Bytes.size()));
|
|
|
|
}
|
|
|
|
if (HasSource) {
|
|
|
|
if (LineStr)
|
|
|
|
LineStr->emitRef(MCOS, DwarfFile.Source.getValueOr(StringRef()));
|
|
|
|
else {
|
|
|
|
MCOS->EmitBytes(
|
|
|
|
DwarfFile.Source.getValueOr(StringRef())); // Source and...
|
|
|
|
MCOS->EmitBytes(StringRef("\0", 1)); // its null terminator.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-07 04:29:21 +08:00
|
|
|
void MCDwarfLineTableHeader::emitV5FileDirTables(
|
2018-06-13 00:09:03 +08:00
|
|
|
MCStreamer *MCOS, Optional<MCDwarfLineStr> &LineStr,
|
|
|
|
StringRef CtxCompilationDir) const {
|
2018-02-07 04:29:21 +08:00
|
|
|
// The directory format, which is just a list of the directory paths. In a
|
|
|
|
// non-split object, these are references to .debug_line_str; in a split
|
|
|
|
// object, they are inline strings.
|
2017-12-06 04:35:00 +08:00
|
|
|
MCOS->EmitIntValue(1, 1);
|
|
|
|
MCOS->EmitULEB128IntValue(dwarf::DW_LNCT_path);
|
2018-02-07 04:29:21 +08:00
|
|
|
MCOS->EmitULEB128IntValue(LineStr ? dwarf::DW_FORM_line_strp
|
|
|
|
: dwarf::DW_FORM_string);
|
2017-12-06 04:35:00 +08:00
|
|
|
MCOS->EmitULEB128IntValue(MCDwarfDirs.size() + 1);
|
2018-06-13 00:09:03 +08:00
|
|
|
// Try not to emit an empty compilation directory.
|
2018-06-21 01:08:46 +08:00
|
|
|
const StringRef CompDir =
|
|
|
|
CompilationDir.empty() ? CtxCompilationDir : StringRef(CompilationDir);
|
2018-02-07 04:29:21 +08:00
|
|
|
if (LineStr) {
|
|
|
|
// Record path strings, emit references here.
|
2018-06-13 00:09:03 +08:00
|
|
|
LineStr->emitRef(MCOS, CompDir);
|
2018-07-10 22:41:54 +08:00
|
|
|
for (const auto &Dir : MCDwarfDirs)
|
2018-02-07 04:29:21 +08:00
|
|
|
LineStr->emitRef(MCOS, Dir);
|
|
|
|
} else {
|
2018-06-13 00:09:03 +08:00
|
|
|
// The list of directory paths. Compilation directory comes first.
|
|
|
|
MCOS->EmitBytes(CompDir);
|
2018-02-07 04:29:21 +08:00
|
|
|
MCOS->EmitBytes(StringRef("\0", 1));
|
2018-07-10 22:41:54 +08:00
|
|
|
for (const auto &Dir : MCDwarfDirs) {
|
2018-02-07 04:29:21 +08:00
|
|
|
MCOS->EmitBytes(Dir); // The DirectoryName, and...
|
|
|
|
MCOS->EmitBytes(StringRef("\0", 1)); // its null terminator.
|
|
|
|
}
|
2017-12-06 04:35:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// The file format, which is the inline null-terminated filename and a
|
|
|
|
// directory index. We don't track file size/timestamp so don't emit them
|
2018-02-24 07:01:06 +08:00
|
|
|
// in the v5 table. Emit MD5 checksums and source if we have them.
|
|
|
|
uint64_t Entries = 2;
|
2018-06-14 21:38:20 +08:00
|
|
|
if (HasAllMD5)
|
2018-02-24 07:01:06 +08:00
|
|
|
Entries += 1;
|
|
|
|
if (HasSource)
|
|
|
|
Entries += 1;
|
|
|
|
MCOS->EmitIntValue(Entries, 1);
|
2017-12-06 04:35:00 +08:00
|
|
|
MCOS->EmitULEB128IntValue(dwarf::DW_LNCT_path);
|
2018-02-07 04:29:21 +08:00
|
|
|
MCOS->EmitULEB128IntValue(LineStr ? dwarf::DW_FORM_line_strp
|
|
|
|
: dwarf::DW_FORM_string);
|
2017-12-06 04:35:00 +08:00
|
|
|
MCOS->EmitULEB128IntValue(dwarf::DW_LNCT_directory_index);
|
|
|
|
MCOS->EmitULEB128IntValue(dwarf::DW_FORM_udata);
|
2018-06-14 21:38:20 +08:00
|
|
|
if (HasAllMD5) {
|
2018-01-10 07:31:48 +08:00
|
|
|
MCOS->EmitULEB128IntValue(dwarf::DW_LNCT_MD5);
|
|
|
|
MCOS->EmitULEB128IntValue(dwarf::DW_FORM_data16);
|
|
|
|
}
|
2018-02-24 07:01:06 +08:00
|
|
|
if (HasSource) {
|
|
|
|
MCOS->EmitULEB128IntValue(dwarf::DW_LNCT_LLVM_source);
|
|
|
|
MCOS->EmitULEB128IntValue(LineStr ? dwarf::DW_FORM_line_strp
|
|
|
|
: dwarf::DW_FORM_string);
|
|
|
|
}
|
2018-03-30 01:16:41 +08:00
|
|
|
// Then the counted list of files. The root file is file #0, then emit the
|
2018-06-13 00:09:03 +08:00
|
|
|
// files as provide by .file directives. To accommodate assembler source
|
|
|
|
// written for DWARF v4 but trying to emit v5, if we didn't see a root file
|
|
|
|
// explicitly, replicate file #1.
|
2018-03-30 01:16:41 +08:00
|
|
|
MCOS->EmitULEB128IntValue(MCDwarfFiles.size());
|
2018-06-13 00:09:03 +08:00
|
|
|
emitOneV5FileEntry(MCOS, RootFile.Name.empty() ? MCDwarfFiles[1] : RootFile,
|
2018-06-14 21:38:20 +08:00
|
|
|
HasAllMD5, HasSource, LineStr);
|
2018-03-30 01:16:41 +08:00
|
|
|
for (unsigned i = 1; i < MCDwarfFiles.size(); ++i)
|
2018-06-14 21:38:20 +08:00
|
|
|
emitOneV5FileEntry(MCOS, MCDwarfFiles[i], HasAllMD5, HasSource, LineStr);
|
2017-12-06 04:35:00 +08:00
|
|
|
}
|
|
|
|
|
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,
|
2018-02-07 04:29:21 +08:00
|
|
|
ArrayRef<char> StandardOpcodeLengths,
|
|
|
|
Optional<MCDwarfLineStr> &LineStr) 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
|
|
|
|
2018-08-09 05:16:50 +08:00
|
|
|
// Next 2 bytes is the Version.
|
2018-09-13 21:13:50 +08:00
|
|
|
unsigned LineTableVersion = context.getDwarfVersion();
|
2017-12-05 05:27:46 +08:00
|
|
|
MCOS->EmitIntValue(LineTableVersion, 2);
|
2010-10-01 00:52:03 +08:00
|
|
|
|
2017-12-06 04:35:00 +08:00
|
|
|
// Keep track of the bytes between the very start and where the header length
|
|
|
|
// comes out.
|
|
|
|
unsigned PreHeaderLengthBytes = 4 + 2;
|
|
|
|
|
|
|
|
// In v5, we get address info next.
|
|
|
|
if (LineTableVersion >= 5) {
|
|
|
|
MCOS->EmitIntValue(context.getAsmInfo()->getCodePointerSize(), 1);
|
|
|
|
MCOS->EmitIntValue(0, 1); // Segment selector; same as EmitGenDwarfAranges.
|
|
|
|
PreHeaderLengthBytes += 2;
|
|
|
|
}
|
|
|
|
|
2010-10-01 00:52:03 +08:00
|
|
|
// 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
|
|
|
|
2017-12-06 04:35:00 +08:00
|
|
|
// Length of the prologue, is the next 4 bytes. This is actually the length
|
|
|
|
// from after the length word, to the end of the prologue.
|
|
|
|
emitAbsValue(*MCOS,
|
|
|
|
MakeStartMinusEndExpr(*MCOS, *LineStartSym, *ProEndSym,
|
|
|
|
(PreHeaderLengthBytes + 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);
|
2018-07-31 03:41:25 +08:00
|
|
|
// maximum_operations_per_instruction
|
2017-12-05 05:27:46 +08:00
|
|
|
// For non-VLIW architectures this field is always 1.
|
|
|
|
// FIXME: VLIW architectures need to update this field accordingly.
|
2017-12-06 04:35:00 +08:00
|
|
|
if (LineTableVersion >= 4)
|
2017-12-05 05:27:46 +08:00
|
|
|
MCOS->EmitIntValue(1, 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
|
|
|
|
2017-12-06 04:35:00 +08:00
|
|
|
// Put out the directory and file tables. The formats vary depending on
|
|
|
|
// the version.
|
|
|
|
if (LineTableVersion >= 5)
|
2018-06-13 00:09:03 +08:00
|
|
|
emitV5FileDirTables(MCOS, LineStr, context.getCompilationDir());
|
2017-12-06 04:35:00 +08:00
|
|
|
else
|
2018-01-31 05:39:28 +08:00
|
|
|
emitV2FileDirTables(MCOS);
|
2010-10-01 00:52:03 +08:00
|
|
|
|
|
|
|
// 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,
|
2018-02-07 04:29:21 +08:00
|
|
|
MCDwarfLineTableParams Params,
|
|
|
|
Optional<MCDwarfLineStr> &LineStr) const {
|
|
|
|
MCSymbol *LineEndSym = Header.Emit(MCOS, Params, LineStr).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);
|
|
|
|
}
|
|
|
|
|
2018-02-23 05:03:33 +08:00
|
|
|
Expected<unsigned> MCDwarfLineTable::tryGetFile(StringRef &Directory,
|
|
|
|
StringRef &FileName,
|
|
|
|
MD5::MD5Result *Checksum,
|
2018-02-24 07:01:06 +08:00
|
|
|
Optional<StringRef> Source,
|
2018-02-23 05:03:33 +08:00
|
|
|
unsigned FileNumber) {
|
2018-02-24 07:01:06 +08:00
|
|
|
return Header.tryGetFile(Directory, FileName, Checksum, Source, FileNumber);
|
2014-03-14 05:47:12 +08:00
|
|
|
}
|
|
|
|
|
2018-02-24 07:01:06 +08:00
|
|
|
Expected<unsigned>
|
|
|
|
MCDwarfLineTableHeader::tryGetFile(StringRef &Directory,
|
|
|
|
StringRef &FileName,
|
|
|
|
MD5::MD5Result *Checksum,
|
|
|
|
Optional<StringRef> &Source,
|
|
|
|
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());
|
2018-06-14 21:38:20 +08:00
|
|
|
// Keep track of whether any or all files have an MD5 checksum.
|
|
|
|
// If any files have embedded source, they all must.
|
2018-02-24 07:01:06 +08:00
|
|
|
if (MCDwarfFiles.empty()) {
|
2018-06-14 21:38:20 +08:00
|
|
|
trackMD5Usage(Checksum);
|
2018-02-24 07:01:06 +08:00
|
|
|
HasSource = (Source != None);
|
|
|
|
}
|
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.
|
2017-12-15 02:46:43 +08:00
|
|
|
if (FileNumber >= MCDwarfFiles.size())
|
|
|
|
MCDwarfFiles.resize(FileNumber + 1);
|
2014-03-14 03:15:04 +08:00
|
|
|
|
|
|
|
// Get the new MCDwarfFile slot for this FileNumber.
|
|
|
|
MCDwarfFile &File = MCDwarfFiles[FileNumber];
|
|
|
|
|
2018-02-23 05:03:33 +08:00
|
|
|
// It is an error to see the same number more than once.
|
2014-03-14 03:15:04 +08:00
|
|
|
if (!File.Name.empty())
|
2018-02-23 05:03:33 +08:00
|
|
|
return make_error<StringError>("file number already allocated",
|
|
|
|
inconvertibleErrorCode());
|
2014-03-14 03:15:04 +08:00
|
|
|
|
2018-02-24 07:01:06 +08:00
|
|
|
// If any files have embedded source, they all must.
|
|
|
|
if (HasSource != (Source != None))
|
|
|
|
return make_error<StringError>("inconsistent use of embedded source",
|
|
|
|
inconvertibleErrorCode());
|
2018-01-10 07:31:48 +08:00
|
|
|
|
2014-03-14 03:15:04 +08:00
|
|
|
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;
|
2018-01-10 07:31:48 +08:00
|
|
|
File.Checksum = Checksum;
|
2018-06-14 21:38:20 +08:00
|
|
|
trackMD5Usage(Checksum);
|
2018-02-24 07:01:06 +08:00
|
|
|
File.Source = Source;
|
|
|
|
if (Source)
|
|
|
|
HasSource = true;
|
2014-03-14 03:15:04 +08:00
|
|
|
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
2018-08-01 10:18:06 +08:00
|
|
|
bool MCDwarfLineAddr::FixedEncode(MCContext &Context,
|
|
|
|
MCDwarfLineTableParams Params,
|
|
|
|
int64_t LineDelta, uint64_t AddrDelta,
|
|
|
|
raw_ostream &OS,
|
|
|
|
uint32_t *Offset, uint32_t *Size) {
|
|
|
|
if (LineDelta != INT64_MAX) {
|
|
|
|
OS << char(dwarf::DW_LNS_advance_line);
|
|
|
|
encodeSLEB128(LineDelta, OS);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Use address delta to adjust address or use absolute address to adjust
|
|
|
|
// address.
|
|
|
|
bool SetDelta;
|
|
|
|
// According to DWARF spec., the DW_LNS_fixed_advance_pc opcode takes a
|
|
|
|
// single uhalf (unencoded) operand. So, the maximum value of AddrDelta
|
|
|
|
// is 65535. We set a conservative upper bound for it for relaxation.
|
|
|
|
if (AddrDelta > 60000) {
|
|
|
|
const MCAsmInfo *asmInfo = Context.getAsmInfo();
|
|
|
|
unsigned AddrSize = asmInfo->getCodePointerSize();
|
|
|
|
|
|
|
|
OS << char(dwarf::DW_LNS_extended_op);
|
|
|
|
encodeULEB128(1 + AddrSize, OS);
|
|
|
|
OS << char(dwarf::DW_LNE_set_address);
|
|
|
|
// Generate fixup for the address.
|
|
|
|
*Offset = OS.tell();
|
|
|
|
*Size = AddrSize;
|
|
|
|
SetDelta = false;
|
|
|
|
std::vector<uint8_t> FillData;
|
|
|
|
FillData.insert(FillData.begin(), AddrSize, 0);
|
|
|
|
OS.write(reinterpret_cast<char *>(FillData.data()), AddrSize);
|
|
|
|
} else {
|
|
|
|
OS << char(dwarf::DW_LNS_fixed_advance_pc);
|
|
|
|
// Generate fixup for 2-bytes address delta.
|
|
|
|
*Offset = OS.tell();
|
|
|
|
*Size = 2;
|
|
|
|
SetDelta = true;
|
|
|
|
OS << char(0);
|
|
|
|
OS << char(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (LineDelta == INT64_MAX) {
|
|
|
|
OS << char(dwarf::DW_LNS_extended_op);
|
|
|
|
OS << char(1);
|
|
|
|
OS << char(dwarf::DW_LNE_end_sequence);
|
|
|
|
} else {
|
|
|
|
OS << char(dwarf::DW_LNS_copy);
|
|
|
|
}
|
|
|
|
|
|
|
|
return SetDelta;
|
|
|
|
}
|
|
|
|
|
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();
|
2017-04-18 01:41:25 +08:00
|
|
|
int AddrSize = asmInfo->getCodePointerSize();
|
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
|
|
|
|
2017-03-01 07:40:46 +08:00
|
|
|
// The DWARF v5 header has unit type, address size, abbrev offset.
|
|
|
|
// Earlier versions have abbrev offset, address size.
|
2014-07-20 05:01:58 +08:00
|
|
|
const MCAsmInfo &AsmInfo = *context.getAsmInfo();
|
2017-04-18 01:41:25 +08:00
|
|
|
int AddrSize = AsmInfo.getCodePointerSize();
|
2017-03-01 07:40:46 +08:00
|
|
|
if (context.getDwarfVersion() >= 5) {
|
|
|
|
MCOS->EmitIntValue(dwarf::DW_UT_compile, 1);
|
|
|
|
MCOS->EmitIntValue(AddrSize, 1);
|
|
|
|
}
|
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());
|
2017-03-01 07:40:46 +08:00
|
|
|
if (context.getDwarfVersion() <= 4)
|
|
|
|
MCOS->EmitIntValue(AddrSize, 1);
|
2011-12-10 02:09:40 +08:00
|
|
|
|
|
|
|
// 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();
|
2017-04-18 01:41:25 +08:00
|
|
|
int AddrSize = AsmInfo->getCodePointerSize();
|
2014-06-19 23:52:37 +08:00
|
|
|
|
|
|
|
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
|
|
|
|
2017-02-14 08:33:36 +08:00
|
|
|
assert((RangesSectionSymbol != nullptr) || !UseRangesSection);
|
2014-06-19 23:52:37 +08:00
|
|
|
|
|
|
|
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.
|
2016-10-14 13:47:37 +08:00
|
|
|
if (!context.getGenDwarfSectionSyms().count(MCOS->getCurrentSectionOnly()))
|
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:
|
2017-04-18 01:41:25 +08:00
|
|
|
return context.getAsmInfo()->getCodePointerSize();
|
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 {
|
2017-02-14 08:33:36 +08:00
|
|
|
|
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
|
|
|
|
2017-07-30 04:03:02 +08:00
|
|
|
const MCSymbol &EmitCIE(const MCDwarfFrameInfo &F);
|
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) {
|
2017-12-02 05:44:27 +08:00
|
|
|
Reg1 = MRI->getDwarfRegNumFromDwarfEHRegNum(Reg1);
|
|
|
|
Reg2 = MRI->getDwarfRegNumFromDwarfEHRegNum(Reg2);
|
2015-02-27 03:48:07 +08:00
|
|
|
}
|
2012-11-25 23:14:49 +08:00
|
|
|
Streamer.EmitIntValue(dwarf::DW_CFA_register, 1);
|
|
|
|
Streamer.EmitULEB128IntValue(Reg1);
|
|
|
|
Streamer.EmitULEB128IntValue(Reg2);
|
|
|
|
return;
|
|
|
|
}
|
2017-02-14 08:33:36 +08:00
|
|
|
case MCCFIInstruction::OpWindowSave:
|
2013-09-26 22:49:40 +08:00
|
|
|
Streamer.EmitIntValue(dwarf::DW_CFA_GNU_window_save, 1);
|
|
|
|
return;
|
2017-02-14 08:33:36 +08:00
|
|
|
|
2018-12-18 18:37:42 +08:00
|
|
|
case MCCFIInstruction::OpNegateRAState:
|
|
|
|
Streamer.EmitIntValue(dwarf::DW_CFA_AARCH64_negate_ra_state, 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)
|
2017-12-02 05:44:27 +08:00
|
|
|
Reg = MRI->getDwarfRegNumFromDwarfEHRegNum(Reg);
|
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)
|
2017-12-02 05:44:27 +08:00
|
|
|
Reg = MRI->getDwarfRegNumFromDwarfEHRegNum(Reg);
|
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)
|
2017-12-02 05:44:27 +08:00
|
|
|
Reg = MRI->getDwarfRegNumFromDwarfEHRegNum(Reg);
|
2015-02-27 03:48:07 +08:00
|
|
|
|
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)
|
2017-12-02 05:44:27 +08:00
|
|
|
Reg = MRI->getDwarfRegNumFromDwarfEHRegNum(Reg);
|
2018-11-13 18:54:49 +08:00
|
|
|
if (Reg < 64) {
|
|
|
|
Streamer.EmitIntValue(dwarf::DW_CFA_restore | Reg, 1);
|
|
|
|
} else {
|
|
|
|
Streamer.EmitIntValue(dwarf::DW_CFA_restore_extended, 1);
|
|
|
|
Streamer.EmitULEB128IntValue(Reg);
|
|
|
|
}
|
2011-12-30 05:43:03 +08:00
|
|
|
return;
|
|
|
|
}
|
2017-02-14 08:33:36 +08:00
|
|
|
case MCCFIInstruction::OpGnuArgsSize:
|
2015-10-07 15:01:31 +08:00
|
|
|
Streamer.EmitIntValue(dwarf::DW_CFA_GNU_args_size, 1);
|
|
|
|
Streamer.EmitULEB128IntValue(Instr.getOffset());
|
|
|
|
return;
|
2017-02-14 08:33:36 +08:00
|
|
|
|
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) {
|
2016-06-26 22:49:00 +08:00
|
|
|
for (const MCCFIInstruction &Instr : Instrs) {
|
2010-12-29 02:36:23 +08:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
2017-07-30 04:03:02 +08:00
|
|
|
const MCSymbol &FrameEmitterImpl::EmitCIE(const MCDwarfFrameInfo &Frame) {
|
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
|
|
|
|
2011-05-10 11:54:12 +08:00
|
|
|
if (IsEH) {
|
2018-12-21 18:45:08 +08:00
|
|
|
SmallString<8> Augmentation;
|
2011-05-10 11:54:12 +08:00
|
|
|
Augmentation += "z";
|
2017-07-30 04:03:02 +08:00
|
|
|
if (Frame.Personality)
|
2011-05-10 11:54:12 +08:00
|
|
|
Augmentation += "P";
|
2017-07-30 04:03:02 +08:00
|
|
|
if (Frame.Lsda)
|
2011-05-10 11:54:12 +08:00
|
|
|
Augmentation += "L";
|
|
|
|
Augmentation += "R";
|
2017-07-30 04:03:02 +08:00
|
|
|
if (Frame.IsSignalFrame)
|
2012-01-24 05:51:52 +08:00
|
|
|
Augmentation += "S";
|
2018-12-21 18:45:08 +08:00
|
|
|
if (Frame.IsBKeyFrame)
|
|
|
|
Augmentation += "B";
|
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
|
2017-04-18 01:41:25 +08:00
|
|
|
Streamer.EmitIntValue(context.getAsmInfo()->getCodePointerSize(), 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
|
2017-07-30 04:03:02 +08:00
|
|
|
unsigned RAReg = Frame.RAReg;
|
2017-07-28 11:39:19 +08:00
|
|
|
if (RAReg == static_cast<unsigned>(INT_MAX))
|
|
|
|
RAReg = MRI->getDwarfRegNum(MRI->getRARegister(), IsEH);
|
|
|
|
|
2014-06-19 23:39:33 +08:00
|
|
|
if (CIEVersion == 1) {
|
2017-07-28 11:39:19 +08:00
|
|
|
assert(RAReg <= 255 &&
|
2014-06-19 23:39:33 +08:00
|
|
|
"DWARF 2 encodes return_address_register in one byte");
|
2017-07-28 11:39:19 +08:00
|
|
|
Streamer.EmitIntValue(RAReg, 1);
|
2014-06-19 23:39:33 +08:00
|
|
|
} else {
|
2017-07-28 11:39:19 +08:00
|
|
|
Streamer.EmitULEB128IntValue(RAReg);
|
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) {
|
2017-07-30 04:03:02 +08:00
|
|
|
if (Frame.Personality) {
|
2011-05-10 11:54:12 +08:00
|
|
|
// Personality Encoding
|
|
|
|
augmentationLength += 1;
|
|
|
|
// Personality
|
2017-07-30 04:03:02 +08:00
|
|
|
augmentationLength +=
|
|
|
|
getSizeForEncoding(Streamer, Frame.PersonalityEncoding);
|
2011-05-10 11:54:12 +08:00
|
|
|
}
|
2017-07-30 04:03:02 +08:00
|
|
|
if (Frame.Lsda)
|
2011-05-10 11:54:12 +08:00
|
|
|
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)
|
2017-07-30 04:03:02 +08:00
|
|
|
if (Frame.Personality) {
|
2011-05-10 11:54:12 +08:00
|
|
|
// Personality Encoding
|
2017-07-30 04:03:02 +08:00
|
|
|
emitEncodingByte(Streamer, Frame.PersonalityEncoding);
|
2011-05-10 11:54:12 +08:00
|
|
|
// Personality
|
2017-07-30 04:03:02 +08:00
|
|
|
EmitPersonality(Streamer, *Frame.Personality, Frame.PersonalityEncoding);
|
2011-05-10 11:54:12 +08:00
|
|
|
}
|
2011-07-01 05:25:51 +08:00
|
|
|
|
2017-07-30 04:03:02 +08:00
|
|
|
if (Frame.Lsda)
|
|
|
|
emitEncodingByte(Streamer, Frame.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();
|
2017-07-30 04:03:02 +08:00
|
|
|
if (!Frame.IsSimple) {
|
2014-01-28 01:20:25 +08:00
|
|
|
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
|
2017-04-18 01:41:25 +08:00
|
|
|
Streamer.EmitValueToAlignment(IsEH ? 4 : MAI->getCodePointerSize());
|
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.
|
2017-04-18 01:41:25 +08:00
|
|
|
unsigned Align = LastInSection ? asmInfo->getCodePointerSize() : PCSize;
|
2015-11-06 11:02:51 +08:00
|
|
|
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 {
|
2017-02-14 08:33:36 +08:00
|
|
|
|
2015-11-06 22:12:17 +08:00
|
|
|
struct CIEKey {
|
|
|
|
static const CIEKey getEmptyKey() {
|
2018-12-21 18:45:08 +08:00
|
|
|
return CIEKey(nullptr, 0, -1, false, false, static_cast<unsigned>(INT_MAX),
|
|
|
|
false);
|
2015-11-06 22:12:17 +08:00
|
|
|
}
|
2017-02-14 08:33:36 +08:00
|
|
|
|
2015-11-06 22:12:17 +08:00
|
|
|
static const CIEKey getTombstoneKey() {
|
2018-12-21 18:45:08 +08:00
|
|
|
return CIEKey(nullptr, -1, 0, false, false, static_cast<unsigned>(INT_MAX),
|
|
|
|
false);
|
2015-11-06 22:12:17 +08:00
|
|
|
}
|
2010-12-31 06:34:44 +08:00
|
|
|
|
2015-11-06 22:12:17 +08:00
|
|
|
CIEKey(const MCSymbol *Personality, unsigned PersonalityEncoding,
|
2017-07-30 04:03:02 +08:00
|
|
|
unsigned LSDAEncoding, bool IsSignalFrame, bool IsSimple,
|
2018-12-21 18:45:08 +08:00
|
|
|
unsigned RAReg, bool IsBKeyFrame)
|
2015-11-06 22:12:17 +08:00
|
|
|
: Personality(Personality), PersonalityEncoding(PersonalityEncoding),
|
2017-07-30 04:03:02 +08:00
|
|
|
LsdaEncoding(LSDAEncoding), IsSignalFrame(IsSignalFrame),
|
2018-12-21 18:45:08 +08:00
|
|
|
IsSimple(IsSimple), RAReg(RAReg), IsBKeyFrame(IsBKeyFrame) {}
|
2017-02-14 08:33:36 +08:00
|
|
|
|
2017-07-30 04:03:02 +08:00
|
|
|
explicit CIEKey(const MCDwarfFrameInfo &Frame)
|
|
|
|
: Personality(Frame.Personality),
|
|
|
|
PersonalityEncoding(Frame.PersonalityEncoding),
|
|
|
|
LsdaEncoding(Frame.LsdaEncoding), IsSignalFrame(Frame.IsSignalFrame),
|
2018-12-21 18:45:08 +08:00
|
|
|
IsSimple(Frame.IsSimple), RAReg(Frame.RAReg),
|
|
|
|
IsBKeyFrame(Frame.IsBKeyFrame) {}
|
2017-07-30 04:03:02 +08:00
|
|
|
|
2015-11-06 22:12:17 +08:00
|
|
|
const MCSymbol *Personality;
|
|
|
|
unsigned PersonalityEncoding;
|
|
|
|
unsigned LsdaEncoding;
|
|
|
|
bool IsSignalFrame;
|
|
|
|
bool IsSimple;
|
2017-07-30 04:03:00 +08:00
|
|
|
unsigned RAReg;
|
2018-12-21 18:45:08 +08:00
|
|
|
bool IsBKeyFrame;
|
2015-11-06 22:12:17 +08:00
|
|
|
};
|
2017-02-14 08:33:36 +08:00
|
|
|
|
|
|
|
} // end anonymous namespace
|
2010-12-27 23:56:22 +08:00
|
|
|
|
|
|
|
namespace llvm {
|
2017-02-14 08:33:36 +08:00
|
|
|
|
2015-11-06 22:12:17 +08:00
|
|
|
template <> struct DenseMapInfo<CIEKey> {
|
|
|
|
static CIEKey getEmptyKey() { return CIEKey::getEmptyKey(); }
|
|
|
|
static CIEKey getTombstoneKey() { return CIEKey::getTombstoneKey(); }
|
2017-02-14 08:33:36 +08:00
|
|
|
|
2015-11-06 22:12:17 +08:00
|
|
|
static unsigned getHashValue(const CIEKey &Key) {
|
2018-12-21 18:45:08 +08:00
|
|
|
return static_cast<unsigned>(hash_combine(
|
|
|
|
Key.Personality, Key.PersonalityEncoding, Key.LsdaEncoding,
|
|
|
|
Key.IsSignalFrame, Key.IsSimple, Key.RAReg, Key.IsBKeyFrame));
|
2015-11-06 22:12:17 +08:00
|
|
|
}
|
2017-02-14 08:33:36 +08:00
|
|
|
|
2015-11-06 22:12:17 +08:00
|
|
|
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 &&
|
2018-12-21 18:45:08 +08:00
|
|
|
LHS.IsSimple == RHS.IsSimple && LHS.RAReg == RHS.RAReg &&
|
|
|
|
LHS.IsBKeyFrame == RHS.IsBKeyFrame;
|
2015-11-06 22:12:17 +08:00
|
|
|
}
|
|
|
|
};
|
2017-02-14 08:33:36 +08:00
|
|
|
|
|
|
|
} // end 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();
|
2017-04-18 01:41:25 +08:00
|
|
|
const MCAsmInfo *AsmInfo = Context.getAsmInfo();
|
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;
|
2016-06-26 22:49:00 +08:00
|
|
|
for (const MCDwarfFrameInfo &Frame : FrameArray) {
|
2013-05-08 04:56:33 +08:00
|
|
|
if (Frame.CompactUnwindEncoding == 0) continue;
|
|
|
|
if (!SectionEmitted) {
|
|
|
|
Streamer.SwitchSection(MOFI->getCompactUnwindSection());
|
2017-04-18 01:41:25 +08:00
|
|
|
Streamer.EmitValueToAlignment(AsmInfo->getCodePointerSize());
|
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;
|
|
|
|
|
2017-07-30 04:03:02 +08:00
|
|
|
CIEKey Key(Frame);
|
2011-06-23 15:44:54 +08:00
|
|
|
const MCSymbol *&CIEStart = IsEH ? CIEStarts[Key] : DummyDebugKey;
|
|
|
|
if (!CIEStart)
|
2017-07-30 04:03:02 +08:00
|
|
|
CIEStart = &Emitter.EmitCIE(Frame);
|
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);
|
|
|
|
|
2018-05-19 03:46:24 +08:00
|
|
|
support::endianness E =
|
|
|
|
Context.getAsmInfo()->isLittleEndian() ? support::little : support::big;
|
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);
|
2018-05-19 03:46:24 +08:00
|
|
|
support::endian::write<uint16_t>(OS, AddrDelta, E);
|
2010-12-28 13:39:27 +08:00
|
|
|
} else {
|
|
|
|
assert(isUInt<32>(AddrDelta));
|
|
|
|
OS << uint8_t(dwarf::DW_CFA_advance_loc4);
|
2018-05-19 03:46:24 +08:00
|
|
|
support::endian::write<uint32_t>(OS, AddrDelta, E);
|
2010-12-28 13:39:27 +08:00
|
|
|
}
|
|
|
|
}
|