summaryrefslogtreecommitdiffstats
path: root/llvm/lib/MC/MCDwarf.cpp
diff options
context:
space:
mode:
authorFrederic Riss <friss@apple.com>2015-08-07 15:14:08 +0000
committerFrederic Riss <friss@apple.com>2015-08-07 15:14:08 +0000
commita5ab8443c122b6e1832e7cf6fbc8d33b8e031038 (patch)
tree534acdfc009d7d508829494b48f48aef4ab4f479 /llvm/lib/MC/MCDwarf.cpp
parent01da42d8db3263ede2c10b466daed51f4b1d43e5 (diff)
downloadbcm5719-llvm-a5ab8443c122b6e1832e7cf6fbc8d33b8e031038.tar.gz
bcm5719-llvm-a5ab8443c122b6e1832e7cf6fbc8d33b8e031038.zip
[MC/Dwarf] Allow to specify custom parameters for linetable emission.
NFC patch for current users, but llvm-dsymutil will use the new functionality to adapt to the input linetable. Based on a patch by Adrian Prantl. llvm-svn: 244318
Diffstat (limited to 'llvm/lib/MC/MCDwarf.cpp')
-rw-r--r--llvm/lib/MC/MCDwarf.cpp87
1 files changed, 42 insertions, 45 deletions
diff --git a/llvm/lib/MC/MCDwarf.cpp b/llvm/lib/MC/MCDwarf.cpp
index c84c4865f51..cfe58dae343 100644
--- a/llvm/lib/MC/MCDwarf.cpp
+++ b/llvm/lib/MC/MCDwarf.cpp
@@ -29,25 +29,6 @@
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
-// Given a special op, return the address skip amount (in units of
-// DWARF2_LINE_MIN_INSN_LENGTH.
-#define SPECIAL_ADDR(op) (((op) - DWARF2_LINE_OPCODE_BASE)/DWARF2_LINE_RANGE)
-
-// The maximum address skip amount that can be encoded with a special op.
-#define MAX_SPECIAL_ADDR_DELTA SPECIAL_ADDR(255)
-
-// First special line opcode - leave room for the standard opcodes.
-// Note: If you want to change this, you'll have to update the
-// "standard_opcode_lengths" table that is emitted in DwarfFileTable::Emit().
-#define DWARF2_LINE_OPCODE_BASE 13
-
-// Minimum line offset in a special line info. opcode. This value
-// was chosen to give a reasonable range of values.
-#define DWARF2_LINE_BASE -5
-
-// Range of line offsets in a special line info. opcode.
-#define DWARF2_LINE_RANGE 14
-
static inline uint64_t ScaleAddrDelta(MCContext &Context, uint64_t AddrDelta) {
unsigned MinInsnLength = Context.getAsmInfo()->getMinInstAlignment();
if (MinInsnLength == 1)
@@ -197,7 +178,8 @@ EmitDwarfLineTable(MCObjectStreamer *MCOS, MCSection *Section,
//
// This emits the Dwarf file and the line tables.
//
-void MCDwarfLineTable::Emit(MCObjectStreamer *MCOS) {
+void MCDwarfLineTable::Emit(MCObjectStreamer *MCOS,
+ MCDwarfLineTableParams Params) {
MCContext &context = MCOS->getContext();
auto &LineTables = context.getMCDwarfLineTables();
@@ -212,14 +194,17 @@ void MCDwarfLineTable::Emit(MCObjectStreamer *MCOS) {
// Handle the rest of the Compile Units.
for (const auto &CUIDTablePair : LineTables)
- CUIDTablePair.second.EmitCU(MCOS);
+ CUIDTablePair.second.EmitCU(MCOS, Params);
}
-void MCDwarfDwoLineTable::Emit(MCStreamer &MCOS) const {
- MCOS.EmitLabel(Header.Emit(&MCOS, None).second);
+void MCDwarfDwoLineTable::Emit(MCStreamer &MCOS,
+ MCDwarfLineTableParams Params) const {
+ MCOS.EmitLabel(Header.Emit(&MCOS, Params, None).second);
}
-std::pair<MCSymbol *, MCSymbol *> MCDwarfLineTableHeader::Emit(MCStreamer *MCOS) const {
+std::pair<MCSymbol *, MCSymbol *>
+MCDwarfLineTableHeader::Emit(MCStreamer *MCOS,
+ MCDwarfLineTableParams Params) const {
static const char StandardOpcodeLengths[] = {
0, // length of DW_LNS_copy
1, // length of DW_LNS_advance_pc
@@ -234,9 +219,10 @@ std::pair<MCSymbol *, MCSymbol *> MCDwarfLineTableHeader::Emit(MCStreamer *MCOS)
0, // length of DW_LNS_set_epilogue_begin
1 // DW_LNS_set_isa
};
- assert(array_lengthof(StandardOpcodeLengths) ==
- (DWARF2_LINE_OPCODE_BASE - 1));
- return Emit(MCOS, StandardOpcodeLengths);
+ assert(array_lengthof(StandardOpcodeLengths) >=
+ (Params.DWARF2LineOpcodeBase - 1));
+ return Emit(MCOS, Params, ArrayRef<char>(StandardOpcodeLengths,
+ Params.DWARF2LineOpcodeBase - 1));
}
static const MCExpr *forceExpAbs(MCStreamer &OS, const MCExpr* Expr) {
@@ -256,7 +242,7 @@ static void emitAbsValue(MCStreamer &OS, const MCExpr *Value, unsigned Size) {
}
std::pair<MCSymbol *, MCSymbol *>
-MCDwarfLineTableHeader::Emit(MCStreamer *MCOS,
+MCDwarfLineTableHeader::Emit(MCStreamer *MCOS, MCDwarfLineTableParams Params,
ArrayRef<char> StandardOpcodeLengths) const {
MCContext &context = MCOS->getContext();
@@ -293,8 +279,8 @@ MCDwarfLineTableHeader::Emit(MCStreamer *MCOS,
// Parameters of the state machine, are next.
MCOS->EmitIntValue(context.getAsmInfo()->getMinInstAlignment(), 1);
MCOS->EmitIntValue(DWARF2_LINE_DEFAULT_IS_STMT, 1);
- MCOS->EmitIntValue(DWARF2_LINE_BASE, 1);
- MCOS->EmitIntValue(DWARF2_LINE_RANGE, 1);
+ MCOS->EmitIntValue(Params.DWARF2LineBase, 1);
+ MCOS->EmitIntValue(Params.DWARF2LineRange, 1);
MCOS->EmitIntValue(StandardOpcodeLengths.size() + 1, 1);
// Standard opcode lengths
@@ -329,8 +315,9 @@ MCDwarfLineTableHeader::Emit(MCStreamer *MCOS,
return std::make_pair(LineStartSym, LineEndSym);
}
-void MCDwarfLineTable::EmitCU(MCObjectStreamer *MCOS) const {
- MCSymbol *LineEndSym = Header.Emit(MCOS).second;
+void MCDwarfLineTable::EmitCU(MCObjectStreamer *MCOS,
+ MCDwarfLineTableParams Params) const {
+ MCSymbol *LineEndSym = Header.Emit(MCOS, Params).second;
// Put out the line tables.
for (const auto &LineSec : MCLineSections.getMCLineEntries())
@@ -416,21 +403,31 @@ unsigned MCDwarfLineTableHeader::getFile(StringRef &Directory,
}
/// Utility function to emit the encoding to a streamer.
-void MCDwarfLineAddr::Emit(MCStreamer *MCOS, int64_t LineDelta,
- uint64_t AddrDelta) {
+void MCDwarfLineAddr::Emit(MCStreamer *MCOS, MCDwarfLineTableParams Params,
+ int64_t LineDelta, uint64_t AddrDelta) {
MCContext &Context = MCOS->getContext();
SmallString<256> Tmp;
raw_svector_ostream OS(Tmp);
- MCDwarfLineAddr::Encode(Context, LineDelta, AddrDelta, OS);
+ MCDwarfLineAddr::Encode(Context, Params, LineDelta, AddrDelta, OS);
MCOS->EmitBytes(OS.str());
}
+/// 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;
+}
+
/// Utility function to encode a Dwarf pair of LineDelta and AddrDeltas.
-void MCDwarfLineAddr::Encode(MCContext &Context, int64_t LineDelta,
- uint64_t AddrDelta, raw_ostream &OS) {
+void MCDwarfLineAddr::Encode(MCContext &Context, MCDwarfLineTableParams Params,
+ int64_t LineDelta, uint64_t AddrDelta,
+ raw_ostream &OS) {
uint64_t Temp, Opcode;
bool NeedCopy = false;
+ // The maximum address skip amount that can be encoded with a special op.
+ uint64_t MaxSpecialAddrDelta = SpecialAddr(Params, 255);
+
// Scale the address delta by the minimum instruction length.
AddrDelta = ScaleAddrDelta(Context, AddrDelta);
@@ -438,7 +435,7 @@ void MCDwarfLineAddr::Encode(MCContext &Context, int64_t LineDelta,
// DW_LNE_end_sequence. We cannot use special opcodes here, since we want the
// end_sequence to emit the matrix entry.
if (LineDelta == INT64_MAX) {
- if (AddrDelta == MAX_SPECIAL_ADDR_DELTA)
+ if (AddrDelta == MaxSpecialAddrDelta)
OS << char(dwarf::DW_LNS_const_add_pc);
else if (AddrDelta) {
OS << char(dwarf::DW_LNS_advance_pc);
@@ -451,16 +448,16 @@ void MCDwarfLineAddr::Encode(MCContext &Context, int64_t LineDelta,
}
// Bias the line delta by the base.
- Temp = LineDelta - DWARF2_LINE_BASE;
+ Temp = LineDelta - Params.DWARF2LineBase;
// If the line increment is out of range of a special opcode, we must encode
// it with DW_LNS_advance_line.
- if (Temp >= DWARF2_LINE_RANGE) {
+ if (Temp >= Params.DWARF2LineRange) {
OS << char(dwarf::DW_LNS_advance_line);
encodeSLEB128(LineDelta, OS);
LineDelta = 0;
- Temp = 0 - DWARF2_LINE_BASE;
+ Temp = 0 - Params.DWARF2LineBase;
NeedCopy = true;
}
@@ -471,19 +468,19 @@ void MCDwarfLineAddr::Encode(MCContext &Context, int64_t LineDelta,
}
// Bias the opcode by the special opcode base.
- Temp += DWARF2_LINE_OPCODE_BASE;
+ Temp += Params.DWARF2LineOpcodeBase;
// Avoid overflow when addr_delta is large.
- if (AddrDelta < 256 + MAX_SPECIAL_ADDR_DELTA) {
+ if (AddrDelta < 256 + MaxSpecialAddrDelta) {
// Try using a special opcode.
- Opcode = Temp + AddrDelta * DWARF2_LINE_RANGE;
+ Opcode = Temp + AddrDelta * Params.DWARF2LineRange;
if (Opcode <= 255) {
OS << char(Opcode);
return;
}
// Try using DW_LNS_const_add_pc followed by special op.
- Opcode = Temp + (AddrDelta - MAX_SPECIAL_ADDR_DELTA) * DWARF2_LINE_RANGE;
+ Opcode = Temp + (AddrDelta - MaxSpecialAddrDelta) * Params.DWARF2LineRange;
if (Opcode <= 255) {
OS << char(dwarf::DW_LNS_const_add_pc);
OS << char(Opcode);
OpenPOWER on IntegriCloud