2010-07-28 22:55:35 +02:00
|
|
|
//===- lib/MC/MCDwarf.cpp - MCDwarf implementation ------------------------===//
|
|
|
|
//
|
2019-01-19 09:50:56 +01: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-28 22:55:35 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-06-06 13:49:48 +02:00
|
|
|
#include "llvm/MC/MCDwarf.h"
|
2017-02-14 01:33:36 +01:00
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2012-12-03 17:50:05 +01:00
|
|
|
#include "llvm/ADT/Hashing.h"
|
2018-02-24 00:01:06 +01:00
|
|
|
#include "llvm/ADT/Optional.h"
|
2017-06-06 13:49:48 +02:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2012-12-03 17:50:05 +01:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
2017-02-14 01:33:36 +01:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
2012-12-03 17:50:05 +01:00
|
|
|
#include "llvm/ADT/Twine.h"
|
2017-06-07 05:48:56 +02:00
|
|
|
#include "llvm/BinaryFormat/Dwarf.h"
|
2012-12-03 17:50:05 +01:00
|
|
|
#include "llvm/Config/config.h"
|
2011-07-20 07:58:47 +02:00
|
|
|
#include "llvm/MC/MCAsmInfo.h"
|
|
|
|
#include "llvm/MC/MCContext.h"
|
2012-12-03 17:50:05 +01:00
|
|
|
#include "llvm/MC/MCExpr.h"
|
2011-07-20 07:58:47 +02:00
|
|
|
#include "llvm/MC/MCObjectFileInfo.h"
|
2014-05-12 16:28:48 +02:00
|
|
|
#include "llvm/MC/MCObjectStreamer.h"
|
2011-07-20 07:58:47 +02:00
|
|
|
#include "llvm/MC/MCRegisterInfo.h"
|
2014-06-19 17:52:37 +02:00
|
|
|
#include "llvm/MC/MCSection.h"
|
2017-02-14 01:33:36 +01:00
|
|
|
#include "llvm/MC/MCStreamer.h"
|
2010-09-30 18:52:03 +02:00
|
|
|
#include "llvm/MC/MCSymbol.h"
|
2018-02-06 21:29:21 +01:00
|
|
|
#include "llvm/MC/StringTableBuilder.h"
|
2017-02-14 01:33:36 +01:00
|
|
|
#include "llvm/Support/Casting.h"
|
|
|
|
#include "llvm/Support/Endian.h"
|
2016-06-23 01:23:08 +02:00
|
|
|
#include "llvm/Support/EndianStream.h"
|
2010-12-28 19:36:23 +01:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2012-08-09 01:56:06 +02:00
|
|
|
#include "llvm/Support/LEB128.h"
|
2017-02-14 01:33:36 +01:00
|
|
|
#include "llvm/Support/MathExtras.h"
|
2011-12-09 19:09:40 +01:00
|
|
|
#include "llvm/Support/Path.h"
|
|
|
|
#include "llvm/Support/SourceMgr.h"
|
2012-12-03 17:50:05 +01:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2017-02-14 01:33:36 +01:00
|
|
|
#include <cassert>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
2015-10-07 01:24:35 +02:00
|
|
|
|
2010-07-28 22:55:35 +02:00
|
|
|
using namespace llvm;
|
|
|
|
|
2020-03-03 22:58:02 +01:00
|
|
|
MCSymbol *mcdwarf::emitListsTableHeaderStart(MCStreamer &S) {
|
2020-12-21 23:04:13 +01:00
|
|
|
MCSymbol *Start = S.getContext().createTempSymbol("debug_list_header_start");
|
|
|
|
MCSymbol *End = S.getContext().createTempSymbol("debug_list_header_end");
|
2020-06-03 11:51:51 +02:00
|
|
|
auto DwarfFormat = S.getContext().getDwarfFormat();
|
|
|
|
if (DwarfFormat == dwarf::DWARF64) {
|
|
|
|
S.AddComment("DWARF64 mark");
|
|
|
|
S.emitInt32(dwarf::DW_LENGTH_DWARF64);
|
|
|
|
}
|
2020-03-03 22:58:02 +01:00
|
|
|
S.AddComment("Length");
|
2020-06-03 11:51:51 +02:00
|
|
|
S.emitAbsoluteSymbolDiff(End, Start,
|
|
|
|
dwarf::getDwarfOffsetByteSize(DwarfFormat));
|
2020-03-03 22:58:02 +01:00
|
|
|
S.emitLabel(Start);
|
|
|
|
S.AddComment("Version");
|
|
|
|
S.emitInt16(S.getContext().getDwarfVersion());
|
|
|
|
S.AddComment("Address size");
|
|
|
|
S.emitInt8(S.getContext().getAsmInfo()->getCodePointerSize());
|
|
|
|
S.AddComment("Segment selector size");
|
|
|
|
S.emitInt8(0);
|
|
|
|
return End;
|
2020-02-28 06:57:40 +01:00
|
|
|
}
|
|
|
|
|
2018-02-06 21:29:21 +01: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 16:46:54 +02:00
|
|
|
static inline uint64_t ScaleAddrDelta(MCContext &Context, uint64_t AddrDelta) {
|
2013-06-18 09:20:20 +02:00
|
|
|
unsigned MinInsnLength = Context.getAsmInfo()->getMinInstAlignment();
|
2013-06-12 16:46:54 +02:00
|
|
|
if (MinInsnLength == 1)
|
2010-09-30 18:52:03 +02:00
|
|
|
return AddrDelta;
|
2013-06-12 16:46:54 +02:00
|
|
|
if (AddrDelta % MinInsnLength != 0) {
|
2010-09-30 18:52:03 +02:00
|
|
|
// TODO: report this error, but really only once.
|
|
|
|
;
|
|
|
|
}
|
2013-06-12 16:46:54 +02:00
|
|
|
return AddrDelta / MinInsnLength;
|
2010-09-30 18:52:03 +02: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.
|
|
|
|
//
|
2021-03-05 02:47:41 +01:00
|
|
|
void MCDwarfLineEntry::make(MCStreamer *MCOS, MCSection *Section) {
|
2010-09-30 18:52:03 +02:00
|
|
|
if (!MCOS->getContext().getDwarfLocSeen())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Create a symbol at in the current section for use in the line entry.
|
2015-05-18 20:43:14 +02:00
|
|
|
MCSymbol *LineSym = MCOS->getContext().createTempSymbol();
|
2016-01-21 02:59:03 +01:00
|
|
|
// Set the value of the symbol to use for the MCDwarfLineEntry.
|
2020-02-15 04:21:58 +01:00
|
|
|
MCOS->emitLabel(LineSym);
|
2010-09-30 18:52:03 +02:00
|
|
|
|
|
|
|
// 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 02:59:03 +01:00
|
|
|
MCDwarfLineEntry LineEntry(LineSym, DwarfLoc);
|
2010-09-30 18:52:03 +02:00
|
|
|
|
|
|
|
// clear DwarfLocSeen saying the current .loc info is now used.
|
2015-05-18 20:43:14 +02:00
|
|
|
MCOS->getContext().clearDwarfLocSeen();
|
2010-09-30 18:52:03 +02:00
|
|
|
|
|
|
|
// Add the line entry to this section's entries.
|
2014-03-12 23:28:56 +01:00
|
|
|
MCOS->getContext()
|
2014-03-13 22:59:51 +01:00
|
|
|
.getMCDwarfLineTable(MCOS->getContext().getDwarfCompileUnitID())
|
2014-03-13 18:55:28 +01:00
|
|
|
.getMCLineSections()
|
2014-03-12 23:28:56 +01:00
|
|
|
.addLineEntry(LineEntry, Section);
|
2010-09-30 18:52:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// This helper routine returns an expression of End - Start + IntVal .
|
2012-05-11 03:41:30 +02:00
|
|
|
//
|
2020-06-18 15:15:55 +02:00
|
|
|
static inline const MCExpr *makeEndMinusStartExpr(MCContext &Ctx,
|
2010-12-10 00:08:35 +01:00
|
|
|
const MCSymbol &Start,
|
|
|
|
const MCSymbol &End,
|
|
|
|
int IntVal) {
|
2010-09-30 18:52:03 +02:00
|
|
|
MCSymbolRefExpr::VariantKind Variant = MCSymbolRefExpr::VK_None;
|
2020-05-21 08:05:38 +02:00
|
|
|
const MCExpr *Res = MCSymbolRefExpr::create(&End, Variant, Ctx);
|
|
|
|
const MCExpr *RHS = MCSymbolRefExpr::create(&Start, Variant, Ctx);
|
|
|
|
const MCExpr *Res1 = MCBinaryExpr::create(MCBinaryExpr::Sub, Res, RHS, Ctx);
|
|
|
|
const MCExpr *Res2 = MCConstantExpr::create(IntVal, Ctx);
|
|
|
|
const MCExpr *Res3 = MCBinaryExpr::create(MCBinaryExpr::Sub, Res1, Res2, Ctx);
|
2010-09-30 18:52:03 +02:00
|
|
|
return Res3;
|
|
|
|
}
|
|
|
|
|
2018-02-06 21:29:21 +01: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-09-30 18:52:03 +02:00
|
|
|
//
|
|
|
|
// This emits the Dwarf line table for the specified section from the entries
|
|
|
|
// in the LineSection.
|
|
|
|
//
|
2020-02-13 22:26:21 +01:00
|
|
|
static inline void emitDwarfLineTable(
|
2021-03-05 02:47:41 +01:00
|
|
|
MCStreamer *MCOS, MCSection *Section,
|
2020-02-13 22:26:21 +01:00
|
|
|
const MCLineSection::MCDwarfLineEntryCollection &LineEntries) {
|
2010-09-30 18:52:03 +02: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-14 20:27:53 +01:00
|
|
|
unsigned Discriminator = 0;
|
2014-04-13 06:57:38 +02:00
|
|
|
MCSymbol *LastLabel = nullptr;
|
2010-09-30 18:52:03 +02:00
|
|
|
|
2016-01-21 02:59:03 +01:00
|
|
|
// Loop through each MCDwarfLineEntry and encode the dwarf line number table.
|
2016-06-26 16:49:00 +02:00
|
|
|
for (const MCDwarfLineEntry &LineEntry : LineEntries) {
|
|
|
|
int64_t LineDelta = static_cast<int64_t>(LineEntry.getLine()) - LastLine;
|
2010-09-30 18:52:03 +02:00
|
|
|
|
2016-06-26 16:49:00 +02:00
|
|
|
if (FileNum != LineEntry.getFileNum()) {
|
|
|
|
FileNum = LineEntry.getFileNum();
|
2020-02-29 17:25:22 +01:00
|
|
|
MCOS->emitInt8(dwarf::DW_LNS_set_file);
|
2020-02-13 22:26:21 +01:00
|
|
|
MCOS->emitULEB128IntValue(FileNum);
|
2010-09-30 18:52:03 +02:00
|
|
|
}
|
2016-06-26 16:49:00 +02:00
|
|
|
if (Column != LineEntry.getColumn()) {
|
|
|
|
Column = LineEntry.getColumn();
|
2020-02-29 17:25:22 +01:00
|
|
|
MCOS->emitInt8(dwarf::DW_LNS_set_column);
|
2020-02-13 22:26:21 +01:00
|
|
|
MCOS->emitULEB128IntValue(Column);
|
2010-09-30 18:52:03 +02:00
|
|
|
}
|
2016-10-07 17:21:31 +02:00
|
|
|
if (Discriminator != LineEntry.getDiscriminator() &&
|
|
|
|
MCOS->getContext().getDwarfVersion() >= 4) {
|
2016-06-26 16:49:00 +02:00
|
|
|
Discriminator = LineEntry.getDiscriminator();
|
2014-02-22 15:00:39 +01:00
|
|
|
unsigned Size = getULEB128Size(Discriminator);
|
2020-02-29 17:25:22 +01:00
|
|
|
MCOS->emitInt8(dwarf::DW_LNS_extended_op);
|
2020-02-13 22:26:21 +01:00
|
|
|
MCOS->emitULEB128IntValue(Size + 1);
|
2020-02-29 17:25:22 +01:00
|
|
|
MCOS->emitInt8(dwarf::DW_LNE_set_discriminator);
|
2020-02-13 22:26:21 +01:00
|
|
|
MCOS->emitULEB128IntValue(Discriminator);
|
2014-02-14 20:27:53 +01:00
|
|
|
}
|
2016-06-26 16:49:00 +02:00
|
|
|
if (Isa != LineEntry.getIsa()) {
|
|
|
|
Isa = LineEntry.getIsa();
|
2020-02-29 17:25:22 +01:00
|
|
|
MCOS->emitInt8(dwarf::DW_LNS_set_isa);
|
2020-02-13 22:26:21 +01:00
|
|
|
MCOS->emitULEB128IntValue(Isa);
|
2010-09-30 18:52:03 +02:00
|
|
|
}
|
2016-06-26 16:49:00 +02:00
|
|
|
if ((LineEntry.getFlags() ^ Flags) & DWARF2_FLAG_IS_STMT) {
|
|
|
|
Flags = LineEntry.getFlags();
|
2020-02-29 17:25:22 +01:00
|
|
|
MCOS->emitInt8(dwarf::DW_LNS_negate_stmt);
|
2010-09-30 18:52:03 +02:00
|
|
|
}
|
2016-06-26 16:49:00 +02:00
|
|
|
if (LineEntry.getFlags() & DWARF2_FLAG_BASIC_BLOCK)
|
2020-02-29 17:25:22 +01:00
|
|
|
MCOS->emitInt8(dwarf::DW_LNS_set_basic_block);
|
2016-06-26 16:49:00 +02:00
|
|
|
if (LineEntry.getFlags() & DWARF2_FLAG_PROLOGUE_END)
|
2020-02-29 17:25:22 +01:00
|
|
|
MCOS->emitInt8(dwarf::DW_LNS_set_prologue_end);
|
2016-06-26 16:49:00 +02:00
|
|
|
if (LineEntry.getFlags() & DWARF2_FLAG_EPILOGUE_BEGIN)
|
2020-02-29 17:25:22 +01:00
|
|
|
MCOS->emitInt8(dwarf::DW_LNS_set_epilogue_begin);
|
2010-09-30 18:52:03 +02:00
|
|
|
|
2016-06-26 16:49:00 +02:00
|
|
|
MCSymbol *Label = LineEntry.getLabel();
|
2010-09-30 18:52:03 +02: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 09:20:20 +02:00
|
|
|
const MCAsmInfo *asmInfo = MCOS->getContext().getAsmInfo();
|
2020-02-13 22:26:21 +01:00
|
|
|
MCOS->emitDwarfAdvanceLineAddr(LineDelta, LastLabel, Label,
|
2017-04-17 19:41:25 +02:00
|
|
|
asmInfo->getCodePointerSize());
|
2010-09-30 18:52:03 +02:00
|
|
|
|
2016-04-29 00:09:37 +02:00
|
|
|
Discriminator = 0;
|
2016-06-26 16:49:00 +02:00
|
|
|
LastLine = LineEntry.getLine();
|
2010-09-30 18:52:03 +02:00
|
|
|
LastLabel = Label;
|
|
|
|
}
|
|
|
|
|
2021-03-05 02:47:41 +01:00
|
|
|
// Generate DWARF line end entry.
|
|
|
|
MCOS->emitDwarfLineEndEntry(Section, LastLabel);
|
2010-09-30 18:52:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// This emits the Dwarf file and the line tables.
|
|
|
|
//
|
2021-03-05 02:47:41 +01:00
|
|
|
void MCDwarfLineTable::emit(MCStreamer *MCOS, MCDwarfLineTableParams Params) {
|
2010-12-10 08:39:47 +01:00
|
|
|
MCContext &context = MCOS->getContext();
|
2010-09-30 18:52:03 +02:00
|
|
|
|
2014-04-01 09:35:52 +02: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-13 18:55:28 +01:00
|
|
|
|
2018-02-06 21:29:21 +01: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-13 18:55:28 +01:00
|
|
|
// Switch to the section where the table will be emitted into.
|
|
|
|
MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfLineSection());
|
|
|
|
|
2013-02-05 22:52:47 +01:00
|
|
|
// Handle the rest of the Compile Units.
|
2018-07-10 16:41:54 +02:00
|
|
|
for (const auto &CUIDTablePair : LineTables) {
|
2021-03-05 02:47:41 +01:00
|
|
|
CUIDTablePair.second.emitCU(MCOS, Params, LineStr);
|
2018-07-10 16:41:54 +02:00
|
|
|
}
|
2018-02-06 21:29:21 +01:00
|
|
|
|
|
|
|
if (LineStr)
|
|
|
|
LineStr->emitSection(MCOS);
|
2013-02-05 22:52:47 +01:00
|
|
|
}
|
|
|
|
|
2018-03-27 23:28:59 +02:00
|
|
|
void MCDwarfDwoLineTable::Emit(MCStreamer &MCOS, MCDwarfLineTableParams Params,
|
|
|
|
MCSection *Section) const {
|
[llvm] Prevent duplicate files in debug line header in dwarf 5: another attempt
Another attempt to land the changes in debug line header to prevent duplicate
files in Dwarf 5. I rolled back my previous commit because of a mistake in
generating the object file in a test. Meanwhile, I addressed some offline
comments and changed the implementation; the largest difference is that
MCDwarfLineTableHeader does not keep DwarfVersion but gets it as a parameter. I
also merged the patch to fix two lld tests that will strt to fail into this
patch.
Original Commit:
https://reviews.llvm.org/D59515
Original Message:
Motivation: In previous dwarf versions, file name indexes started from 1, and
the primary source file was not explicit. Dwarf 5 standard (6.2.4) prescribes
the primary source file to be explicitly given an entry with an index number 0.
The current implementation honors the specification by just duplicating the
main source file, once with index number 0, and later maybe with another
index number. While this is compliant with the letter of the standard, the
duplication causes problems for consumers of this information such as lldb.
(Some files are duplicated, where only some of them have a line table although
all refer to the same file)
With this change, dwarf 5 debug line section files always start from 0, and
the zeroth entry is not duplicated whenever possible. This requires different
handling of dwarf 4 and dwarf 5 during generation (e.g. when a function returns
an index zero for a file name, it signals an error in dwarf 4, but not in dwarf
5) However, I think the minor complication is worth it, because it enables all
consumers (lldb, gdb, dwarfdump, objdump, and so on) to treat all files in the
file name list homogenously.
llvm-svn: 358732
2019-04-19 04:26:56 +02:00
|
|
|
if (!HasSplitLineTable)
|
2018-03-27 23:28:59 +02:00
|
|
|
return;
|
2018-02-06 21:29:21 +01:00
|
|
|
Optional<MCDwarfLineStr> NoLineStr(None);
|
2018-03-27 23:28:59 +02:00
|
|
|
MCOS.SwitchSection(Section);
|
2020-02-15 04:21:58 +01:00
|
|
|
MCOS.emitLabel(Header.Emit(&MCOS, Params, None, NoLineStr).second);
|
2014-03-18 03:13:23 +01:00
|
|
|
}
|
|
|
|
|
2015-08-07 17:14:08 +02:00
|
|
|
std::pair<MCSymbol *, MCSymbol *>
|
2018-02-06 21:29:21 +01:00
|
|
|
MCDwarfLineTableHeader::Emit(MCStreamer *MCOS, MCDwarfLineTableParams Params,
|
|
|
|
Optional<MCDwarfLineStr> &LineStr) const {
|
2014-03-18 03:13:23 +01: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 17:14:08 +02:00
|
|
|
assert(array_lengthof(StandardOpcodeLengths) >=
|
2015-08-10 17:22:39 +02:00
|
|
|
(Params.DWARF2LineOpcodeBase - 1U));
|
2018-02-06 21:29:21 +01:00
|
|
|
return Emit(
|
|
|
|
MCOS, Params,
|
|
|
|
makeArrayRef(StandardOpcodeLengths, Params.DWARF2LineOpcodeBase - 1),
|
|
|
|
LineStr);
|
2014-03-18 03:13:23 +01:00
|
|
|
}
|
|
|
|
|
2014-08-15 17:12:13 +02: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-18 20:43:14 +02:00
|
|
|
MCSymbol *ABS = Context.createTempSymbol();
|
2020-02-15 03:16:24 +01:00
|
|
|
OS.emitAssignment(ABS, Expr);
|
2015-05-30 03:25:56 +02:00
|
|
|
return MCSymbolRefExpr::create(ABS, Context);
|
2014-08-15 17:12:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void emitAbsValue(MCStreamer &OS, const MCExpr *Value, unsigned Size) {
|
|
|
|
const MCExpr *ABS = forceExpAbs(OS, Value);
|
2020-02-15 07:40:47 +01:00
|
|
|
OS.emitValue(ABS, Size);
|
2014-08-15 17:12:13 +02:00
|
|
|
}
|
|
|
|
|
2018-02-06 21:29:21 +01: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());
|
2020-02-15 03:16:24 +01:00
|
|
|
MCOS->emitBinaryData(Data.str());
|
2018-02-06 21:29:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void MCDwarfLineStr::emitRef(MCStreamer *MCOS, StringRef Path) {
|
2020-06-03 11:48:37 +02:00
|
|
|
int RefSize =
|
|
|
|
dwarf::getDwarfOffsetByteSize(MCOS->getContext().getDwarfFormat());
|
2018-02-06 21:29:21 +01:00
|
|
|
size_t Offset = LineStrings.add(Path);
|
|
|
|
if (UseRelocs) {
|
|
|
|
MCContext &Ctx = MCOS->getContext();
|
2020-02-15 07:40:47 +01:00
|
|
|
MCOS->emitValue(makeStartPlusIntExpr(Ctx, *LineStrLabel, Offset), RefSize);
|
2018-02-06 21:29:21 +01:00
|
|
|
} else
|
2020-02-15 07:40:47 +01:00
|
|
|
MCOS->emitIntValue(Offset, RefSize);
|
2018-02-06 21:29:21 +01:00
|
|
|
}
|
|
|
|
|
2018-01-30 22:39:28 +01:00
|
|
|
void MCDwarfLineTableHeader::emitV2FileDirTables(MCStreamer *MCOS) const {
|
2017-12-05 21:35:00 +01:00
|
|
|
// First the directory table.
|
2018-01-30 22:39:28 +01:00
|
|
|
for (auto &Dir : MCDwarfDirs) {
|
2020-02-15 03:16:24 +01:00
|
|
|
MCOS->emitBytes(Dir); // The DirectoryName, and...
|
|
|
|
MCOS->emitBytes(StringRef("\0", 1)); // its null terminator.
|
2017-12-05 21:35:00 +01:00
|
|
|
}
|
2020-02-29 17:25:22 +01:00
|
|
|
MCOS->emitInt8(0); // Terminate the directory list.
|
2017-12-05 21:35:00 +01:00
|
|
|
|
|
|
|
// Second the file table.
|
|
|
|
for (unsigned i = 1; i < MCDwarfFiles.size(); i++) {
|
|
|
|
assert(!MCDwarfFiles[i].Name.empty());
|
2020-02-15 03:16:24 +01:00
|
|
|
MCOS->emitBytes(MCDwarfFiles[i].Name); // FileName and...
|
|
|
|
MCOS->emitBytes(StringRef("\0", 1)); // its null terminator.
|
2020-02-13 22:26:21 +01:00
|
|
|
MCOS->emitULEB128IntValue(MCDwarfFiles[i].DirIndex); // Directory number.
|
2020-02-29 17:25:22 +01:00
|
|
|
MCOS->emitInt8(0); // Last modification timestamp (always 0).
|
|
|
|
MCOS->emitInt8(0); // File size (always 0).
|
2017-12-05 21:35:00 +01:00
|
|
|
}
|
2020-02-29 17:25:22 +01:00
|
|
|
MCOS->emitInt8(0); // Terminate the file list.
|
2017-12-05 21:35:00 +01:00
|
|
|
}
|
|
|
|
|
2018-03-29 19:16:41 +02:00
|
|
|
static void emitOneV5FileEntry(MCStreamer *MCOS, const MCDwarfFile &DwarfFile,
|
2018-06-14 15:38:20 +02:00
|
|
|
bool EmitMD5, bool HasSource,
|
2018-03-29 19:16:41 +02:00
|
|
|
Optional<MCDwarfLineStr> &LineStr) {
|
|
|
|
assert(!DwarfFile.Name.empty());
|
|
|
|
if (LineStr)
|
|
|
|
LineStr->emitRef(MCOS, DwarfFile.Name);
|
|
|
|
else {
|
2020-02-15 03:16:24 +01:00
|
|
|
MCOS->emitBytes(DwarfFile.Name); // FileName and...
|
|
|
|
MCOS->emitBytes(StringRef("\0", 1)); // its null terminator.
|
2018-03-29 19:16:41 +02:00
|
|
|
}
|
2020-02-13 22:26:21 +01:00
|
|
|
MCOS->emitULEB128IntValue(DwarfFile.DirIndex); // Directory number.
|
2018-06-14 15:38:20 +02:00
|
|
|
if (EmitMD5) {
|
2019-04-05 01:34:38 +02:00
|
|
|
const MD5::MD5Result &Cksum = *DwarfFile.Checksum;
|
2020-02-15 03:16:24 +01:00
|
|
|
MCOS->emitBinaryData(
|
2019-04-05 01:34:38 +02:00
|
|
|
StringRef(reinterpret_cast<const char *>(Cksum.Bytes.data()),
|
|
|
|
Cksum.Bytes.size()));
|
2018-03-29 19:16:41 +02:00
|
|
|
}
|
|
|
|
if (HasSource) {
|
|
|
|
if (LineStr)
|
|
|
|
LineStr->emitRef(MCOS, DwarfFile.Source.getValueOr(StringRef()));
|
|
|
|
else {
|
2020-02-15 03:16:24 +01:00
|
|
|
MCOS->emitBytes(
|
2018-03-29 19:16:41 +02:00
|
|
|
DwarfFile.Source.getValueOr(StringRef())); // Source and...
|
2020-02-15 03:16:24 +01:00
|
|
|
MCOS->emitBytes(StringRef("\0", 1)); // its null terminator.
|
2018-03-29 19:16:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-06 21:29:21 +01:00
|
|
|
void MCDwarfLineTableHeader::emitV5FileDirTables(
|
2019-04-12 03:02:02 +02:00
|
|
|
MCStreamer *MCOS, Optional<MCDwarfLineStr> &LineStr) const {
|
2018-02-06 21:29:21 +01: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.
|
2020-02-29 17:25:22 +01:00
|
|
|
MCOS->emitInt8(1);
|
2020-02-13 22:26:21 +01:00
|
|
|
MCOS->emitULEB128IntValue(dwarf::DW_LNCT_path);
|
|
|
|
MCOS->emitULEB128IntValue(LineStr ? dwarf::DW_FORM_line_strp
|
2018-02-06 21:29:21 +01:00
|
|
|
: dwarf::DW_FORM_string);
|
2020-02-13 22:26:21 +01:00
|
|
|
MCOS->emitULEB128IntValue(MCDwarfDirs.size() + 1);
|
2018-06-12 18:09:03 +02:00
|
|
|
// Try not to emit an empty compilation directory.
|
2019-04-12 03:02:02 +02:00
|
|
|
const StringRef CompDir = CompilationDir.empty()
|
|
|
|
? MCOS->getContext().getCompilationDir()
|
|
|
|
: StringRef(CompilationDir);
|
2018-02-06 21:29:21 +01:00
|
|
|
if (LineStr) {
|
|
|
|
// Record path strings, emit references here.
|
2018-06-12 18:09:03 +02:00
|
|
|
LineStr->emitRef(MCOS, CompDir);
|
2018-07-10 16:41:54 +02:00
|
|
|
for (const auto &Dir : MCDwarfDirs)
|
2018-02-06 21:29:21 +01:00
|
|
|
LineStr->emitRef(MCOS, Dir);
|
|
|
|
} else {
|
2018-06-12 18:09:03 +02:00
|
|
|
// The list of directory paths. Compilation directory comes first.
|
2020-02-15 03:16:24 +01:00
|
|
|
MCOS->emitBytes(CompDir);
|
|
|
|
MCOS->emitBytes(StringRef("\0", 1));
|
2018-07-10 16:41:54 +02:00
|
|
|
for (const auto &Dir : MCDwarfDirs) {
|
2020-02-15 03:16:24 +01:00
|
|
|
MCOS->emitBytes(Dir); // The DirectoryName, and...
|
|
|
|
MCOS->emitBytes(StringRef("\0", 1)); // its null terminator.
|
2018-02-06 21:29:21 +01:00
|
|
|
}
|
2017-12-05 21:35:00 +01: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 00:01:06 +01:00
|
|
|
// in the v5 table. Emit MD5 checksums and source if we have them.
|
|
|
|
uint64_t Entries = 2;
|
2018-06-14 15:38:20 +02:00
|
|
|
if (HasAllMD5)
|
2018-02-24 00:01:06 +01:00
|
|
|
Entries += 1;
|
|
|
|
if (HasSource)
|
|
|
|
Entries += 1;
|
2020-02-29 17:25:22 +01:00
|
|
|
MCOS->emitInt8(Entries);
|
2020-02-13 22:26:21 +01:00
|
|
|
MCOS->emitULEB128IntValue(dwarf::DW_LNCT_path);
|
|
|
|
MCOS->emitULEB128IntValue(LineStr ? dwarf::DW_FORM_line_strp
|
2018-02-06 21:29:21 +01:00
|
|
|
: dwarf::DW_FORM_string);
|
2020-02-13 22:26:21 +01:00
|
|
|
MCOS->emitULEB128IntValue(dwarf::DW_LNCT_directory_index);
|
|
|
|
MCOS->emitULEB128IntValue(dwarf::DW_FORM_udata);
|
2018-06-14 15:38:20 +02:00
|
|
|
if (HasAllMD5) {
|
2020-02-13 22:26:21 +01:00
|
|
|
MCOS->emitULEB128IntValue(dwarf::DW_LNCT_MD5);
|
|
|
|
MCOS->emitULEB128IntValue(dwarf::DW_FORM_data16);
|
2018-01-10 00:31:48 +01:00
|
|
|
}
|
2018-02-24 00:01:06 +01:00
|
|
|
if (HasSource) {
|
2020-02-13 22:26:21 +01:00
|
|
|
MCOS->emitULEB128IntValue(dwarf::DW_LNCT_LLVM_source);
|
|
|
|
MCOS->emitULEB128IntValue(LineStr ? dwarf::DW_FORM_line_strp
|
2018-02-24 00:01:06 +01:00
|
|
|
: dwarf::DW_FORM_string);
|
|
|
|
}
|
2018-03-29 19:16:41 +02:00
|
|
|
// Then the counted list of files. The root file is file #0, then emit the
|
2019-03-01 21:58:04 +01:00
|
|
|
// files as provide by .file directives.
|
|
|
|
// MCDwarfFiles has an unused element [0] so use size() not size()+1.
|
|
|
|
// But sometimes MCDwarfFiles is empty, in which case we still emit one file.
|
2020-02-13 22:26:21 +01:00
|
|
|
MCOS->emitULEB128IntValue(MCDwarfFiles.empty() ? 1 : MCDwarfFiles.size());
|
2019-03-01 21:58:04 +01:00
|
|
|
// 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.
|
|
|
|
assert((!RootFile.Name.empty() || MCDwarfFiles.size() >= 1) &&
|
|
|
|
"No root file and no .file directives");
|
2018-06-12 18:09:03 +02:00
|
|
|
emitOneV5FileEntry(MCOS, RootFile.Name.empty() ? MCDwarfFiles[1] : RootFile,
|
2018-06-14 15:38:20 +02:00
|
|
|
HasAllMD5, HasSource, LineStr);
|
2018-03-29 19:16:41 +02:00
|
|
|
for (unsigned i = 1; i < MCDwarfFiles.size(); ++i)
|
2018-06-14 15:38:20 +02:00
|
|
|
emitOneV5FileEntry(MCOS, MCDwarfFiles[i], HasAllMD5, HasSource, LineStr);
|
2017-12-05 21:35:00 +01:00
|
|
|
}
|
|
|
|
|
2014-03-18 03:13:23 +01:00
|
|
|
std::pair<MCSymbol *, MCSymbol *>
|
2015-08-07 17:14:08 +02:00
|
|
|
MCDwarfLineTableHeader::Emit(MCStreamer *MCOS, MCDwarfLineTableParams Params,
|
2018-02-06 21:29:21 +01:00
|
|
|
ArrayRef<char> StandardOpcodeLengths,
|
|
|
|
Optional<MCDwarfLineStr> &LineStr) const {
|
2013-02-05 22:52:47 +01:00
|
|
|
MCContext &context = MCOS->getContext();
|
|
|
|
|
|
|
|
// Create a symbol at the beginning of the line table.
|
2014-03-13 18:55:28 +01:00
|
|
|
MCSymbol *LineStartSym = Label;
|
2013-02-05 22:52:47 +01:00
|
|
|
if (!LineStartSym)
|
2015-05-18 20:43:14 +02:00
|
|
|
LineStartSym = context.createTempSymbol();
|
2021-03-05 02:47:41 +01:00
|
|
|
|
2013-02-05 22:52:47 +01:00
|
|
|
// Set the value of the symbol, as we are at the start of the line table.
|
2021-03-05 02:47:41 +01:00
|
|
|
MCOS->emitDwarfLineStartLabel(LineStartSym);
|
2010-09-30 18:52:03 +02:00
|
|
|
|
2020-06-03 11:48:37 +02:00
|
|
|
unsigned OffsetSize = dwarf::getDwarfOffsetByteSize(context.getDwarfFormat());
|
|
|
|
|
2021-02-28 04:33:49 +01:00
|
|
|
MCSymbol *LineEndSym = MCOS->emitDwarfUnitLength("debug_line", "unit length");
|
2010-09-30 18:52:03 +02:00
|
|
|
|
2018-08-08 23:16:50 +02:00
|
|
|
// Next 2 bytes is the Version.
|
2018-09-13 15:13:50 +02:00
|
|
|
unsigned LineTableVersion = context.getDwarfVersion();
|
2020-02-29 17:25:22 +01:00
|
|
|
MCOS->emitInt16(LineTableVersion);
|
2010-09-30 18:52:03 +02:00
|
|
|
|
2017-12-05 21:35:00 +01:00
|
|
|
// In v5, we get address info next.
|
|
|
|
if (LineTableVersion >= 5) {
|
2020-02-29 17:25:22 +01:00
|
|
|
MCOS->emitInt8(context.getAsmInfo()->getCodePointerSize());
|
|
|
|
MCOS->emitInt8(0); // Segment selector; same as EmitGenDwarfAranges.
|
2017-12-05 21:35:00 +01:00
|
|
|
}
|
|
|
|
|
2021-02-28 04:33:49 +01:00
|
|
|
MCSymbol *ProStartSym = context.createTempSymbol();
|
|
|
|
|
2010-09-30 18:52:03 +02:00
|
|
|
// Create a symbol for the end of the prologue (to be set when we get there).
|
2015-05-18 20:43:14 +02:00
|
|
|
MCSymbol *ProEndSym = context.createTempSymbol(); // Lprologue_end
|
2010-09-30 18:52:03 +02:00
|
|
|
|
2020-06-03 11:48:37 +02:00
|
|
|
// Length of the prologue, is the next 4 bytes (8 bytes for DWARF64). This is
|
|
|
|
// actually the length from after the length word, to the end of the prologue.
|
2021-02-28 04:33:49 +01:00
|
|
|
MCOS->emitAbsoluteSymbolDiff(ProEndSym, ProStartSym, OffsetSize);
|
|
|
|
|
|
|
|
MCOS->emitLabel(ProStartSym);
|
2010-09-30 18:52:03 +02:00
|
|
|
|
|
|
|
// Parameters of the state machine, are next.
|
2020-02-29 17:25:22 +01:00
|
|
|
MCOS->emitInt8(context.getAsmInfo()->getMinInstAlignment());
|
2018-07-30 21:41:25 +02:00
|
|
|
// maximum_operations_per_instruction
|
2017-12-04 22:27:46 +01:00
|
|
|
// For non-VLIW architectures this field is always 1.
|
|
|
|
// FIXME: VLIW architectures need to update this field accordingly.
|
2017-12-05 21:35:00 +01:00
|
|
|
if (LineTableVersion >= 4)
|
2020-02-29 17:25:22 +01:00
|
|
|
MCOS->emitInt8(1);
|
|
|
|
MCOS->emitInt8(DWARF2_LINE_DEFAULT_IS_STMT);
|
|
|
|
MCOS->emitInt8(Params.DWARF2LineBase);
|
|
|
|
MCOS->emitInt8(Params.DWARF2LineRange);
|
|
|
|
MCOS->emitInt8(StandardOpcodeLengths.size() + 1);
|
2010-09-30 18:52:03 +02:00
|
|
|
|
|
|
|
// Standard opcode lengths
|
2014-03-18 03:13:23 +01:00
|
|
|
for (char Length : StandardOpcodeLengths)
|
2020-02-29 17:25:22 +01:00
|
|
|
MCOS->emitInt8(Length);
|
2010-09-30 18:52:03 +02:00
|
|
|
|
2017-12-05 21:35:00 +01:00
|
|
|
// Put out the directory and file tables. The formats vary depending on
|
|
|
|
// the version.
|
|
|
|
if (LineTableVersion >= 5)
|
2019-04-12 03:02:02 +02:00
|
|
|
emitV5FileDirTables(MCOS, LineStr);
|
2017-12-05 21:35:00 +01:00
|
|
|
else
|
2018-01-30 22:39:28 +01:00
|
|
|
emitV2FileDirTables(MCOS);
|
2010-09-30 18:52:03 +02: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).
|
2020-02-15 04:21:58 +01:00
|
|
|
MCOS->emitLabel(ProEndSym);
|
2010-09-30 18:52:03 +02:00
|
|
|
|
2014-03-13 22:47:12 +01:00
|
|
|
return std::make_pair(LineStartSym, LineEndSym);
|
|
|
|
}
|
|
|
|
|
2021-03-05 02:47:41 +01:00
|
|
|
void MCDwarfLineTable::emitCU(MCStreamer *MCOS, MCDwarfLineTableParams Params,
|
2018-02-06 21:29:21 +01:00
|
|
|
Optional<MCDwarfLineStr> &LineStr) const {
|
|
|
|
MCSymbol *LineEndSym = Header.Emit(MCOS, Params, LineStr).second;
|
2014-03-13 22:47:12 +01:00
|
|
|
|
2010-09-30 18:52:03 +02:00
|
|
|
// Put out the line tables.
|
2014-03-13 18:55:28 +01:00
|
|
|
for (const auto &LineSec : MCLineSections.getMCLineEntries())
|
2020-02-13 22:26:21 +01:00
|
|
|
emitDwarfLineTable(MCOS, LineSec.first, LineSec.second);
|
2010-09-30 18:52:03 +02: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).
|
2020-02-15 04:21:58 +01:00
|
|
|
MCOS->emitLabel(LineEndSym);
|
2010-09-30 18:52:03 +02:00
|
|
|
}
|
|
|
|
|
2018-02-22 22:03:33 +01:00
|
|
|
Expected<unsigned> MCDwarfLineTable::tryGetFile(StringRef &Directory,
|
|
|
|
StringRef &FileName,
|
2019-04-05 01:34:38 +02:00
|
|
|
Optional<MD5::MD5Result> Checksum,
|
2018-02-24 00:01:06 +01:00
|
|
|
Optional<StringRef> Source,
|
[llvm] Prevent duplicate files in debug line header in dwarf 5: another attempt
Another attempt to land the changes in debug line header to prevent duplicate
files in Dwarf 5. I rolled back my previous commit because of a mistake in
generating the object file in a test. Meanwhile, I addressed some offline
comments and changed the implementation; the largest difference is that
MCDwarfLineTableHeader does not keep DwarfVersion but gets it as a parameter. I
also merged the patch to fix two lld tests that will strt to fail into this
patch.
Original Commit:
https://reviews.llvm.org/D59515
Original Message:
Motivation: In previous dwarf versions, file name indexes started from 1, and
the primary source file was not explicit. Dwarf 5 standard (6.2.4) prescribes
the primary source file to be explicitly given an entry with an index number 0.
The current implementation honors the specification by just duplicating the
main source file, once with index number 0, and later maybe with another
index number. While this is compliant with the letter of the standard, the
duplication causes problems for consumers of this information such as lldb.
(Some files are duplicated, where only some of them have a line table although
all refer to the same file)
With this change, dwarf 5 debug line section files always start from 0, and
the zeroth entry is not duplicated whenever possible. This requires different
handling of dwarf 4 and dwarf 5 during generation (e.g. when a function returns
an index zero for a file name, it signals an error in dwarf 4, but not in dwarf
5) However, I think the minor complication is worth it, because it enables all
consumers (lldb, gdb, dwarfdump, objdump, and so on) to treat all files in the
file name list homogenously.
llvm-svn: 358732
2019-04-19 04:26:56 +02:00
|
|
|
uint16_t DwarfVersion,
|
2018-02-22 22:03:33 +01:00
|
|
|
unsigned FileNumber) {
|
[llvm] Prevent duplicate files in debug line header in dwarf 5: another attempt
Another attempt to land the changes in debug line header to prevent duplicate
files in Dwarf 5. I rolled back my previous commit because of a mistake in
generating the object file in a test. Meanwhile, I addressed some offline
comments and changed the implementation; the largest difference is that
MCDwarfLineTableHeader does not keep DwarfVersion but gets it as a parameter. I
also merged the patch to fix two lld tests that will strt to fail into this
patch.
Original Commit:
https://reviews.llvm.org/D59515
Original Message:
Motivation: In previous dwarf versions, file name indexes started from 1, and
the primary source file was not explicit. Dwarf 5 standard (6.2.4) prescribes
the primary source file to be explicitly given an entry with an index number 0.
The current implementation honors the specification by just duplicating the
main source file, once with index number 0, and later maybe with another
index number. While this is compliant with the letter of the standard, the
duplication causes problems for consumers of this information such as lldb.
(Some files are duplicated, where only some of them have a line table although
all refer to the same file)
With this change, dwarf 5 debug line section files always start from 0, and
the zeroth entry is not duplicated whenever possible. This requires different
handling of dwarf 4 and dwarf 5 during generation (e.g. when a function returns
an index zero for a file name, it signals an error in dwarf 4, but not in dwarf
5) However, I think the minor complication is worth it, because it enables all
consumers (lldb, gdb, dwarfdump, objdump, and so on) to treat all files in the
file name list homogenously.
llvm-svn: 358732
2019-04-19 04:26:56 +02:00
|
|
|
return Header.tryGetFile(Directory, FileName, Checksum, Source, DwarfVersion,
|
|
|
|
FileNumber);
|
|
|
|
}
|
|
|
|
|
2019-08-23 21:59:23 +02:00
|
|
|
static bool isRootFile(const MCDwarfFile &RootFile, StringRef &Directory,
|
|
|
|
StringRef &FileName, Optional<MD5::MD5Result> Checksum) {
|
[llvm] Prevent duplicate files in debug line header in dwarf 5: another attempt
Another attempt to land the changes in debug line header to prevent duplicate
files in Dwarf 5. I rolled back my previous commit because of a mistake in
generating the object file in a test. Meanwhile, I addressed some offline
comments and changed the implementation; the largest difference is that
MCDwarfLineTableHeader does not keep DwarfVersion but gets it as a parameter. I
also merged the patch to fix two lld tests that will strt to fail into this
patch.
Original Commit:
https://reviews.llvm.org/D59515
Original Message:
Motivation: In previous dwarf versions, file name indexes started from 1, and
the primary source file was not explicit. Dwarf 5 standard (6.2.4) prescribes
the primary source file to be explicitly given an entry with an index number 0.
The current implementation honors the specification by just duplicating the
main source file, once with index number 0, and later maybe with another
index number. While this is compliant with the letter of the standard, the
duplication causes problems for consumers of this information such as lldb.
(Some files are duplicated, where only some of them have a line table although
all refer to the same file)
With this change, dwarf 5 debug line section files always start from 0, and
the zeroth entry is not duplicated whenever possible. This requires different
handling of dwarf 4 and dwarf 5 during generation (e.g. when a function returns
an index zero for a file name, it signals an error in dwarf 4, but not in dwarf
5) However, I think the minor complication is worth it, because it enables all
consumers (lldb, gdb, dwarfdump, objdump, and so on) to treat all files in the
file name list homogenously.
llvm-svn: 358732
2019-04-19 04:26:56 +02:00
|
|
|
if (RootFile.Name.empty() || RootFile.Name != FileName.data())
|
|
|
|
return false;
|
|
|
|
return RootFile.Checksum == Checksum;
|
2014-03-13 22:47:12 +01:00
|
|
|
}
|
|
|
|
|
2018-02-24 00:01:06 +01:00
|
|
|
Expected<unsigned>
|
|
|
|
MCDwarfLineTableHeader::tryGetFile(StringRef &Directory,
|
|
|
|
StringRef &FileName,
|
2019-04-05 01:34:38 +02:00
|
|
|
Optional<MD5::MD5Result> Checksum,
|
2019-04-12 05:49:13 +02:00
|
|
|
Optional<StringRef> Source,
|
[llvm] Prevent duplicate files in debug line header in dwarf 5: another attempt
Another attempt to land the changes in debug line header to prevent duplicate
files in Dwarf 5. I rolled back my previous commit because of a mistake in
generating the object file in a test. Meanwhile, I addressed some offline
comments and changed the implementation; the largest difference is that
MCDwarfLineTableHeader does not keep DwarfVersion but gets it as a parameter. I
also merged the patch to fix two lld tests that will strt to fail into this
patch.
Original Commit:
https://reviews.llvm.org/D59515
Original Message:
Motivation: In previous dwarf versions, file name indexes started from 1, and
the primary source file was not explicit. Dwarf 5 standard (6.2.4) prescribes
the primary source file to be explicitly given an entry with an index number 0.
The current implementation honors the specification by just duplicating the
main source file, once with index number 0, and later maybe with another
index number. While this is compliant with the letter of the standard, the
duplication causes problems for consumers of this information such as lldb.
(Some files are duplicated, where only some of them have a line table although
all refer to the same file)
With this change, dwarf 5 debug line section files always start from 0, and
the zeroth entry is not duplicated whenever possible. This requires different
handling of dwarf 4 and dwarf 5 during generation (e.g. when a function returns
an index zero for a file name, it signals an error in dwarf 4, but not in dwarf
5) However, I think the minor complication is worth it, because it enables all
consumers (lldb, gdb, dwarfdump, objdump, and so on) to treat all files in the
file name list homogenously.
llvm-svn: 358732
2019-04-19 04:26:56 +02:00
|
|
|
uint16_t DwarfVersion,
|
2018-02-24 00:01:06 +01:00
|
|
|
unsigned FileNumber) {
|
2014-03-18 00:29:40 +01:00
|
|
|
if (Directory == CompilationDir)
|
|
|
|
Directory = "";
|
2014-03-17 19:13:58 +01:00
|
|
|
if (FileName.empty()) {
|
|
|
|
FileName = "<stdin>";
|
|
|
|
Directory = "";
|
|
|
|
}
|
|
|
|
assert(!FileName.empty());
|
2018-06-14 15:38:20 +02: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 00:01:06 +01:00
|
|
|
if (MCDwarfFiles.empty()) {
|
2019-04-05 01:34:38 +02:00
|
|
|
trackMD5Usage(Checksum.hasValue());
|
2018-02-24 00:01:06 +01:00
|
|
|
HasSource = (Source != None);
|
|
|
|
}
|
[llvm] Prevent duplicate files in debug line header in dwarf 5: another attempt
Another attempt to land the changes in debug line header to prevent duplicate
files in Dwarf 5. I rolled back my previous commit because of a mistake in
generating the object file in a test. Meanwhile, I addressed some offline
comments and changed the implementation; the largest difference is that
MCDwarfLineTableHeader does not keep DwarfVersion but gets it as a parameter. I
also merged the patch to fix two lld tests that will strt to fail into this
patch.
Original Commit:
https://reviews.llvm.org/D59515
Original Message:
Motivation: In previous dwarf versions, file name indexes started from 1, and
the primary source file was not explicit. Dwarf 5 standard (6.2.4) prescribes
the primary source file to be explicitly given an entry with an index number 0.
The current implementation honors the specification by just duplicating the
main source file, once with index number 0, and later maybe with another
index number. While this is compliant with the letter of the standard, the
duplication causes problems for consumers of this information such as lldb.
(Some files are duplicated, where only some of them have a line table although
all refer to the same file)
With this change, dwarf 5 debug line section files always start from 0, and
the zeroth entry is not duplicated whenever possible. This requires different
handling of dwarf 4 and dwarf 5 during generation (e.g. when a function returns
an index zero for a file name, it signals an error in dwarf 4, but not in dwarf
5) However, I think the minor complication is worth it, because it enables all
consumers (lldb, gdb, dwarfdump, objdump, and so on) to treat all files in the
file name list homogenously.
llvm-svn: 358732
2019-04-19 04:26:56 +02:00
|
|
|
if (isRootFile(RootFile, Directory, FileName, Checksum) && DwarfVersion >= 5)
|
|
|
|
return 0;
|
2014-03-17 02:52:11 +01:00
|
|
|
if (FileNumber == 0) {
|
2016-03-09 18:32:56 +01: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-20 21:12:14 +02:00
|
|
|
SmallString<256> Buffer;
|
2014-11-19 06:49:42 +01:00
|
|
|
auto IterBool = SourceIdMap.insert(
|
2015-05-20 21:12:14 +02:00
|
|
|
std::make_pair((Directory + Twine('\0') + FileName).toStringRef(Buffer),
|
|
|
|
FileNumber));
|
2014-11-19 06:49:42 +01:00
|
|
|
if (!IterBool.second)
|
|
|
|
return IterBool.first->second;
|
2014-03-17 02:52:11 +01:00
|
|
|
}
|
2014-03-13 20:15:04 +01:00
|
|
|
// Make space for this FileNumber in the MCDwarfFiles vector if needed.
|
2017-12-14 19:46:43 +01:00
|
|
|
if (FileNumber >= MCDwarfFiles.size())
|
|
|
|
MCDwarfFiles.resize(FileNumber + 1);
|
2014-03-13 20:15:04 +01:00
|
|
|
|
|
|
|
// Get the new MCDwarfFile slot for this FileNumber.
|
|
|
|
MCDwarfFile &File = MCDwarfFiles[FileNumber];
|
|
|
|
|
2018-02-22 22:03:33 +01:00
|
|
|
// It is an error to see the same number more than once.
|
2014-03-13 20:15:04 +01:00
|
|
|
if (!File.Name.empty())
|
2018-02-22 22:03:33 +01:00
|
|
|
return make_error<StringError>("file number already allocated",
|
|
|
|
inconvertibleErrorCode());
|
2014-03-13 20:15:04 +01:00
|
|
|
|
2018-02-24 00:01:06 +01: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 00:31:48 +01:00
|
|
|
|
2014-03-13 20:15:04 +01: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 {
|
2019-04-12 06:55:10 +02:00
|
|
|
DirIndex = llvm::find(MCDwarfDirs, Directory) - MCDwarfDirs.begin();
|
2014-03-13 20:15:04 +01:00
|
|
|
if (DirIndex >= MCDwarfDirs.size())
|
2020-01-28 20:23:46 +01:00
|
|
|
MCDwarfDirs.push_back(std::string(Directory));
|
2014-03-13 20:15:04 +01:00
|
|
|
// 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++;
|
|
|
|
}
|
|
|
|
|
2020-01-28 20:23:46 +01:00
|
|
|
File.Name = std::string(FileName);
|
2014-03-13 20:15:04 +01:00
|
|
|
File.DirIndex = DirIndex;
|
2018-01-10 00:31:48 +01:00
|
|
|
File.Checksum = Checksum;
|
2019-04-05 01:34:38 +02:00
|
|
|
trackMD5Usage(Checksum.hasValue());
|
2018-02-24 00:01:06 +01:00
|
|
|
File.Source = Source;
|
|
|
|
if (Source)
|
|
|
|
HasSource = true;
|
2014-03-13 20:15:04 +01:00
|
|
|
|
|
|
|
// return the allocated FileNumber.
|
|
|
|
return FileNumber;
|
|
|
|
}
|
|
|
|
|
2010-09-30 18:52:03 +02:00
|
|
|
/// Utility function to emit the encoding to a streamer.
|
2015-08-07 17:14:08 +02:00
|
|
|
void MCDwarfLineAddr::Emit(MCStreamer *MCOS, MCDwarfLineTableParams Params,
|
|
|
|
int64_t LineDelta, uint64_t AddrDelta) {
|
2013-06-12 16:46:54 +02:00
|
|
|
MCContext &Context = MCOS->getContext();
|
2014-06-27 00:52:05 +02:00
|
|
|
SmallString<256> Tmp;
|
|
|
|
raw_svector_ostream OS(Tmp);
|
2015-08-07 17:14:08 +02:00
|
|
|
MCDwarfLineAddr::Encode(Context, Params, LineDelta, AddrDelta, OS);
|
2020-02-15 03:16:24 +01:00
|
|
|
MCOS->emitBytes(OS.str());
|
2010-09-30 18:52:03 +02:00
|
|
|
}
|
|
|
|
|
2015-08-07 17:14:08 +02: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-09-30 18:52:03 +02:00
|
|
|
/// Utility function to encode a Dwarf pair of LineDelta and AddrDeltas.
|
2015-08-07 17:14:08 +02:00
|
|
|
void MCDwarfLineAddr::Encode(MCContext &Context, MCDwarfLineTableParams Params,
|
|
|
|
int64_t LineDelta, uint64_t AddrDelta,
|
|
|
|
raw_ostream &OS) {
|
2010-09-30 18:52:03 +02:00
|
|
|
uint64_t Temp, Opcode;
|
|
|
|
bool NeedCopy = false;
|
|
|
|
|
2015-08-07 17:14:08 +02:00
|
|
|
// The maximum address skip amount that can be encoded with a special op.
|
|
|
|
uint64_t MaxSpecialAddrDelta = SpecialAddr(Params, 255);
|
|
|
|
|
2010-09-30 18:52:03 +02:00
|
|
|
// Scale the address delta by the minimum instruction length.
|
2013-06-12 16:46:54 +02:00
|
|
|
AddrDelta = ScaleAddrDelta(Context, AddrDelta);
|
2010-09-30 18:52:03 +02:00
|
|
|
|
|
|
|
// A LineDelta of INT64_MAX is a signal that this is actually a
|
2012-05-11 03:41:30 +02:00
|
|
|
// DW_LNE_end_sequence. We cannot use special opcodes here, since we want the
|
2010-09-30 18:52:03 +02:00
|
|
|
// end_sequence to emit the matrix entry.
|
|
|
|
if (LineDelta == INT64_MAX) {
|
2015-08-07 17:14:08 +02:00
|
|
|
if (AddrDelta == MaxSpecialAddrDelta)
|
2010-09-30 18:52:03 +02:00
|
|
|
OS << char(dwarf::DW_LNS_const_add_pc);
|
2015-03-15 21:45:39 +01:00
|
|
|
else if (AddrDelta) {
|
2010-09-30 18:52:03 +02:00
|
|
|
OS << char(dwarf::DW_LNS_advance_pc);
|
2012-08-09 01:56:06 +02:00
|
|
|
encodeULEB128(AddrDelta, OS);
|
2010-09-30 18:52:03 +02: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 17:14:08 +02:00
|
|
|
Temp = LineDelta - Params.DWARF2LineBase;
|
2010-09-30 18:52:03 +02:00
|
|
|
|
|
|
|
// If the line increment is out of range of a special opcode, we must encode
|
|
|
|
// it with DW_LNS_advance_line.
|
2016-01-31 23:06:35 +01:00
|
|
|
if (Temp >= Params.DWARF2LineRange ||
|
|
|
|
Temp + Params.DWARF2LineOpcodeBase > 255) {
|
2010-09-30 18:52:03 +02:00
|
|
|
OS << char(dwarf::DW_LNS_advance_line);
|
2012-08-09 01:56:06 +02:00
|
|
|
encodeSLEB128(LineDelta, OS);
|
2010-09-30 18:52:03 +02:00
|
|
|
|
|
|
|
LineDelta = 0;
|
2015-08-07 17:14:08 +02:00
|
|
|
Temp = 0 - Params.DWARF2LineBase;
|
2010-09-30 18:52:03 +02: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 17:14:08 +02:00
|
|
|
Temp += Params.DWARF2LineOpcodeBase;
|
2010-09-30 18:52:03 +02:00
|
|
|
|
|
|
|
// Avoid overflow when addr_delta is large.
|
2015-08-07 17:14:08 +02:00
|
|
|
if (AddrDelta < 256 + MaxSpecialAddrDelta) {
|
2010-09-30 18:52:03 +02:00
|
|
|
// Try using a special opcode.
|
2015-08-07 17:14:08 +02:00
|
|
|
Opcode = Temp + AddrDelta * Params.DWARF2LineRange;
|
2010-09-30 18:52:03 +02:00
|
|
|
if (Opcode <= 255) {
|
|
|
|
OS << char(Opcode);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try using DW_LNS_const_add_pc followed by special op.
|
2015-08-07 17:14:08 +02:00
|
|
|
Opcode = Temp + (AddrDelta - MaxSpecialAddrDelta) * Params.DWARF2LineRange;
|
2010-09-30 18:52:03 +02: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 01:56:06 +02:00
|
|
|
encodeULEB128(AddrDelta, OS);
|
2010-09-30 18:52:03 +02:00
|
|
|
|
|
|
|
if (NeedCopy)
|
|
|
|
OS << char(dwarf::DW_LNS_copy);
|
2016-01-31 23:06:35 +01:00
|
|
|
else {
|
|
|
|
assert(Temp <= 255 && "Buggy special opcode encoding.");
|
2010-09-30 18:52:03 +02:00
|
|
|
OS << char(Temp);
|
2016-01-31 23:06:35 +01:00
|
|
|
}
|
2010-09-30 18:52:03 +02:00
|
|
|
}
|
|
|
|
|
2021-01-21 09:55:07 +01:00
|
|
|
std::tuple<uint32_t, uint32_t, bool>
|
|
|
|
MCDwarfLineAddr::fixedEncode(MCContext &Context, int64_t LineDelta,
|
|
|
|
uint64_t AddrDelta, raw_ostream &OS) {
|
|
|
|
uint32_t Offset, Size;
|
2018-08-01 04:18:06 +02:00
|
|
|
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.
|
2021-01-21 09:55:07 +01:00
|
|
|
Offset = OS.tell();
|
|
|
|
Size = AddrSize;
|
2018-08-01 04:18:06 +02:00
|
|
|
SetDelta = false;
|
2019-04-10 11:41:48 +02:00
|
|
|
OS.write_zeros(AddrSize);
|
2018-08-01 04:18:06 +02:00
|
|
|
} else {
|
|
|
|
OS << char(dwarf::DW_LNS_fixed_advance_pc);
|
|
|
|
// Generate fixup for 2-bytes address delta.
|
2021-01-21 09:55:07 +01:00
|
|
|
Offset = OS.tell();
|
|
|
|
Size = 2;
|
2018-08-01 04:18:06 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2021-01-21 14:04:44 +01:00
|
|
|
return std::make_tuple(Offset, Size, SetDelta);
|
2018-08-01 04:18:06 +02:00
|
|
|
}
|
|
|
|
|
2011-12-09 19:09:40 +01:00
|
|
|
// Utility function to write a tuple for .debug_abbrev.
|
|
|
|
static void EmitAbbrev(MCStreamer *MCOS, uint64_t Name, uint64_t Form) {
|
2020-02-13 22:26:21 +01:00
|
|
|
MCOS->emitULEB128IntValue(Name);
|
|
|
|
MCOS->emitULEB128IntValue(Form);
|
2011-12-09 19:09:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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).
|
2020-02-13 22:26:21 +01:00
|
|
|
MCOS->emitULEB128IntValue(1);
|
|
|
|
MCOS->emitULEB128IntValue(dwarf::DW_TAG_compile_unit);
|
2020-02-29 17:25:22 +01:00
|
|
|
MCOS->emitInt8(dwarf::DW_CHILDREN_yes);
|
2020-06-03 11:51:07 +02:00
|
|
|
dwarf::Form SecOffsetForm =
|
|
|
|
context.getDwarfVersion() >= 4
|
|
|
|
? dwarf::DW_FORM_sec_offset
|
|
|
|
: (context.getDwarfFormat() == dwarf::DWARF64 ? dwarf::DW_FORM_data8
|
|
|
|
: dwarf::DW_FORM_data4);
|
|
|
|
EmitAbbrev(MCOS, dwarf::DW_AT_stmt_list, SecOffsetForm);
|
2015-12-23 02:57:31 +01:00
|
|
|
if (context.getGenDwarfSectionSyms().size() > 1 &&
|
|
|
|
context.getDwarfVersion() >= 3) {
|
2020-06-03 11:51:07 +02:00
|
|
|
EmitAbbrev(MCOS, dwarf::DW_AT_ranges, SecOffsetForm);
|
2014-06-19 17:52:37 +02: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-09 19:09:40 +01:00
|
|
|
EmitAbbrev(MCOS, dwarf::DW_AT_name, dwarf::DW_FORM_string);
|
2013-12-10 05:39:09 +01:00
|
|
|
if (!context.getCompilationDir().empty())
|
|
|
|
EmitAbbrev(MCOS, dwarf::DW_AT_comp_dir, dwarf::DW_FORM_string);
|
2011-12-09 19:09:40 +01: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-10 18:52:29 +01:00
|
|
|
// DW_TAG_label DIE abbrev (2).
|
2020-02-13 22:26:21 +01:00
|
|
|
MCOS->emitULEB128IntValue(2);
|
|
|
|
MCOS->emitULEB128IntValue(dwarf::DW_TAG_label);
|
2020-05-25 07:30:59 +02:00
|
|
|
MCOS->emitInt8(dwarf::DW_CHILDREN_no);
|
2011-12-09 19:09:40 +01:00
|
|
|
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, 0, 0);
|
|
|
|
|
|
|
|
// Terminate the abbreviations for this compilation unit.
|
2020-02-29 17:25:22 +01:00
|
|
|
MCOS->emitInt8(0);
|
2011-12-09 19:09:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// When generating dwarf for assembly source files this emits the data for
|
2014-06-19 17:52:37 +02: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 10:55:38 +01:00
|
|
|
static void EmitGenDwarfAranges(MCStreamer *MCOS,
|
|
|
|
const MCSymbol *InfoSectionSymbol) {
|
2011-12-09 19:09:40 +01:00
|
|
|
MCContext &context = MCOS->getContext();
|
|
|
|
|
2014-06-19 17:52:37 +02:00
|
|
|
auto &Sections = context.getGenDwarfSectionSyms();
|
2011-12-09 19:09:40 +01:00
|
|
|
|
|
|
|
MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfARangesSection());
|
|
|
|
|
2020-06-03 11:51:27 +02:00
|
|
|
unsigned UnitLengthBytes =
|
|
|
|
dwarf::getUnitLengthFieldByteSize(context.getDwarfFormat());
|
|
|
|
unsigned OffsetSize = dwarf::getDwarfOffsetByteSize(context.getDwarfFormat());
|
|
|
|
|
2011-12-09 19:09:40 +01:00
|
|
|
// 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).
|
2020-06-03 11:51:27 +02:00
|
|
|
int Length = UnitLengthBytes + 2 + OffsetSize + 1 + 1;
|
2011-12-09 19:09:40 +01:00
|
|
|
|
|
|
|
// Figure the padding after the header before the table of address and size
|
|
|
|
// pairs who's values are PointerSize'ed.
|
2013-06-18 09:20:20 +02:00
|
|
|
const MCAsmInfo *asmInfo = context.getAsmInfo();
|
2017-04-17 19:41:25 +02:00
|
|
|
int AddrSize = asmInfo->getCodePointerSize();
|
2011-12-09 19:09:40 +01: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 17:52:37 +02:00
|
|
|
// of each section we have in the table.
|
|
|
|
Length += 2 * AddrSize * Sections.size();
|
2011-12-09 19:09:40 +01:00
|
|
|
// And the pair of terminating zeros.
|
|
|
|
Length += 2 * AddrSize;
|
|
|
|
|
|
|
|
// Emit the header for this section.
|
2020-06-03 11:51:27 +02:00
|
|
|
if (context.getDwarfFormat() == dwarf::DWARF64)
|
|
|
|
// The DWARF64 mark.
|
|
|
|
MCOS->emitInt32(dwarf::DW_LENGTH_DWARF64);
|
|
|
|
// The 4 (8 for DWARF64) byte length not including the length of the unit
|
|
|
|
// length field itself.
|
|
|
|
MCOS->emitIntValue(Length - UnitLengthBytes, OffsetSize);
|
2011-12-09 19:09:40 +01:00
|
|
|
// The 2 byte version, which is 2.
|
2020-02-29 17:25:22 +01:00
|
|
|
MCOS->emitInt16(2);
|
2020-06-03 11:51:27 +02:00
|
|
|
// The 4 (8 for DWARF64) byte offset to the compile unit in the .debug_info
|
|
|
|
// from the start of the .debug_info.
|
2012-11-14 10:55:38 +01:00
|
|
|
if (InfoSectionSymbol)
|
2020-06-03 11:51:27 +02:00
|
|
|
MCOS->emitSymbolValue(InfoSectionSymbol, OffsetSize,
|
2014-09-06 21:57:48 +02:00
|
|
|
asmInfo->needsDwarfSectionOffsetDirective());
|
2012-11-14 10:55:38 +01:00
|
|
|
else
|
2020-06-03 11:51:27 +02:00
|
|
|
MCOS->emitIntValue(0, OffsetSize);
|
2011-12-09 19:09:40 +01:00
|
|
|
// The 1 byte size of an address.
|
2020-02-29 17:25:22 +01:00
|
|
|
MCOS->emitInt8(AddrSize);
|
2011-12-09 19:09:40 +01:00
|
|
|
// The 1 byte size of a segment descriptor, we use a value of zero.
|
2020-02-29 17:25:22 +01:00
|
|
|
MCOS->emitInt8(0);
|
2011-12-09 19:09:40 +01:00
|
|
|
// Align the header with the padding if needed, before we put out the table.
|
|
|
|
for(int i = 0; i < Pad; i++)
|
2020-02-29 17:25:22 +01:00
|
|
|
MCOS->emitInt8(0);
|
2011-12-09 19:09:40 +01:00
|
|
|
|
2014-06-19 17:52:37 +02:00
|
|
|
// Now emit the table of pairs of PointerSize'ed values for the section
|
|
|
|
// addresses and sizes.
|
2015-05-21 21:20:38 +02:00
|
|
|
for (MCSection *Sec : Sections) {
|
|
|
|
const MCSymbol *StartSymbol = Sec->getBeginSymbol();
|
2015-05-21 18:52:32 +02:00
|
|
|
MCSymbol *EndSymbol = Sec->getEndSymbol(context);
|
2014-06-19 17:52:37 +02:00
|
|
|
assert(StartSymbol && "StartSymbol must not be NULL");
|
|
|
|
assert(EndSymbol && "EndSymbol must not be NULL");
|
|
|
|
|
2015-05-30 03:25:56 +02:00
|
|
|
const MCExpr *Addr = MCSymbolRefExpr::create(
|
2014-06-19 17:52:37 +02:00
|
|
|
StartSymbol, MCSymbolRefExpr::VK_None, context);
|
2020-05-21 08:05:38 +02:00
|
|
|
const MCExpr *Size =
|
2020-06-18 15:15:55 +02:00
|
|
|
makeEndMinusStartExpr(context, *StartSymbol, *EndSymbol, 0);
|
2020-02-15 07:40:47 +01:00
|
|
|
MCOS->emitValue(Addr, AddrSize);
|
2014-08-15 17:12:13 +02:00
|
|
|
emitAbsValue(*MCOS, Size, AddrSize);
|
2014-06-19 17:52:37 +02:00
|
|
|
}
|
2011-12-09 19:09:40 +01:00
|
|
|
|
|
|
|
// And finally the pair of terminating zeros.
|
2020-02-15 07:40:47 +01:00
|
|
|
MCOS->emitIntValue(0, AddrSize);
|
|
|
|
MCOS->emitIntValue(0, AddrSize);
|
2011-12-09 19:09:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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-10 18:52:29 +01:00
|
|
|
// DIE and a list of label DIEs.
|
2012-02-28 22:13:05 +01:00
|
|
|
static void EmitGenDwarfInfo(MCStreamer *MCOS,
|
|
|
|
const MCSymbol *AbbrevSectionSymbol,
|
2014-06-19 17:52:37 +02:00
|
|
|
const MCSymbol *LineSectionSymbol,
|
2020-02-28 06:57:40 +01:00
|
|
|
const MCSymbol *RangesSymbol) {
|
2011-12-09 19:09:40 +01:00
|
|
|
MCContext &context = MCOS->getContext();
|
|
|
|
|
2012-05-11 03:41:30 +02:00
|
|
|
MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfInfoSection());
|
2011-12-09 19:09:40 +01: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-18 20:43:14 +02:00
|
|
|
MCSymbol *InfoStart = context.createTempSymbol();
|
2020-02-15 04:21:58 +01:00
|
|
|
MCOS->emitLabel(InfoStart);
|
2015-05-18 20:43:14 +02:00
|
|
|
MCSymbol *InfoEnd = context.createTempSymbol();
|
2011-12-09 19:09:40 +01:00
|
|
|
|
|
|
|
// First part: the header.
|
|
|
|
|
2020-06-03 16:27:26 +02:00
|
|
|
unsigned UnitLengthBytes =
|
|
|
|
dwarf::getUnitLengthFieldByteSize(context.getDwarfFormat());
|
|
|
|
unsigned OffsetSize = dwarf::getDwarfOffsetByteSize(context.getDwarfFormat());
|
|
|
|
|
|
|
|
if (context.getDwarfFormat() == dwarf::DWARF64)
|
|
|
|
// Emit DWARF64 mark.
|
|
|
|
MCOS->emitInt32(dwarf::DW_LENGTH_DWARF64);
|
|
|
|
|
|
|
|
// The 4 (8 for DWARF64) byte total length of the information for this
|
|
|
|
// compilation unit, not including the unit length field itself.
|
2020-05-21 08:05:38 +02:00
|
|
|
const MCExpr *Length =
|
2020-06-18 15:15:55 +02:00
|
|
|
makeEndMinusStartExpr(context, *InfoStart, *InfoEnd, UnitLengthBytes);
|
2020-06-03 16:27:26 +02:00
|
|
|
emitAbsValue(*MCOS, Length, OffsetSize);
|
2011-12-09 19:09:40 +01:00
|
|
|
|
2014-05-01 10:46:02 +02:00
|
|
|
// The 2 byte DWARF version.
|
2020-02-29 17:25:22 +01:00
|
|
|
MCOS->emitInt16(context.getDwarfVersion());
|
2011-12-09 19:09:40 +01:00
|
|
|
|
2017-03-01 00:40:46 +01:00
|
|
|
// The DWARF v5 header has unit type, address size, abbrev offset.
|
|
|
|
// Earlier versions have abbrev offset, address size.
|
2014-07-19 23:01:58 +02:00
|
|
|
const MCAsmInfo &AsmInfo = *context.getAsmInfo();
|
2017-04-17 19:41:25 +02:00
|
|
|
int AddrSize = AsmInfo.getCodePointerSize();
|
2017-03-01 00:40:46 +01:00
|
|
|
if (context.getDwarfVersion() >= 5) {
|
2020-02-29 17:25:22 +01:00
|
|
|
MCOS->emitInt8(dwarf::DW_UT_compile);
|
|
|
|
MCOS->emitInt8(AddrSize);
|
2017-03-01 00:40:46 +01:00
|
|
|
}
|
2020-06-03 16:27:26 +02:00
|
|
|
// The 4 (8 for DWARF64) byte offset to the debug abbrevs from the start of
|
|
|
|
// the .debug_abbrev.
|
|
|
|
if (AbbrevSectionSymbol)
|
|
|
|
MCOS->emitSymbolValue(AbbrevSectionSymbol, OffsetSize,
|
2014-07-19 23:01:58 +02:00
|
|
|
AsmInfo.needsDwarfSectionOffsetDirective());
|
2020-06-03 16:27:26 +02:00
|
|
|
else
|
|
|
|
// Since the abbrevs are at the start of the section, the offset is zero.
|
|
|
|
MCOS->emitIntValue(0, OffsetSize);
|
2017-03-01 00:40:46 +01:00
|
|
|
if (context.getDwarfVersion() <= 4)
|
2020-02-29 17:25:22 +01:00
|
|
|
MCOS->emitInt8(AddrSize);
|
2011-12-09 19:09:40 +01:00
|
|
|
|
|
|
|
// Second part: the compile_unit DIE.
|
|
|
|
|
|
|
|
// The DW_TAG_compile_unit DIE abbrev (1).
|
2020-02-13 22:26:21 +01:00
|
|
|
MCOS->emitULEB128IntValue(1);
|
2011-12-09 19:09:40 +01:00
|
|
|
|
2020-06-03 16:27:26 +02:00
|
|
|
// DW_AT_stmt_list, a 4 (8 for DWARF64) byte offset from the start of the
|
|
|
|
// .debug_line section.
|
2014-09-05 06:15:00 +02:00
|
|
|
if (LineSectionSymbol)
|
2020-06-03 16:27:26 +02:00
|
|
|
MCOS->emitSymbolValue(LineSectionSymbol, OffsetSize,
|
2014-09-05 06:15:00 +02:00
|
|
|
AsmInfo.needsDwarfSectionOffsetDirective());
|
|
|
|
else
|
2020-06-03 16:27:26 +02:00
|
|
|
// The line table is at the start of the section, so the offset is zero.
|
|
|
|
MCOS->emitIntValue(0, OffsetSize);
|
2011-12-09 19:09:40 +01:00
|
|
|
|
2020-02-28 06:57:40 +01:00
|
|
|
if (RangesSymbol) {
|
|
|
|
// There are multiple sections containing code, so we must use
|
2020-06-03 11:51:51 +02:00
|
|
|
// .debug_ranges/.debug_rnglists. AT_ranges, the 4/8 byte offset from the
|
2020-02-28 06:57:40 +01:00
|
|
|
// start of the .debug_ranges/.debug_rnglists.
|
2020-06-03 11:51:51 +02:00
|
|
|
MCOS->emitSymbolValue(RangesSymbol, OffsetSize);
|
2014-06-19 17:52:37 +02:00
|
|
|
} 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-21 18:52:32 +02:00
|
|
|
MCSymbol *StartSymbol = (*TextSection)->getBeginSymbol();
|
|
|
|
MCSymbol *EndSymbol = (*TextSection)->getEndSymbol(context);
|
2014-06-19 17:52:37 +02: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 03:25:56 +02:00
|
|
|
const MCExpr *Start = MCSymbolRefExpr::create(
|
2014-06-19 17:52:37 +02:00
|
|
|
StartSymbol, MCSymbolRefExpr::VK_None, context);
|
2020-02-15 07:40:47 +01:00
|
|
|
MCOS->emitValue(Start, AddrSize);
|
2014-06-19 17:52:37 +02:00
|
|
|
|
|
|
|
// AT_high_pc, the last address of the default .text section.
|
2015-05-30 03:25:56 +02:00
|
|
|
const MCExpr *End = MCSymbolRefExpr::create(
|
2014-06-19 17:52:37 +02:00
|
|
|
EndSymbol, MCSymbolRefExpr::VK_None, context);
|
2020-02-15 07:40:47 +01:00
|
|
|
MCOS->emitValue(End, AddrSize);
|
2014-06-19 17:52:37 +02:00
|
|
|
}
|
2011-12-09 19:09:40 +01:00
|
|
|
|
|
|
|
// AT_name, the name of the source file. Reconstruct from the first directory
|
|
|
|
// and file table entries.
|
2014-03-13 20:05:33 +01:00
|
|
|
const SmallVectorImpl<std::string> &MCDwarfDirs = context.getMCDwarfDirs();
|
2011-12-09 19:09:40 +01:00
|
|
|
if (MCDwarfDirs.size() > 0) {
|
2020-02-15 03:16:24 +01:00
|
|
|
MCOS->emitBytes(MCDwarfDirs[0]);
|
|
|
|
MCOS->emitBytes(sys::path::get_separator());
|
2011-12-09 19:09:40 +01:00
|
|
|
}
|
2019-03-01 21:58:04 +01:00
|
|
|
const SmallVectorImpl<MCDwarfFile> &MCDwarfFiles = context.getMCDwarfFiles();
|
|
|
|
// MCDwarfFiles might be empty if we have an empty source file.
|
|
|
|
// If it's not empty, [0] is unused and [1] is the first actual file.
|
|
|
|
assert(MCDwarfFiles.empty() || MCDwarfFiles.size() >= 2);
|
|
|
|
const MCDwarfFile &RootFile =
|
|
|
|
MCDwarfFiles.empty()
|
|
|
|
? context.getMCDwarfLineTable(/*CUID=*/0).getRootFile()
|
|
|
|
: MCDwarfFiles[1];
|
2020-02-15 03:16:24 +01:00
|
|
|
MCOS->emitBytes(RootFile.Name);
|
2020-02-29 17:25:22 +01:00
|
|
|
MCOS->emitInt8(0); // NULL byte to terminate the string.
|
2011-12-09 19:09:40 +01:00
|
|
|
|
|
|
|
// AT_comp_dir, the working directory the assembly was done in.
|
2013-12-10 05:39:09 +01:00
|
|
|
if (!context.getCompilationDir().empty()) {
|
2020-02-15 03:16:24 +01:00
|
|
|
MCOS->emitBytes(context.getCompilationDir());
|
2020-02-29 17:25:22 +01:00
|
|
|
MCOS->emitInt8(0); // NULL byte to terminate the string.
|
2013-12-10 05:39:09 +01:00
|
|
|
}
|
2011-12-09 19:09:40 +01:00
|
|
|
|
|
|
|
// AT_APPLE_flags, the command line arguments of the assembler tool.
|
|
|
|
StringRef DwarfDebugFlags = context.getDwarfDebugFlags();
|
|
|
|
if (!DwarfDebugFlags.empty()){
|
2020-02-15 03:16:24 +01:00
|
|
|
MCOS->emitBytes(DwarfDebugFlags);
|
2020-02-29 17:25:22 +01:00
|
|
|
MCOS->emitInt8(0); // NULL byte to terminate the string.
|
2011-12-09 19:09:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// AT_producer, the version of the assembler tool.
|
2013-01-16 18:46:23 +01:00
|
|
|
StringRef DwarfDebugProducer = context.getDwarfDebugProducer();
|
2014-07-17 18:27:35 +02:00
|
|
|
if (!DwarfDebugProducer.empty())
|
2020-02-15 03:16:24 +01:00
|
|
|
MCOS->emitBytes(DwarfDebugProducer);
|
2014-07-17 18:27:35 +02:00
|
|
|
else
|
2020-02-15 03:16:24 +01:00
|
|
|
MCOS->emitBytes(StringRef("llvm-mc (based on LLVM " PACKAGE_VERSION ")"));
|
2020-02-29 17:25:22 +01:00
|
|
|
MCOS->emitInt8(0); // NULL byte to terminate the string.
|
2011-12-09 19:09:40 +01:00
|
|
|
|
|
|
|
// AT_language, a 4 byte value. We use DW_LANG_Mips_Assembler as the dwarf2
|
|
|
|
// draft has no standard code for assembler.
|
2020-02-29 17:25:22 +01:00
|
|
|
MCOS->emitInt16(dwarf::DW_LANG_Mips_Assembler);
|
2011-12-09 19:09:40 +01:00
|
|
|
|
2012-01-10 18:52:29 +01:00
|
|
|
// Third part: the list of label DIEs.
|
2011-12-09 19:09:40 +01:00
|
|
|
|
2012-01-10 22:12:34 +01:00
|
|
|
// Loop on saved info for dwarf labels and create the DIEs for them.
|
2014-04-11 02:43:52 +02:00
|
|
|
const std::vector<MCGenDwarfLabelEntry> &Entries =
|
|
|
|
MCOS->getContext().getMCGenDwarfLabelEntries();
|
|
|
|
for (const auto &Entry : Entries) {
|
2012-01-10 18:52:29 +01:00
|
|
|
// The DW_TAG_label DIE abbrev (2).
|
2020-02-13 22:26:21 +01:00
|
|
|
MCOS->emitULEB128IntValue(2);
|
2011-12-09 19:09:40 +01:00
|
|
|
|
|
|
|
// AT_name, of the label without any leading underbar.
|
2020-02-15 03:16:24 +01:00
|
|
|
MCOS->emitBytes(Entry.getName());
|
2020-02-29 17:25:22 +01:00
|
|
|
MCOS->emitInt8(0); // NULL byte to terminate the string.
|
2011-12-09 19:09:40 +01:00
|
|
|
|
|
|
|
// AT_decl_file, index into the file table.
|
2020-02-29 17:25:22 +01:00
|
|
|
MCOS->emitInt32(Entry.getFileNumber());
|
2011-12-09 19:09:40 +01:00
|
|
|
|
|
|
|
// AT_decl_line, source line number.
|
2020-02-29 17:25:22 +01:00
|
|
|
MCOS->emitInt32(Entry.getLineNumber());
|
2011-12-09 19:09:40 +01:00
|
|
|
|
|
|
|
// AT_low_pc, start address of the label.
|
2015-05-30 03:25:56 +02:00
|
|
|
const MCExpr *AT_low_pc = MCSymbolRefExpr::create(Entry.getLabel(),
|
2011-12-09 19:09:40 +01:00
|
|
|
MCSymbolRefExpr::VK_None, context);
|
2020-02-15 07:40:47 +01:00
|
|
|
MCOS->emitValue(AT_low_pc, AddrSize);
|
2011-12-09 19:09:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add the NULL DIE terminating the Compile Unit DIE's.
|
2020-02-29 17:25:22 +01:00
|
|
|
MCOS->emitInt8(0);
|
2011-12-09 19:09:40 +01:00
|
|
|
|
|
|
|
// Now set the value of the symbol at the end of the info section.
|
2020-02-15 04:21:58 +01:00
|
|
|
MCOS->emitLabel(InfoEnd);
|
2011-12-09 19:09:40 +01:00
|
|
|
}
|
|
|
|
|
2014-06-19 17:52:37 +02: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.
|
2020-02-28 06:57:40 +01:00
|
|
|
static MCSymbol *emitGenDwarfRanges(MCStreamer *MCOS) {
|
2014-06-19 17:52:37 +02:00
|
|
|
MCContext &context = MCOS->getContext();
|
|
|
|
auto &Sections = context.getGenDwarfSectionSyms();
|
|
|
|
|
|
|
|
const MCAsmInfo *AsmInfo = context.getAsmInfo();
|
2017-04-17 19:41:25 +02:00
|
|
|
int AddrSize = AsmInfo->getCodePointerSize();
|
2020-02-28 06:57:40 +01:00
|
|
|
MCSymbol *RangesSymbol;
|
|
|
|
|
|
|
|
if (MCOS->getContext().getDwarfVersion() >= 5) {
|
|
|
|
MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfRnglistsSection());
|
2020-03-03 22:58:02 +01:00
|
|
|
MCSymbol *EndSymbol = mcdwarf::emitListsTableHeaderStart(*MCOS);
|
2020-02-28 06:57:40 +01:00
|
|
|
MCOS->AddComment("Offset entry count");
|
|
|
|
MCOS->emitInt32(0);
|
2020-12-21 23:04:13 +01:00
|
|
|
RangesSymbol = context.createTempSymbol("debug_rnglist0_start");
|
2020-02-28 06:57:40 +01:00
|
|
|
MCOS->emitLabel(RangesSymbol);
|
|
|
|
for (MCSection *Sec : Sections) {
|
|
|
|
const MCSymbol *StartSymbol = Sec->getBeginSymbol();
|
|
|
|
const MCSymbol *EndSymbol = Sec->getEndSymbol(context);
|
|
|
|
const MCExpr *SectionStartAddr = MCSymbolRefExpr::create(
|
|
|
|
StartSymbol, MCSymbolRefExpr::VK_None, context);
|
|
|
|
const MCExpr *SectionSize =
|
2020-06-18 15:15:55 +02:00
|
|
|
makeEndMinusStartExpr(context, *StartSymbol, *EndSymbol, 0);
|
2020-02-28 06:57:40 +01:00
|
|
|
MCOS->emitInt8(dwarf::DW_RLE_start_length);
|
|
|
|
MCOS->emitValue(SectionStartAddr, AddrSize);
|
|
|
|
MCOS->emitULEB128Value(SectionSize);
|
|
|
|
}
|
|
|
|
MCOS->emitInt8(dwarf::DW_RLE_end_of_list);
|
|
|
|
MCOS->emitLabel(EndSymbol);
|
|
|
|
} else {
|
|
|
|
MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfRangesSection());
|
2020-12-21 23:04:13 +01:00
|
|
|
RangesSymbol = context.createTempSymbol("debug_ranges_start");
|
2020-02-28 06:57:40 +01:00
|
|
|
MCOS->emitLabel(RangesSymbol);
|
|
|
|
for (MCSection *Sec : Sections) {
|
|
|
|
const MCSymbol *StartSymbol = Sec->getBeginSymbol();
|
|
|
|
const MCSymbol *EndSymbol = Sec->getEndSymbol(context);
|
|
|
|
|
|
|
|
// Emit a base address selection entry for the section start.
|
|
|
|
const MCExpr *SectionStartAddr = MCSymbolRefExpr::create(
|
|
|
|
StartSymbol, MCSymbolRefExpr::VK_None, context);
|
|
|
|
MCOS->emitFill(AddrSize, 0xFF);
|
|
|
|
MCOS->emitValue(SectionStartAddr, AddrSize);
|
|
|
|
|
|
|
|
// Emit a range list entry spanning this section.
|
|
|
|
const MCExpr *SectionSize =
|
2020-06-18 15:15:55 +02:00
|
|
|
makeEndMinusStartExpr(context, *StartSymbol, *EndSymbol, 0);
|
2020-02-28 06:57:40 +01:00
|
|
|
MCOS->emitIntValue(0, AddrSize);
|
|
|
|
emitAbsValue(*MCOS, SectionSize, AddrSize);
|
|
|
|
}
|
2014-06-19 17:52:37 +02:00
|
|
|
|
2020-02-28 06:57:40 +01:00
|
|
|
// Emit end of list entry
|
|
|
|
MCOS->emitIntValue(0, AddrSize);
|
2020-02-15 07:40:47 +01:00
|
|
|
MCOS->emitIntValue(0, AddrSize);
|
2014-06-19 17:52:37 +02:00
|
|
|
}
|
|
|
|
|
2020-02-28 06:57:40 +01:00
|
|
|
return RangesSymbol;
|
2014-06-19 17:52:37 +02:00
|
|
|
}
|
|
|
|
|
2011-12-09 19:09:40 +01:00
|
|
|
//
|
|
|
|
// When generating dwarf for assembly source files this emits the Dwarf
|
|
|
|
// sections.
|
|
|
|
//
|
2014-04-01 09:35:52 +02:00
|
|
|
void MCGenDwarfInfo::Emit(MCStreamer *MCOS) {
|
2011-12-09 19:09:40 +01:00
|
|
|
MCContext &context = MCOS->getContext();
|
2014-06-19 17:52:37 +02:00
|
|
|
|
|
|
|
// Create the dwarf sections in this order (.debug_line already created).
|
2013-06-18 09:20:20 +02:00
|
|
|
const MCAsmInfo *AsmInfo = context.getAsmInfo();
|
2012-11-14 10:55:38 +01:00
|
|
|
bool CreateDwarfSectionSymbols =
|
2013-06-18 09:20:20 +02:00
|
|
|
AsmInfo->doesDwarfUseRelocationsAcrossSections();
|
2014-04-01 09:35:52 +02:00
|
|
|
MCSymbol *LineSectionSymbol = nullptr;
|
2014-04-01 10:07:52 +02:00
|
|
|
if (CreateDwarfSectionSymbols)
|
|
|
|
LineSectionSymbol = MCOS->getDwarfLineTableSymbol(0);
|
2014-04-13 06:57:38 +02:00
|
|
|
MCSymbol *AbbrevSectionSymbol = nullptr;
|
|
|
|
MCSymbol *InfoSectionSymbol = nullptr;
|
2020-02-28 06:57:40 +01:00
|
|
|
MCSymbol *RangesSymbol = nullptr;
|
2014-06-19 17:52:37 +02: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 12:45:16 +02: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 17:52:37 +02:00
|
|
|
const bool UseRangesSection =
|
2014-09-22 12:45:16 +02:00
|
|
|
MCOS->getContext().getGenDwarfSectionSyms().size() > 1 &&
|
|
|
|
MCOS->getContext().getDwarfVersion() >= 3;
|
2014-06-19 17:52:37 +02:00
|
|
|
CreateDwarfSectionSymbols |= UseRangesSection;
|
|
|
|
|
2011-12-09 19:09:40 +01:00
|
|
|
MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfInfoSection());
|
2012-11-14 10:55:38 +01:00
|
|
|
if (CreateDwarfSectionSymbols) {
|
2015-05-18 20:43:14 +02:00
|
|
|
InfoSectionSymbol = context.createTempSymbol();
|
2020-02-15 04:21:58 +01:00
|
|
|
MCOS->emitLabel(InfoSectionSymbol);
|
2012-11-14 10:55:38 +01:00
|
|
|
}
|
2011-12-09 19:09:40 +01:00
|
|
|
MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfAbbrevSection());
|
2012-11-14 10:55:38 +01:00
|
|
|
if (CreateDwarfSectionSymbols) {
|
2015-05-18 20:43:14 +02:00
|
|
|
AbbrevSectionSymbol = context.createTempSymbol();
|
2020-02-15 04:21:58 +01:00
|
|
|
MCOS->emitLabel(AbbrevSectionSymbol);
|
2012-02-28 22:13:05 +01:00
|
|
|
}
|
2014-06-19 17:52:37 +02:00
|
|
|
|
|
|
|
MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfARangesSection());
|
2011-12-09 19:09:40 +01:00
|
|
|
|
|
|
|
// Output the data for .debug_aranges section.
|
2012-11-14 10:55:38 +01:00
|
|
|
EmitGenDwarfAranges(MCOS, InfoSectionSymbol);
|
2011-12-09 19:09:40 +01:00
|
|
|
|
2020-02-28 06:57:40 +01:00
|
|
|
if (UseRangesSection) {
|
|
|
|
RangesSymbol = emitGenDwarfRanges(MCOS);
|
|
|
|
assert(RangesSymbol);
|
|
|
|
}
|
2014-06-19 17:52:37 +02:00
|
|
|
|
2011-12-09 19:09:40 +01:00
|
|
|
// Output the data for .debug_abbrev section.
|
|
|
|
EmitGenDwarfAbbrev(MCOS);
|
|
|
|
|
|
|
|
// Output the data for .debug_info section.
|
2020-02-28 06:57:40 +01:00
|
|
|
EmitGenDwarfInfo(MCOS, AbbrevSectionSymbol, LineSectionSymbol, RangesSymbol);
|
2011-12-09 19:09:40 +01: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-10 22:12:34 +01:00
|
|
|
// a dwarf label.
|
2011-12-09 19:09:40 +01:00
|
|
|
//
|
2012-01-10 22:12:34 +01:00
|
|
|
void MCGenDwarfLabelEntry::Make(MCSymbol *Symbol, MCStreamer *MCOS,
|
2011-12-09 19:09:40 +01:00
|
|
|
SourceMgr &SrcMgr, SMLoc &Loc) {
|
2014-06-19 17:52:37 +02:00
|
|
|
// We won't create dwarf labels for temporary symbols.
|
2011-12-09 19:09:40 +01:00
|
|
|
if (Symbol->isTemporary())
|
|
|
|
return;
|
|
|
|
MCContext &context = MCOS->getContext();
|
2014-06-19 17:52:37 +02:00
|
|
|
// We won't create dwarf labels for symbols in sections that we are not
|
|
|
|
// generating debug info for.
|
2016-10-14 07:47:37 +02:00
|
|
|
if (!context.getGenDwarfSectionSyms().count(MCOS->getCurrentSectionOnly()))
|
2011-12-09 19:09:40 +01:00
|
|
|
return;
|
|
|
|
|
2012-01-10 22:12:34 +01:00
|
|
|
// The dwarf label's name does not have the symbol name's leading
|
2011-12-09 19:09:40 +01:00
|
|
|
// underbar if any.
|
|
|
|
StringRef Name = Symbol->getName();
|
|
|
|
if (Name.startswith("_"))
|
|
|
|
Name = Name.substr(1, Name.size()-1);
|
|
|
|
|
2012-01-10 22:12:34 +01:00
|
|
|
// Get the dwarf file number to be used for the dwarf label.
|
2011-12-09 19:09:40 +01:00
|
|
|
unsigned FileNumber = context.getGenDwarfFileNumber();
|
|
|
|
|
|
|
|
// Finding the line number is the expensive part which is why we just don't
|
2012-01-10 22:12:34 +01:00
|
|
|
// pass it in as for some symbols we won't create a dwarf label.
|
2014-07-06 12:33:31 +02:00
|
|
|
unsigned CurBuffer = SrcMgr.FindBufferContainingLoc(Loc);
|
2011-12-09 19:09:40 +01: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-18 20:43:14 +02:00
|
|
|
MCSymbol *Label = context.createTempSymbol();
|
2020-02-15 04:21:58 +01:00
|
|
|
MCOS->emitLabel(Label);
|
2011-12-09 19:09:40 +01:00
|
|
|
|
|
|
|
// Create and entry for the info and add it to the other entries.
|
2014-04-11 02:43:52 +02:00
|
|
|
MCOS->getContext().addMCGenDwarfLabelEntry(
|
|
|
|
MCGenDwarfLabelEntry(Name, FileNumber, LineNumber, Label));
|
2011-12-09 19:09:40 +01:00
|
|
|
}
|
|
|
|
|
2010-12-10 08:39:47 +01:00
|
|
|
static int getDataAlignmentFactor(MCStreamer &streamer) {
|
|
|
|
MCContext &context = streamer.getContext();
|
2013-06-18 09:20:20 +02:00
|
|
|
const MCAsmInfo *asmInfo = context.getAsmInfo();
|
|
|
|
int size = asmInfo->getCalleeSaveStackSlotSize();
|
|
|
|
if (asmInfo->isStackGrowthDirectionUp())
|
2010-12-10 08:39:47 +01:00
|
|
|
return size;
|
2011-07-15 04:09:41 +02:00
|
|
|
else
|
|
|
|
return -size;
|
2010-12-10 08:39:47 +01:00
|
|
|
}
|
|
|
|
|
2011-04-22 02:08:43 +02:00
|
|
|
static unsigned getSizeForEncoding(MCStreamer &streamer,
|
|
|
|
unsigned symbolEncoding) {
|
2011-04-12 18:12:03 +02:00
|
|
|
MCContext &context = streamer.getContext();
|
|
|
|
unsigned format = symbolEncoding & 0x0f;
|
|
|
|
switch (format) {
|
2012-02-07 06:05:23 +01:00
|
|
|
default: llvm_unreachable("Unknown Encoding");
|
2011-04-12 18:12:03 +02:00
|
|
|
case dwarf::DW_EH_PE_absptr:
|
|
|
|
case dwarf::DW_EH_PE_signed:
|
2017-04-17 19:41:25 +02:00
|
|
|
return context.getAsmInfo()->getCodePointerSize();
|
2011-04-12 18:12:03 +02:00
|
|
|
case dwarf::DW_EH_PE_udata2:
|
|
|
|
case dwarf::DW_EH_PE_sdata2:
|
2011-04-22 02:08:43 +02:00
|
|
|
return 2;
|
2011-04-12 18:12:03 +02:00
|
|
|
case dwarf::DW_EH_PE_udata4:
|
|
|
|
case dwarf::DW_EH_PE_sdata4:
|
2011-04-22 02:08:43 +02:00
|
|
|
return 4;
|
2011-04-12 18:12:03 +02:00
|
|
|
case dwarf::DW_EH_PE_udata8:
|
|
|
|
case dwarf::DW_EH_PE_sdata8:
|
2011-04-22 02:08:43 +02:00
|
|
|
return 8;
|
2011-04-12 18:12:03 +02:00
|
|
|
}
|
2011-04-22 02:08:43 +02:00
|
|
|
}
|
|
|
|
|
2014-08-15 05:07:13 +02:00
|
|
|
static void emitFDESymbol(MCObjectStreamer &streamer, const MCSymbol &symbol,
|
|
|
|
unsigned symbolEncoding, bool isEH) {
|
2011-04-28 23:04:39 +02:00
|
|
|
MCContext &context = streamer.getContext();
|
2013-06-18 09:20:20 +02:00
|
|
|
const MCAsmInfo *asmInfo = context.getAsmInfo();
|
|
|
|
const MCExpr *v = asmInfo->getExprForFDESymbol(&symbol,
|
|
|
|
symbolEncoding,
|
|
|
|
streamer);
|
2011-04-22 02:08:43 +02:00
|
|
|
unsigned size = getSizeForEncoding(streamer, symbolEncoding);
|
2014-01-08 11:22:54 +01:00
|
|
|
if (asmInfo->doDwarfFDESymbolsUseAbsDiff() && isEH)
|
2014-08-15 17:12:13 +02:00
|
|
|
emitAbsValue(streamer, v, size);
|
2014-01-08 11:22:54 +01:00
|
|
|
else
|
2020-02-15 07:40:47 +01:00
|
|
|
streamer.emitValue(v, size);
|
2011-04-12 18:12:03 +02:00
|
|
|
}
|
|
|
|
|
2011-04-28 18:09:09 +02:00
|
|
|
static void EmitPersonality(MCStreamer &streamer, const MCSymbol &symbol,
|
|
|
|
unsigned symbolEncoding) {
|
|
|
|
MCContext &context = streamer.getContext();
|
2013-06-18 09:20:20 +02:00
|
|
|
const MCAsmInfo *asmInfo = context.getAsmInfo();
|
|
|
|
const MCExpr *v = asmInfo->getExprForPersonalitySymbol(&symbol,
|
|
|
|
symbolEncoding,
|
|
|
|
streamer);
|
2011-04-28 18:09:09 +02:00
|
|
|
unsigned size = getSizeForEncoding(streamer, symbolEncoding);
|
2020-02-15 07:40:47 +01:00
|
|
|
streamer.emitValue(v, size);
|
2011-04-28 18:09:09 +02:00
|
|
|
}
|
|
|
|
|
2011-04-12 18:12:03 +02:00
|
|
|
namespace {
|
2017-02-14 01:33:36 +01:00
|
|
|
|
2015-11-06 00:54:18 +01:00
|
|
|
class FrameEmitterImpl {
|
2015-11-06 00:55:51 +01:00
|
|
|
int CFAOffset = 0;
|
|
|
|
int InitialCFAOffset = 0;
|
2015-11-06 00:54:18 +01:00
|
|
|
bool IsEH;
|
2015-11-06 01:05:57 +01:00
|
|
|
MCObjectStreamer &Streamer;
|
2015-11-06 00:54:18 +01:00
|
|
|
|
|
|
|
public:
|
2015-11-06 01:05:57 +01:00
|
|
|
FrameEmitterImpl(bool IsEH, MCObjectStreamer &Streamer)
|
|
|
|
: IsEH(IsEH), Streamer(Streamer) {}
|
2015-11-06 00:54:18 +01:00
|
|
|
|
|
|
|
/// Emit the unwind information in a compact way.
|
2015-11-06 01:05:57 +01:00
|
|
|
void EmitCompactUnwind(const MCDwarfFrameInfo &frame);
|
2015-11-06 00:54:18 +01:00
|
|
|
|
2017-07-29 22:03:02 +02:00
|
|
|
const MCSymbol &EmitCIE(const MCDwarfFrameInfo &F);
|
2015-11-06 04:02:51 +01:00
|
|
|
void EmitFDE(const MCSymbol &cieStart, const MCDwarfFrameInfo &frame,
|
2015-11-06 14:14:59 +01:00
|
|
|
bool LastInSection, const MCSymbol &SectionStart);
|
2020-02-14 06:58:16 +01:00
|
|
|
void emitCFIInstructions(ArrayRef<MCCFIInstruction> Instrs,
|
2015-11-06 00:54:18 +01:00
|
|
|
MCSymbol *BaseLabel);
|
2020-02-14 06:58:16 +01:00
|
|
|
void emitCFIInstruction(const MCCFIInstruction &Instr);
|
2015-11-06 00:54:18 +01:00
|
|
|
};
|
2011-06-30 23:25:51 +02:00
|
|
|
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
2014-08-15 05:07:13 +02:00
|
|
|
static void emitEncodingByte(MCObjectStreamer &Streamer, unsigned Encoding) {
|
2020-02-29 17:25:22 +01:00
|
|
|
Streamer.emitInt8(Encoding);
|
2011-04-12 18:12:03 +02:00
|
|
|
}
|
|
|
|
|
2020-02-14 06:58:16 +01:00
|
|
|
void FrameEmitterImpl::emitCFIInstruction(const MCCFIInstruction &Instr) {
|
2010-12-28 19:36:23 +01:00
|
|
|
int dataAlignmentFactor = getDataAlignmentFactor(Streamer);
|
2015-02-26 20:48:07 +01:00
|
|
|
auto *MRI = Streamer.getContext().getRegisterInfo();
|
2010-12-10 08:39:47 +01:00
|
|
|
|
2010-12-28 19:36:23 +01:00
|
|
|
switch (Instr.getOperation()) {
|
2012-11-25 16:14:49 +01:00
|
|
|
case MCCFIInstruction::OpRegister: {
|
|
|
|
unsigned Reg1 = Instr.getRegister();
|
|
|
|
unsigned Reg2 = Instr.getRegister2();
|
2015-02-26 20:48:07 +01:00
|
|
|
if (!IsEH) {
|
2017-12-01 22:44:27 +01:00
|
|
|
Reg1 = MRI->getDwarfRegNumFromDwarfEHRegNum(Reg1);
|
|
|
|
Reg2 = MRI->getDwarfRegNumFromDwarfEHRegNum(Reg2);
|
2015-02-26 20:48:07 +01:00
|
|
|
}
|
2020-02-29 17:25:22 +01:00
|
|
|
Streamer.emitInt8(dwarf::DW_CFA_register);
|
2020-02-13 22:26:21 +01:00
|
|
|
Streamer.emitULEB128IntValue(Reg1);
|
|
|
|
Streamer.emitULEB128IntValue(Reg2);
|
2012-11-25 16:14:49 +01:00
|
|
|
return;
|
|
|
|
}
|
2017-02-14 01:33:36 +01:00
|
|
|
case MCCFIInstruction::OpWindowSave:
|
2020-02-29 17:25:22 +01:00
|
|
|
Streamer.emitInt8(dwarf::DW_CFA_GNU_window_save);
|
2013-09-26 16:49:40 +02:00
|
|
|
return;
|
2017-02-14 01:33:36 +01:00
|
|
|
|
2018-12-18 11:37:42 +01:00
|
|
|
case MCCFIInstruction::OpNegateRAState:
|
2020-02-29 17:25:22 +01:00
|
|
|
Streamer.emitInt8(dwarf::DW_CFA_AARCH64_negate_ra_state);
|
2018-12-18 11:37:42 +01:00
|
|
|
return;
|
|
|
|
|
2012-11-24 04:10:54 +01:00
|
|
|
case MCCFIInstruction::OpUndefined: {
|
2012-11-24 05:33:48 +01:00
|
|
|
unsigned Reg = Instr.getRegister();
|
2020-02-29 17:25:22 +01:00
|
|
|
Streamer.emitInt8(dwarf::DW_CFA_undefined);
|
2020-02-13 22:26:21 +01:00
|
|
|
Streamer.emitULEB128IntValue(Reg);
|
2012-11-23 17:59:41 +01:00
|
|
|
return;
|
|
|
|
}
|
2012-11-24 04:10:54 +01:00
|
|
|
case MCCFIInstruction::OpAdjustCfaOffset:
|
|
|
|
case MCCFIInstruction::OpDefCfaOffset: {
|
|
|
|
const bool IsRelative =
|
|
|
|
Instr.getOperation() == MCCFIInstruction::OpAdjustCfaOffset;
|
2010-12-10 08:39:47 +01:00
|
|
|
|
2020-02-29 17:25:22 +01:00
|
|
|
Streamer.emitInt8(dwarf::DW_CFA_def_cfa_offset);
|
2011-04-12 20:53:30 +02:00
|
|
|
|
2012-11-24 04:10:54 +01:00
|
|
|
if (IsRelative)
|
2012-11-24 05:33:48 +01:00
|
|
|
CFAOffset += Instr.getOffset();
|
2012-11-24 04:10:54 +01:00
|
|
|
else
|
2020-05-23 04:57:21 +02:00
|
|
|
CFAOffset = Instr.getOffset();
|
2010-12-10 08:39:47 +01:00
|
|
|
|
2020-02-13 22:26:21 +01:00
|
|
|
Streamer.emitULEB128IntValue(CFAOffset);
|
2012-11-24 04:10:54 +01:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case MCCFIInstruction::OpDefCfa: {
|
2015-02-26 20:48:07 +01:00
|
|
|
unsigned Reg = Instr.getRegister();
|
|
|
|
if (!IsEH)
|
2017-12-01 22:44:27 +01:00
|
|
|
Reg = MRI->getDwarfRegNumFromDwarfEHRegNum(Reg);
|
2020-02-29 17:25:22 +01:00
|
|
|
Streamer.emitInt8(dwarf::DW_CFA_def_cfa);
|
2020-02-13 22:26:21 +01:00
|
|
|
Streamer.emitULEB128IntValue(Reg);
|
2020-05-23 05:18:15 +02:00
|
|
|
CFAOffset = Instr.getOffset();
|
2020-02-13 22:26:21 +01:00
|
|
|
Streamer.emitULEB128IntValue(CFAOffset);
|
2012-11-24 04:10:54 +01:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case MCCFIInstruction::OpDefCfaRegister: {
|
2015-02-26 20:48:07 +01:00
|
|
|
unsigned Reg = Instr.getRegister();
|
|
|
|
if (!IsEH)
|
2017-12-01 22:44:27 +01:00
|
|
|
Reg = MRI->getDwarfRegNumFromDwarfEHRegNum(Reg);
|
2020-02-29 17:25:22 +01:00
|
|
|
Streamer.emitInt8(dwarf::DW_CFA_def_cfa_register);
|
2020-02-13 22:26:21 +01:00
|
|
|
Streamer.emitULEB128IntValue(Reg);
|
2012-11-24 04:10:54 +01:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case MCCFIInstruction::OpOffset:
|
|
|
|
case MCCFIInstruction::OpRelOffset: {
|
|
|
|
const bool IsRelative =
|
|
|
|
Instr.getOperation() == MCCFIInstruction::OpRelOffset;
|
2010-12-10 08:39:47 +01:00
|
|
|
|
2012-11-24 05:33:48 +01:00
|
|
|
unsigned Reg = Instr.getRegister();
|
2015-02-26 20:48:07 +01:00
|
|
|
if (!IsEH)
|
2017-12-01 22:44:27 +01:00
|
|
|
Reg = MRI->getDwarfRegNumFromDwarfEHRegNum(Reg);
|
2015-02-26 20:48:07 +01:00
|
|
|
|
2012-11-24 05:33:48 +01:00
|
|
|
int Offset = Instr.getOffset();
|
2011-04-12 18:12:03 +02:00
|
|
|
if (IsRelative)
|
|
|
|
Offset -= CFAOffset;
|
|
|
|
Offset = Offset / dataAlignmentFactor;
|
2010-12-10 08:39:47 +01:00
|
|
|
|
|
|
|
if (Offset < 0) {
|
2020-02-29 17:25:22 +01:00
|
|
|
Streamer.emitInt8(dwarf::DW_CFA_offset_extended_sf);
|
2020-02-13 22:26:21 +01:00
|
|
|
Streamer.emitULEB128IntValue(Reg);
|
|
|
|
Streamer.emitSLEB128IntValue(Offset);
|
2010-12-10 08:39:47 +01:00
|
|
|
} else if (Reg < 64) {
|
2020-02-29 17:25:22 +01:00
|
|
|
Streamer.emitInt8(dwarf::DW_CFA_offset + Reg);
|
2020-02-13 22:26:21 +01:00
|
|
|
Streamer.emitULEB128IntValue(Offset);
|
2010-12-10 08:39:47 +01:00
|
|
|
} else {
|
2020-02-29 17:25:22 +01:00
|
|
|
Streamer.emitInt8(dwarf::DW_CFA_offset_extended);
|
2020-02-13 22:26:21 +01:00
|
|
|
Streamer.emitULEB128IntValue(Reg);
|
|
|
|
Streamer.emitULEB128IntValue(Offset);
|
2010-12-28 19:36:23 +01:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2012-11-24 04:10:54 +01:00
|
|
|
case MCCFIInstruction::OpRememberState:
|
2020-02-29 17:25:22 +01:00
|
|
|
Streamer.emitInt8(dwarf::DW_CFA_remember_state);
|
2010-12-28 19:36:23 +01:00
|
|
|
return;
|
2012-11-24 04:10:54 +01:00
|
|
|
case MCCFIInstruction::OpRestoreState:
|
2020-02-29 17:25:22 +01:00
|
|
|
Streamer.emitInt8(dwarf::DW_CFA_restore_state);
|
2010-12-28 19:36:23 +01:00
|
|
|
return;
|
2012-11-24 04:10:54 +01:00
|
|
|
case MCCFIInstruction::OpSameValue: {
|
2012-11-24 05:33:48 +01:00
|
|
|
unsigned Reg = Instr.getRegister();
|
2020-02-29 17:25:22 +01:00
|
|
|
Streamer.emitInt8(dwarf::DW_CFA_same_value);
|
2020-02-13 22:26:21 +01:00
|
|
|
Streamer.emitULEB128IntValue(Reg);
|
2011-04-12 17:31:05 +02:00
|
|
|
return;
|
|
|
|
}
|
2012-11-24 04:10:54 +01:00
|
|
|
case MCCFIInstruction::OpRestore: {
|
2012-11-24 05:33:48 +01:00
|
|
|
unsigned Reg = Instr.getRegister();
|
2015-02-26 20:48:07 +01:00
|
|
|
if (!IsEH)
|
2017-12-01 22:44:27 +01:00
|
|
|
Reg = MRI->getDwarfRegNumFromDwarfEHRegNum(Reg);
|
2018-11-13 11:54:49 +01:00
|
|
|
if (Reg < 64) {
|
2020-02-29 17:25:22 +01:00
|
|
|
Streamer.emitInt8(dwarf::DW_CFA_restore | Reg);
|
2018-11-13 11:54:49 +01:00
|
|
|
} else {
|
2020-02-29 17:25:22 +01:00
|
|
|
Streamer.emitInt8(dwarf::DW_CFA_restore_extended);
|
2020-02-13 22:26:21 +01:00
|
|
|
Streamer.emitULEB128IntValue(Reg);
|
2018-11-13 11:54:49 +01:00
|
|
|
}
|
2011-12-29 22:43:03 +01:00
|
|
|
return;
|
|
|
|
}
|
2017-02-14 01:33:36 +01:00
|
|
|
case MCCFIInstruction::OpGnuArgsSize:
|
2020-02-29 17:25:22 +01:00
|
|
|
Streamer.emitInt8(dwarf::DW_CFA_GNU_args_size);
|
2020-02-13 22:26:21 +01:00
|
|
|
Streamer.emitULEB128IntValue(Instr.getOffset());
|
2015-10-07 09:01:31 +02:00
|
|
|
return;
|
2017-02-14 01:33:36 +01:00
|
|
|
|
2012-11-24 04:10:54 +01:00
|
|
|
case MCCFIInstruction::OpEscape:
|
2020-02-15 03:16:24 +01:00
|
|
|
Streamer.emitBytes(Instr.getValues());
|
2011-12-29 21:24:47 +01:00
|
|
|
return;
|
2010-12-28 19:36:23 +01:00
|
|
|
}
|
|
|
|
llvm_unreachable("Unhandled case in switch");
|
|
|
|
}
|
|
|
|
|
2014-08-15 05:07:13 +02:00
|
|
|
/// Emit frame instructions to describe the layout of the frame.
|
2020-02-14 06:58:16 +01:00
|
|
|
void FrameEmitterImpl::emitCFIInstructions(ArrayRef<MCCFIInstruction> Instrs,
|
2011-04-12 18:12:03 +02:00
|
|
|
MCSymbol *BaseLabel) {
|
2016-06-26 16:49:00 +02:00
|
|
|
for (const MCCFIInstruction &Instr : Instrs) {
|
2010-12-28 19:36:23 +01: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) {
|
2020-02-13 22:26:21 +01:00
|
|
|
Streamer.emitDwarfAdvanceFrameAddr(BaseLabel, ThisSym);
|
2010-12-28 19:36:23 +01:00
|
|
|
BaseLabel = ThisSym;
|
|
|
|
}
|
2010-12-10 08:39:47 +01:00
|
|
|
}
|
2010-12-28 19:36:23 +01:00
|
|
|
|
2020-02-14 06:58:16 +01:00
|
|
|
emitCFIInstruction(Instr);
|
2010-12-10 08:39:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-15 05:07:13 +02:00
|
|
|
/// Emit the unwind information in a compact way.
|
2015-11-06 01:05:57 +01:00
|
|
|
void FrameEmitterImpl::EmitCompactUnwind(const MCDwarfFrameInfo &Frame) {
|
2011-06-23 03:06:23 +02:00
|
|
|
MCContext &Context = Streamer.getContext();
|
2011-07-20 07:58:47 +02:00
|
|
|
const MCObjectFileInfo *MOFI = Context.getObjectFileInfo();
|
2011-06-23 03:06:23 +02: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 02:06:12 +02:00
|
|
|
uint32_t Encoding = Frame.CompactUnwindEncoding;
|
2013-04-19 01:16:46 +02:00
|
|
|
if (!Encoding) return;
|
2013-04-10 23:42:06 +02:00
|
|
|
bool DwarfEHFrameOnly = (Encoding == MOFI->getCompactUnwindDwarfEHFrameOnly());
|
2011-07-07 02:54:13 +02:00
|
|
|
|
2011-07-15 01:34:45 +02:00
|
|
|
// The encoding needs to know we have an LSDA.
|
2013-04-10 23:42:06 +02:00
|
|
|
if (!DwarfEHFrameOnly && Frame.Lsda)
|
2011-07-15 01:34:45 +02:00
|
|
|
Encoding |= 0x40000000;
|
|
|
|
|
2011-06-23 03:06:23 +02:00
|
|
|
// Range Start
|
2014-05-12 15:47:05 +02:00
|
|
|
unsigned FDEEncoding = MOFI->getFDEEncoding();
|
2011-06-30 01:49:12 +02:00
|
|
|
unsigned Size = getSizeForEncoding(Streamer, FDEEncoding);
|
2020-02-15 04:21:58 +01:00
|
|
|
Streamer.emitSymbolValue(Frame.Begin, Size);
|
2011-06-23 03:06:23 +02:00
|
|
|
|
|
|
|
// Range Length
|
2020-05-21 08:05:38 +02:00
|
|
|
const MCExpr *Range =
|
2020-06-18 15:15:55 +02:00
|
|
|
makeEndMinusStartExpr(Context, *Frame.Begin, *Frame.End, 0);
|
2014-08-15 17:12:13 +02:00
|
|
|
emitAbsValue(Streamer, Range, 4);
|
2011-06-30 02:30:52 +02:00
|
|
|
|
|
|
|
// Compact Encoding
|
|
|
|
Size = getSizeForEncoding(Streamer, dwarf::DW_EH_PE_udata4);
|
2020-02-15 07:40:47 +01:00
|
|
|
Streamer.emitIntValue(Encoding, Size);
|
2011-06-30 02:30:52 +02:00
|
|
|
|
2011-06-30 01:49:12 +02:00
|
|
|
// Personality Function
|
2011-07-15 01:34:45 +02:00
|
|
|
Size = getSizeForEncoding(Streamer, dwarf::DW_EH_PE_absptr);
|
2013-04-10 23:42:06 +02:00
|
|
|
if (!DwarfEHFrameOnly && Frame.Personality)
|
2020-02-15 04:21:58 +01:00
|
|
|
Streamer.emitSymbolValue(Frame.Personality, Size);
|
2011-06-30 01:53:16 +02:00
|
|
|
else
|
2020-02-15 07:40:47 +01:00
|
|
|
Streamer.emitIntValue(0, Size); // No personality fn
|
2011-06-30 01:49:12 +02:00
|
|
|
|
|
|
|
// LSDA
|
2011-06-30 01:53:16 +02:00
|
|
|
Size = getSizeForEncoding(Streamer, Frame.LsdaEncoding);
|
2013-04-10 23:42:06 +02:00
|
|
|
if (!DwarfEHFrameOnly && Frame.Lsda)
|
2020-02-15 04:21:58 +01:00
|
|
|
Streamer.emitSymbolValue(Frame.Lsda, Size);
|
2011-06-30 01:53:16 +02:00
|
|
|
else
|
2020-02-15 07:40:47 +01:00
|
|
|
Streamer.emitIntValue(0, Size); // No LSDA
|
2011-06-23 03:06:23 +02:00
|
|
|
}
|
|
|
|
|
2015-04-28 15:55:31 +02: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 00:02:42 +01:00
|
|
|
case 5:
|
2015-04-28 15:55:31 +02:00
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
llvm_unreachable("Unknown version");
|
|
|
|
}
|
|
|
|
|
2017-07-29 22:03:02 +02:00
|
|
|
const MCSymbol &FrameEmitterImpl::EmitCIE(const MCDwarfFrameInfo &Frame) {
|
2015-11-06 01:05:57 +01:00
|
|
|
MCContext &context = Streamer.getContext();
|
2013-06-18 09:20:20 +02:00
|
|
|
const MCRegisterInfo *MRI = context.getRegisterInfo();
|
2011-07-20 07:58:47 +02:00
|
|
|
const MCObjectFileInfo *MOFI = context.getObjectFileInfo();
|
2011-04-28 05:26:11 +02:00
|
|
|
|
2015-05-18 20:43:14 +02:00
|
|
|
MCSymbol *sectionStart = context.createTempSymbol();
|
2020-02-15 04:21:58 +01:00
|
|
|
Streamer.emitLabel(sectionStart);
|
2011-04-28 05:26:11 +02:00
|
|
|
|
2015-05-18 20:43:14 +02:00
|
|
|
MCSymbol *sectionEnd = context.createTempSymbol();
|
2010-12-10 08:39:47 +01:00
|
|
|
|
2020-06-03 11:52:02 +02:00
|
|
|
dwarf::DwarfFormat Format = IsEH ? dwarf::DWARF32 : context.getDwarfFormat();
|
|
|
|
unsigned UnitLengthBytes = dwarf::getUnitLengthFieldByteSize(Format);
|
|
|
|
unsigned OffsetSize = dwarf::getDwarfOffsetByteSize(Format);
|
|
|
|
bool IsDwarf64 = Format == dwarf::DWARF64;
|
|
|
|
|
|
|
|
if (IsDwarf64)
|
|
|
|
// DWARF64 mark
|
|
|
|
Streamer.emitInt32(dwarf::DW_LENGTH_DWARF64);
|
|
|
|
|
2010-12-10 08:39:47 +01:00
|
|
|
// Length
|
2020-06-18 15:15:55 +02:00
|
|
|
const MCExpr *Length = makeEndMinusStartExpr(context, *sectionStart,
|
2020-06-03 11:52:02 +02:00
|
|
|
*sectionEnd, UnitLengthBytes);
|
|
|
|
emitAbsValue(Streamer, Length, OffsetSize);
|
2010-12-10 08:39:47 +01:00
|
|
|
|
|
|
|
// CIE ID
|
2020-06-03 11:52:02 +02:00
|
|
|
uint64_t CIE_ID =
|
|
|
|
IsEH ? 0 : (IsDwarf64 ? dwarf::DW64_CIE_ID : dwarf::DW_CIE_ID);
|
|
|
|
Streamer.emitIntValue(CIE_ID, OffsetSize);
|
2010-12-10 08:39:47 +01:00
|
|
|
|
|
|
|
// Version
|
2015-04-28 15:55:31 +02:00
|
|
|
uint8_t CIEVersion = getCIEVersion(IsEH, context.getDwarfVersion());
|
2020-02-29 17:25:22 +01:00
|
|
|
Streamer.emitInt8(CIEVersion);
|
2010-12-10 08:39:47 +01:00
|
|
|
|
2011-05-10 05:54:12 +02:00
|
|
|
if (IsEH) {
|
2018-12-21 11:45:08 +01:00
|
|
|
SmallString<8> Augmentation;
|
2011-05-10 05:54:12 +02:00
|
|
|
Augmentation += "z";
|
2017-07-29 22:03:02 +02:00
|
|
|
if (Frame.Personality)
|
2011-05-10 05:54:12 +02:00
|
|
|
Augmentation += "P";
|
2017-07-29 22:03:02 +02:00
|
|
|
if (Frame.Lsda)
|
2011-05-10 05:54:12 +02:00
|
|
|
Augmentation += "L";
|
|
|
|
Augmentation += "R";
|
2017-07-29 22:03:02 +02:00
|
|
|
if (Frame.IsSignalFrame)
|
2012-01-23 22:51:52 +01:00
|
|
|
Augmentation += "S";
|
2018-12-21 11:45:08 +01:00
|
|
|
if (Frame.IsBKeyFrame)
|
|
|
|
Augmentation += "B";
|
2020-02-15 03:16:24 +01:00
|
|
|
Streamer.emitBytes(Augmentation);
|
2011-05-10 05:54:12 +02:00
|
|
|
}
|
2020-02-29 17:25:22 +01:00
|
|
|
Streamer.emitInt8(0);
|
2010-12-10 08:39:47 +01:00
|
|
|
|
2015-05-12 17:25:08 +02:00
|
|
|
if (CIEVersion >= 4) {
|
|
|
|
// Address Size
|
2020-02-29 17:25:22 +01:00
|
|
|
Streamer.emitInt8(context.getAsmInfo()->getCodePointerSize());
|
2015-05-12 17:25:08 +02:00
|
|
|
|
|
|
|
// Segment Descriptor Size
|
2020-02-29 17:25:22 +01:00
|
|
|
Streamer.emitInt8(0);
|
2015-05-12 17:25:08 +02:00
|
|
|
}
|
|
|
|
|
2010-12-10 08:39:47 +01:00
|
|
|
// Code Alignment Factor
|
2020-02-13 22:26:21 +01:00
|
|
|
Streamer.emitULEB128IntValue(context.getAsmInfo()->getMinInstAlignment());
|
2010-12-10 08:39:47 +01:00
|
|
|
|
|
|
|
// Data Alignment Factor
|
2020-02-13 22:26:21 +01:00
|
|
|
Streamer.emitSLEB128IntValue(getDataAlignmentFactor(Streamer));
|
2010-12-10 08:39:47 +01:00
|
|
|
|
|
|
|
// Return Address Register
|
2017-07-29 22:03:02 +02:00
|
|
|
unsigned RAReg = Frame.RAReg;
|
2017-07-28 05:39:19 +02:00
|
|
|
if (RAReg == static_cast<unsigned>(INT_MAX))
|
|
|
|
RAReg = MRI->getDwarfRegNum(MRI->getRARegister(), IsEH);
|
|
|
|
|
2014-06-19 17:39:33 +02:00
|
|
|
if (CIEVersion == 1) {
|
2017-07-28 05:39:19 +02:00
|
|
|
assert(RAReg <= 255 &&
|
2014-06-19 17:39:33 +02:00
|
|
|
"DWARF 2 encodes return_address_register in one byte");
|
2020-02-29 17:25:22 +01:00
|
|
|
Streamer.emitInt8(RAReg);
|
2014-06-19 17:39:33 +02:00
|
|
|
} else {
|
2020-02-13 22:26:21 +01:00
|
|
|
Streamer.emitULEB128IntValue(RAReg);
|
2014-06-19 17:39:33 +02:00
|
|
|
}
|
2010-12-10 08:39:47 +01:00
|
|
|
|
|
|
|
// Augmentation Data Length (optional)
|
2011-04-29 23:50:57 +02:00
|
|
|
unsigned augmentationLength = 0;
|
2011-05-10 05:54:12 +02:00
|
|
|
if (IsEH) {
|
2017-07-29 22:03:02 +02:00
|
|
|
if (Frame.Personality) {
|
2011-05-10 05:54:12 +02:00
|
|
|
// Personality Encoding
|
|
|
|
augmentationLength += 1;
|
|
|
|
// Personality
|
2017-07-29 22:03:02 +02:00
|
|
|
augmentationLength +=
|
|
|
|
getSizeForEncoding(Streamer, Frame.PersonalityEncoding);
|
2011-05-10 05:54:12 +02:00
|
|
|
}
|
2017-07-29 22:03:02 +02:00
|
|
|
if (Frame.Lsda)
|
2011-05-10 05:54:12 +02:00
|
|
|
augmentationLength += 1;
|
|
|
|
// Encoding of the FDE pointers
|
2011-04-29 23:50:57 +02:00
|
|
|
augmentationLength += 1;
|
|
|
|
|
2020-02-13 22:26:21 +01:00
|
|
|
Streamer.emitULEB128IntValue(augmentationLength);
|
2010-12-10 08:39:47 +01:00
|
|
|
|
2011-05-10 05:54:12 +02:00
|
|
|
// Augmentation Data (optional)
|
2017-07-29 22:03:02 +02:00
|
|
|
if (Frame.Personality) {
|
2011-05-10 05:54:12 +02:00
|
|
|
// Personality Encoding
|
2017-07-29 22:03:02 +02:00
|
|
|
emitEncodingByte(Streamer, Frame.PersonalityEncoding);
|
2011-05-10 05:54:12 +02:00
|
|
|
// Personality
|
2017-07-29 22:03:02 +02:00
|
|
|
EmitPersonality(Streamer, *Frame.Personality, Frame.PersonalityEncoding);
|
2011-05-10 05:54:12 +02:00
|
|
|
}
|
2011-06-30 23:25:51 +02:00
|
|
|
|
2017-07-29 22:03:02 +02:00
|
|
|
if (Frame.Lsda)
|
|
|
|
emitEncodingByte(Streamer, Frame.LsdaEncoding);
|
2011-06-30 23:25:51 +02:00
|
|
|
|
2011-05-10 05:54:12 +02:00
|
|
|
// Encoding of the FDE pointers
|
2015-11-06 01:05:57 +01:00
|
|
|
emitEncodingByte(Streamer, MOFI->getFDEEncoding());
|
2010-12-27 16:56:22 +01:00
|
|
|
}
|
2010-12-10 08:39:47 +01:00
|
|
|
|
|
|
|
// Initial Instructions
|
|
|
|
|
2013-06-18 09:20:20 +02:00
|
|
|
const MCAsmInfo *MAI = context.getAsmInfo();
|
2017-07-29 22:03:02 +02:00
|
|
|
if (!Frame.IsSimple) {
|
2014-01-27 18:20:25 +01:00
|
|
|
const std::vector<MCCFIInstruction> &Instructions =
|
|
|
|
MAI->getInitialFrameState();
|
2020-02-14 06:58:16 +01:00
|
|
|
emitCFIInstructions(Instructions, nullptr);
|
2014-01-27 18:20:25 +01:00
|
|
|
}
|
2010-12-10 08:39:47 +01:00
|
|
|
|
2015-03-24 22:47:31 +01:00
|
|
|
InitialCFAOffset = CFAOffset;
|
|
|
|
|
2010-12-10 08:39:47 +01:00
|
|
|
// Padding
|
2020-02-15 04:21:58 +01:00
|
|
|
Streamer.emitValueToAlignment(IsEH ? 4 : MAI->getCodePointerSize());
|
2010-12-10 08:39:47 +01:00
|
|
|
|
2020-02-15 04:21:58 +01:00
|
|
|
Streamer.emitLabel(sectionEnd);
|
2010-12-10 08:39:47 +01:00
|
|
|
return *sectionStart;
|
|
|
|
}
|
|
|
|
|
2015-11-06 04:02:51 +01:00
|
|
|
void FrameEmitterImpl::EmitFDE(const MCSymbol &cieStart,
|
|
|
|
const MCDwarfFrameInfo &frame,
|
2015-11-06 14:14:59 +01:00
|
|
|
bool LastInSection,
|
|
|
|
const MCSymbol &SectionStart) {
|
2015-11-06 01:05:57 +01:00
|
|
|
MCContext &context = Streamer.getContext();
|
2015-05-18 20:43:14 +02:00
|
|
|
MCSymbol *fdeStart = context.createTempSymbol();
|
|
|
|
MCSymbol *fdeEnd = context.createTempSymbol();
|
2011-07-20 07:58:47 +02:00
|
|
|
const MCObjectFileInfo *MOFI = context.getObjectFileInfo();
|
2010-12-10 08:39:47 +01:00
|
|
|
|
2015-03-24 22:47:31 +01:00
|
|
|
CFAOffset = InitialCFAOffset;
|
|
|
|
|
2020-06-03 11:52:02 +02:00
|
|
|
dwarf::DwarfFormat Format = IsEH ? dwarf::DWARF32 : context.getDwarfFormat();
|
|
|
|
unsigned OffsetSize = dwarf::getDwarfOffsetByteSize(Format);
|
|
|
|
|
|
|
|
if (Format == dwarf::DWARF64)
|
|
|
|
// DWARF64 mark
|
|
|
|
Streamer.emitInt32(dwarf::DW_LENGTH_DWARF64);
|
|
|
|
|
2010-12-10 08:39:47 +01:00
|
|
|
// Length
|
2020-06-18 15:15:55 +02:00
|
|
|
const MCExpr *Length = makeEndMinusStartExpr(context, *fdeStart, *fdeEnd, 0);
|
2020-06-03 11:52:02 +02:00
|
|
|
emitAbsValue(Streamer, Length, OffsetSize);
|
2010-12-10 08:39:47 +01:00
|
|
|
|
2020-02-15 04:21:58 +01:00
|
|
|
Streamer.emitLabel(fdeStart);
|
2011-05-10 22:59:42 +02:00
|
|
|
|
2010-12-10 08:39:47 +01:00
|
|
|
// CIE Pointer
|
2013-06-18 09:20:20 +02:00
|
|
|
const MCAsmInfo *asmInfo = context.getAsmInfo();
|
2011-05-10 17:20:23 +02:00
|
|
|
if (IsEH) {
|
2015-11-06 01:05:57 +01:00
|
|
|
const MCExpr *offset =
|
2020-06-18 15:15:55 +02:00
|
|
|
makeEndMinusStartExpr(context, cieStart, *fdeStart, 0);
|
2020-06-03 11:52:02 +02:00
|
|
|
emitAbsValue(Streamer, offset, OffsetSize);
|
2013-06-18 09:20:20 +02:00
|
|
|
} else if (!asmInfo->doesDwarfUseRelocationsAcrossSections()) {
|
2015-11-06 01:05:57 +01:00
|
|
|
const MCExpr *offset =
|
2020-06-18 15:15:55 +02:00
|
|
|
makeEndMinusStartExpr(context, SectionStart, cieStart, 0);
|
2020-06-03 11:52:02 +02:00
|
|
|
emitAbsValue(Streamer, offset, OffsetSize);
|
2011-05-10 17:20:23 +02:00
|
|
|
} else {
|
2020-06-03 11:52:02 +02:00
|
|
|
Streamer.emitSymbolValue(&cieStart, OffsetSize,
|
2019-11-22 23:46:24 +01:00
|
|
|
asmInfo->needsDwarfSectionOffsetDirective());
|
2011-05-10 17:20:23 +02:00
|
|
|
}
|
2011-07-01 00:02:20 +02:00
|
|
|
|
2010-12-10 08:39:47 +01:00
|
|
|
// PC Begin
|
2014-05-12 15:40:49 +02:00
|
|
|
unsigned PCEncoding =
|
2014-05-12 15:47:05 +02:00
|
|
|
IsEH ? MOFI->getFDEEncoding() : (unsigned)dwarf::DW_EH_PE_absptr;
|
2015-11-06 01:05:57 +01:00
|
|
|
unsigned PCSize = getSizeForEncoding(Streamer, PCEncoding);
|
|
|
|
emitFDESymbol(Streamer, *frame.Begin, PCEncoding, IsEH);
|
2010-12-10 08:39:47 +01:00
|
|
|
|
|
|
|
// PC Range
|
2015-11-06 01:05:57 +01:00
|
|
|
const MCExpr *Range =
|
2020-06-18 15:15:55 +02:00
|
|
|
makeEndMinusStartExpr(context, *frame.Begin, *frame.End, 0);
|
2015-11-06 01:05:57 +01:00
|
|
|
emitAbsValue(Streamer, Range, PCSize);
|
2010-12-10 08:39:47 +01:00
|
|
|
|
2011-05-10 05:54:12 +02:00
|
|
|
if (IsEH) {
|
|
|
|
// Augmentation Data Length
|
|
|
|
unsigned augmentationLength = 0;
|
2011-04-29 23:50:57 +02:00
|
|
|
|
2011-05-10 05:54:12 +02:00
|
|
|
if (frame.Lsda)
|
2015-11-06 01:05:57 +01:00
|
|
|
augmentationLength += getSizeForEncoding(Streamer, frame.LsdaEncoding);
|
2011-04-29 23:50:57 +02:00
|
|
|
|
2020-02-13 22:26:21 +01:00
|
|
|
Streamer.emitULEB128IntValue(augmentationLength);
|
2010-12-10 08:39:47 +01:00
|
|
|
|
2011-05-10 05:54:12 +02:00
|
|
|
// Augmentation Data
|
|
|
|
if (frame.Lsda)
|
2015-11-06 01:05:57 +01:00
|
|
|
emitFDESymbol(Streamer, *frame.Lsda, frame.LsdaEncoding, true);
|
2011-05-10 05:54:12 +02:00
|
|
|
}
|
2011-04-29 05:06:29 +02:00
|
|
|
|
2010-12-10 08:39:47 +01:00
|
|
|
// Call Frame Instructions
|
2020-02-14 06:58:16 +01:00
|
|
|
emitCFIInstructions(frame.Instructions, frame.Begin);
|
2010-12-28 05:15:37 +01:00
|
|
|
|
2010-12-10 08:39:47 +01:00
|
|
|
// Padding
|
2015-11-06 04:02:51 +01: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-17 19:41:25 +02:00
|
|
|
unsigned Align = LastInSection ? asmInfo->getCodePointerSize() : PCSize;
|
2020-02-15 04:21:58 +01:00
|
|
|
Streamer.emitValueToAlignment(Align);
|
2010-12-17 01:28:02 +01:00
|
|
|
|
2020-02-15 04:21:58 +01:00
|
|
|
Streamer.emitLabel(fdeEnd);
|
2010-12-10 08:39:47 +01:00
|
|
|
}
|
|
|
|
|
2010-12-30 23:34:44 +01:00
|
|
|
namespace {
|
2017-02-14 01:33:36 +01:00
|
|
|
|
2015-11-06 15:12:17 +01:00
|
|
|
struct CIEKey {
|
|
|
|
static const CIEKey getEmptyKey() {
|
2018-12-21 11:45:08 +01:00
|
|
|
return CIEKey(nullptr, 0, -1, false, false, static_cast<unsigned>(INT_MAX),
|
|
|
|
false);
|
2015-11-06 15:12:17 +01:00
|
|
|
}
|
2017-02-14 01:33:36 +01:00
|
|
|
|
2015-11-06 15:12:17 +01:00
|
|
|
static const CIEKey getTombstoneKey() {
|
2018-12-21 11:45:08 +01:00
|
|
|
return CIEKey(nullptr, -1, 0, false, false, static_cast<unsigned>(INT_MAX),
|
|
|
|
false);
|
2015-11-06 15:12:17 +01:00
|
|
|
}
|
2010-12-30 23:34:44 +01:00
|
|
|
|
2015-11-06 15:12:17 +01:00
|
|
|
CIEKey(const MCSymbol *Personality, unsigned PersonalityEncoding,
|
2017-07-29 22:03:02 +02:00
|
|
|
unsigned LSDAEncoding, bool IsSignalFrame, bool IsSimple,
|
2018-12-21 11:45:08 +01:00
|
|
|
unsigned RAReg, bool IsBKeyFrame)
|
2015-11-06 15:12:17 +01:00
|
|
|
: Personality(Personality), PersonalityEncoding(PersonalityEncoding),
|
2017-07-29 22:03:02 +02:00
|
|
|
LsdaEncoding(LSDAEncoding), IsSignalFrame(IsSignalFrame),
|
2018-12-21 11:45:08 +01:00
|
|
|
IsSimple(IsSimple), RAReg(RAReg), IsBKeyFrame(IsBKeyFrame) {}
|
2017-02-14 01:33:36 +01:00
|
|
|
|
2017-07-29 22:03:02 +02:00
|
|
|
explicit CIEKey(const MCDwarfFrameInfo &Frame)
|
|
|
|
: Personality(Frame.Personality),
|
|
|
|
PersonalityEncoding(Frame.PersonalityEncoding),
|
|
|
|
LsdaEncoding(Frame.LsdaEncoding), IsSignalFrame(Frame.IsSignalFrame),
|
2018-12-21 11:45:08 +01:00
|
|
|
IsSimple(Frame.IsSimple), RAReg(Frame.RAReg),
|
|
|
|
IsBKeyFrame(Frame.IsBKeyFrame) {}
|
2017-07-29 22:03:02 +02:00
|
|
|
|
2019-03-15 00:08:19 +01:00
|
|
|
StringRef PersonalityName() const {
|
|
|
|
if (!Personality)
|
|
|
|
return StringRef();
|
|
|
|
return Personality->getName();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator<(const CIEKey &Other) const {
|
|
|
|
return std::make_tuple(PersonalityName(), PersonalityEncoding, LsdaEncoding,
|
|
|
|
IsSignalFrame, IsSimple, RAReg) <
|
|
|
|
std::make_tuple(Other.PersonalityName(), Other.PersonalityEncoding,
|
|
|
|
Other.LsdaEncoding, Other.IsSignalFrame,
|
|
|
|
Other.IsSimple, Other.RAReg);
|
|
|
|
}
|
|
|
|
|
2015-11-06 15:12:17 +01:00
|
|
|
const MCSymbol *Personality;
|
|
|
|
unsigned PersonalityEncoding;
|
|
|
|
unsigned LsdaEncoding;
|
|
|
|
bool IsSignalFrame;
|
|
|
|
bool IsSimple;
|
2017-07-29 22:03:00 +02:00
|
|
|
unsigned RAReg;
|
2018-12-21 11:45:08 +01:00
|
|
|
bool IsBKeyFrame;
|
2015-11-06 15:12:17 +01:00
|
|
|
};
|
2017-02-14 01:33:36 +01:00
|
|
|
|
|
|
|
} // end anonymous namespace
|
2010-12-27 16:56:22 +01:00
|
|
|
|
|
|
|
namespace llvm {
|
2017-02-14 01:33:36 +01:00
|
|
|
|
2015-11-06 15:12:17 +01:00
|
|
|
template <> struct DenseMapInfo<CIEKey> {
|
|
|
|
static CIEKey getEmptyKey() { return CIEKey::getEmptyKey(); }
|
|
|
|
static CIEKey getTombstoneKey() { return CIEKey::getTombstoneKey(); }
|
2017-02-14 01:33:36 +01:00
|
|
|
|
2015-11-06 15:12:17 +01:00
|
|
|
static unsigned getHashValue(const CIEKey &Key) {
|
2018-12-21 11:45:08 +01:00
|
|
|
return static_cast<unsigned>(hash_combine(
|
|
|
|
Key.Personality, Key.PersonalityEncoding, Key.LsdaEncoding,
|
|
|
|
Key.IsSignalFrame, Key.IsSimple, Key.RAReg, Key.IsBKeyFrame));
|
2015-11-06 15:12:17 +01:00
|
|
|
}
|
2017-02-14 01:33:36 +01:00
|
|
|
|
2015-11-06 15:12:17 +01: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 11:45:08 +01:00
|
|
|
LHS.IsSimple == RHS.IsSimple && LHS.RAReg == RHS.RAReg &&
|
|
|
|
LHS.IsBKeyFrame == RHS.IsBKeyFrame;
|
2015-11-06 15:12:17 +01:00
|
|
|
}
|
|
|
|
};
|
2017-02-14 01:33:36 +01:00
|
|
|
|
|
|
|
} // end namespace llvm
|
2010-12-27 16:56:22 +01:00
|
|
|
|
2014-05-12 16:28:48 +02:00
|
|
|
void MCDwarfFrameEmitter::Emit(MCObjectStreamer &Streamer, MCAsmBackend *MAB,
|
2014-05-12 15:34:25 +02:00
|
|
|
bool IsEH) {
|
2013-09-09 21:48:37 +02:00
|
|
|
Streamer.generateCompactUnwindEncodings(MAB);
|
|
|
|
|
2011-06-23 09:44:54 +02:00
|
|
|
MCContext &Context = Streamer.getContext();
|
2013-05-30 20:52:57 +02:00
|
|
|
const MCObjectFileInfo *MOFI = Context.getObjectFileInfo();
|
2017-04-17 19:41:25 +02:00
|
|
|
const MCAsmInfo *AsmInfo = Context.getAsmInfo();
|
2015-11-06 01:05:57 +01:00
|
|
|
FrameEmitterImpl Emitter(IsEH, Streamer);
|
2014-07-13 21:03:36 +02:00
|
|
|
ArrayRef<MCDwarfFrameInfo> FrameArray = Streamer.getDwarfFrameInfos();
|
2011-07-22 23:18:59 +02:00
|
|
|
|
2011-09-06 20:37:11 +02:00
|
|
|
// Emit the compact unwind info if available.
|
2014-03-29 10:03:13 +01:00
|
|
|
bool NeedsEHFrameSection = !MOFI->getSupportsCompactUnwindWithoutEHFrame();
|
2013-04-24 05:11:14 +02:00
|
|
|
if (IsEH && MOFI->getCompactUnwindSection()) {
|
|
|
|
bool SectionEmitted = false;
|
2016-06-26 16:49:00 +02:00
|
|
|
for (const MCDwarfFrameInfo &Frame : FrameArray) {
|
2013-05-07 22:56:33 +02:00
|
|
|
if (Frame.CompactUnwindEncoding == 0) continue;
|
|
|
|
if (!SectionEmitted) {
|
|
|
|
Streamer.SwitchSection(MOFI->getCompactUnwindSection());
|
2020-02-15 04:21:58 +01:00
|
|
|
Streamer.emitValueToAlignment(AsmInfo->getCodePointerSize());
|
2013-05-07 22:56:33 +02:00
|
|
|
SectionEmitted = true;
|
2013-04-24 05:11:14 +02:00
|
|
|
}
|
2014-03-29 10:03:13 +01:00
|
|
|
NeedsEHFrameSection |=
|
|
|
|
Frame.CompactUnwindEncoding ==
|
|
|
|
MOFI->getCompactUnwindDwarfEHFrameOnly();
|
2015-11-06 01:05:57 +01:00
|
|
|
Emitter.EmitCompactUnwind(Frame);
|
2011-07-22 23:18:59 +02:00
|
|
|
}
|
2013-04-24 05:11:14 +02:00
|
|
|
}
|
2011-07-22 23:18:59 +02:00
|
|
|
|
2014-03-29 10:03:13 +01:00
|
|
|
if (!NeedsEHFrameSection) return;
|
|
|
|
|
2015-05-21 21:20:38 +02:00
|
|
|
MCSection &Section =
|
|
|
|
IsEH ? *const_cast<MCObjectFileInfo *>(MOFI)->getEHFrameSection()
|
|
|
|
: *MOFI->getDwarfFrameSection();
|
2014-03-29 10:03:13 +01:00
|
|
|
|
2011-06-23 09:44:54 +02:00
|
|
|
Streamer.SwitchSection(&Section);
|
2015-05-18 20:43:14 +02:00
|
|
|
MCSymbol *SectionStart = Context.createTempSymbol();
|
2020-02-15 04:21:58 +01:00
|
|
|
Streamer.emitLabel(SectionStart);
|
2011-06-23 09:44:54 +02:00
|
|
|
|
2014-06-19 22:00:09 +02:00
|
|
|
DenseMap<CIEKey, const MCSymbol *> CIEStarts;
|
2010-12-26 21:20:31 +01:00
|
|
|
|
2014-04-13 06:57:38 +02:00
|
|
|
const MCSymbol *DummyDebugKey = nullptr;
|
2015-10-28 23:56:36 +01:00
|
|
|
bool CanOmitDwarf = MOFI->getOmitDwarfIfHaveCompactUnwind();
|
2019-03-15 00:08:19 +01:00
|
|
|
// Sort the FDEs by their corresponding CIE before we emit them.
|
|
|
|
// This isn't technically necessary according to the DWARF standard,
|
|
|
|
// but the Android libunwindstack rejects eh_frame sections where
|
|
|
|
// an FDE refers to a CIE other than the closest previous CIE.
|
|
|
|
std::vector<MCDwarfFrameInfo> FrameArrayX(FrameArray.begin(), FrameArray.end());
|
2019-04-23 16:51:27 +02:00
|
|
|
llvm::stable_sort(FrameArrayX,
|
|
|
|
[](const MCDwarfFrameInfo &X, const MCDwarfFrameInfo &Y) {
|
|
|
|
return CIEKey(X) < CIEKey(Y);
|
|
|
|
});
|
2019-03-15 00:08:19 +01:00
|
|
|
for (auto I = FrameArrayX.begin(), E = FrameArrayX.end(); I != E;) {
|
2015-11-06 04:02:51 +01:00
|
|
|
const MCDwarfFrameInfo &Frame = *I;
|
|
|
|
++I;
|
2015-10-28 23:56:36 +01:00
|
|
|
if (CanOmitDwarf && Frame.CompactUnwindEncoding !=
|
2014-03-29 10:03:13 +01: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-29 22:03:02 +02:00
|
|
|
CIEKey Key(Frame);
|
2011-06-23 09:44:54 +02:00
|
|
|
const MCSymbol *&CIEStart = IsEH ? CIEStarts[Key] : DummyDebugKey;
|
|
|
|
if (!CIEStart)
|
2017-07-29 22:03:02 +02:00
|
|
|
CIEStart = &Emitter.EmitCIE(Frame);
|
2011-06-23 03:06:23 +02:00
|
|
|
|
2015-11-06 14:14:59 +01:00
|
|
|
Emitter.EmitFDE(*CIEStart, Frame, I == E, *SectionStart);
|
2010-12-17 01:28:02 +01:00
|
|
|
}
|
2010-12-10 08:39:47 +01:00
|
|
|
}
|
2010-12-28 06:39:27 +01:00
|
|
|
|
2014-05-12 16:28:48 +02:00
|
|
|
void MCDwarfFrameEmitter::EmitAdvanceLoc(MCObjectStreamer &Streamer,
|
2010-12-28 06:39:27 +01:00
|
|
|
uint64_t AddrDelta) {
|
2013-06-12 16:46:54 +02:00
|
|
|
MCContext &Context = Streamer.getContext();
|
2014-06-27 00:52:05 +02:00
|
|
|
SmallString<256> Tmp;
|
|
|
|
raw_svector_ostream OS(Tmp);
|
2013-06-12 16:46:54 +02:00
|
|
|
MCDwarfFrameEmitter::EncodeAdvanceLoc(Context, AddrDelta, OS);
|
2020-02-15 03:16:24 +01:00
|
|
|
Streamer.emitBytes(OS.str());
|
2010-12-28 06:39:27 +01:00
|
|
|
}
|
|
|
|
|
2013-06-12 16:46:54 +02:00
|
|
|
void MCDwarfFrameEmitter::EncodeAdvanceLoc(MCContext &Context,
|
2019-07-19 04:03:34 +02:00
|
|
|
uint64_t AddrDelta, raw_ostream &OS,
|
|
|
|
uint32_t *Offset, uint32_t *Size) {
|
2013-06-12 16:46:54 +02:00
|
|
|
// Scale the address delta by the minimum instruction length.
|
|
|
|
AddrDelta = ScaleAddrDelta(Context, AddrDelta);
|
|
|
|
|
2019-07-19 04:03:34 +02:00
|
|
|
bool WithFixups = false;
|
|
|
|
if (Offset && Size)
|
|
|
|
WithFixups = true;
|
|
|
|
|
2018-05-18 21:46:24 +02:00
|
|
|
support::endianness E =
|
|
|
|
Context.getAsmInfo()->isLittleEndian() ? support::little : support::big;
|
2010-12-29 00:38:03 +01:00
|
|
|
if (AddrDelta == 0) {
|
2019-07-19 04:03:34 +02:00
|
|
|
if (WithFixups) {
|
|
|
|
*Offset = 0;
|
|
|
|
*Size = 0;
|
|
|
|
}
|
2011-05-08 16:35:21 +02:00
|
|
|
} else if (isUIntN(6, AddrDelta)) {
|
2010-12-28 06:39:27 +01:00
|
|
|
uint8_t Opcode = dwarf::DW_CFA_advance_loc | AddrDelta;
|
2019-07-19 04:03:34 +02:00
|
|
|
if (WithFixups) {
|
|
|
|
*Offset = OS.tell();
|
|
|
|
*Size = 6;
|
|
|
|
OS << uint8_t(dwarf::DW_CFA_advance_loc);
|
|
|
|
} else
|
|
|
|
OS << Opcode;
|
2011-05-08 16:35:21 +02:00
|
|
|
} else if (isUInt<8>(AddrDelta)) {
|
2010-12-28 06:39:27 +01:00
|
|
|
OS << uint8_t(dwarf::DW_CFA_advance_loc1);
|
2019-07-19 04:03:34 +02:00
|
|
|
if (WithFixups) {
|
|
|
|
*Offset = OS.tell();
|
|
|
|
*Size = 8;
|
|
|
|
OS.write_zeros(1);
|
|
|
|
} else
|
|
|
|
OS << uint8_t(AddrDelta);
|
2011-05-08 16:35:21 +02:00
|
|
|
} else if (isUInt<16>(AddrDelta)) {
|
2010-12-28 06:39:27 +01:00
|
|
|
OS << uint8_t(dwarf::DW_CFA_advance_loc2);
|
2019-07-19 04:03:34 +02:00
|
|
|
if (WithFixups) {
|
|
|
|
*Offset = OS.tell();
|
|
|
|
*Size = 16;
|
|
|
|
OS.write_zeros(2);
|
|
|
|
} else
|
|
|
|
support::endian::write<uint16_t>(OS, AddrDelta, E);
|
2010-12-28 06:39:27 +01:00
|
|
|
} else {
|
|
|
|
assert(isUInt<32>(AddrDelta));
|
|
|
|
OS << uint8_t(dwarf::DW_CFA_advance_loc4);
|
2019-07-19 04:03:34 +02:00
|
|
|
if (WithFixups) {
|
|
|
|
*Offset = OS.tell();
|
|
|
|
*Size = 32;
|
|
|
|
OS.write_zeros(4);
|
|
|
|
} else
|
|
|
|
support::endian::write<uint32_t>(OS, AddrDelta, E);
|
2010-12-28 06:39:27 +01:00
|
|
|
}
|
|
|
|
}
|