Kevin Enderby | 7cbf73a | 2010-07-28 20:55:35 +0000 | [diff] [blame] | 1 | //===- lib/MC/MCDwarf.cpp - MCDwarf implementation ------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "llvm/MC/MCDwarf.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 11 | #include "llvm/ADT/Hashing.h" |
| 12 | #include "llvm/ADT/SmallString.h" |
| 13 | #include "llvm/ADT/Twine.h" |
| 14 | #include "llvm/Config/config.h" |
Evan Cheng | e76a33b | 2011-07-20 05:58:47 +0000 | [diff] [blame] | 15 | #include "llvm/MC/MCAsmInfo.h" |
| 16 | #include "llvm/MC/MCContext.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 17 | #include "llvm/MC/MCExpr.h" |
Evan Cheng | e76a33b | 2011-07-20 05:58:47 +0000 | [diff] [blame] | 18 | #include "llvm/MC/MCObjectFileInfo.h" |
| 19 | #include "llvm/MC/MCObjectWriter.h" |
| 20 | #include "llvm/MC/MCRegisterInfo.h" |
Rafael Espindola | ad8aaa0 | 2010-11-22 11:53:17 +0000 | [diff] [blame] | 21 | #include "llvm/MC/MCStreamer.h" |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 22 | #include "llvm/MC/MCSymbol.h" |
Kevin Enderby | 7cbf73a | 2010-07-28 20:55:35 +0000 | [diff] [blame] | 23 | #include "llvm/Support/Debug.h" |
Rafael Espindola | fe024d0 | 2010-12-28 18:36:23 +0000 | [diff] [blame] | 24 | #include "llvm/Support/ErrorHandling.h" |
Jim Grosbach | 2d39a0e | 2012-08-08 23:56:06 +0000 | [diff] [blame] | 25 | #include "llvm/Support/LEB128.h" |
Kevin Enderby | 94c2e85 | 2011-12-09 18:09:40 +0000 | [diff] [blame] | 26 | #include "llvm/Support/Path.h" |
| 27 | #include "llvm/Support/SourceMgr.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 28 | #include "llvm/Support/raw_ostream.h" |
Kevin Enderby | 7cbf73a | 2010-07-28 20:55:35 +0000 | [diff] [blame] | 29 | using namespace llvm; |
| 30 | |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 31 | // Given a special op, return the address skip amount (in units of |
| 32 | // DWARF2_LINE_MIN_INSN_LENGTH. |
| 33 | #define SPECIAL_ADDR(op) (((op) - DWARF2_LINE_OPCODE_BASE)/DWARF2_LINE_RANGE) |
| 34 | |
| 35 | // The maximum address skip amount that can be encoded with a special op. |
Bill Wendling | c388216 | 2011-06-30 23:59:38 +0000 | [diff] [blame] | 36 | #define MAX_SPECIAL_ADDR_DELTA SPECIAL_ADDR(255) |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 37 | |
| 38 | // First special line opcode - leave room for the standard opcodes. |
| 39 | // Note: If you want to change this, you'll have to update the |
Jim Grosbach | 2684d9e | 2012-05-11 01:41:30 +0000 | [diff] [blame] | 40 | // "standard_opcode_lengths" table that is emitted in DwarfFileTable::Emit(). |
Bill Wendling | c388216 | 2011-06-30 23:59:38 +0000 | [diff] [blame] | 41 | #define DWARF2_LINE_OPCODE_BASE 13 |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 42 | |
| 43 | // Minimum line offset in a special line info. opcode. This value |
| 44 | // was chosen to give a reasonable range of values. |
Bill Wendling | c388216 | 2011-06-30 23:59:38 +0000 | [diff] [blame] | 45 | #define DWARF2_LINE_BASE -5 |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 46 | |
| 47 | // Range of line offsets in a special line info. opcode. |
Bill Wendling | c388216 | 2011-06-30 23:59:38 +0000 | [diff] [blame] | 48 | #define DWARF2_LINE_RANGE 14 |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 49 | |
| 50 | // Define the architecture-dependent minimum instruction length (in bytes). |
| 51 | // This value should be rather too small than too big. |
Bill Wendling | c388216 | 2011-06-30 23:59:38 +0000 | [diff] [blame] | 52 | #define DWARF2_LINE_MIN_INSN_LENGTH 1 |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 53 | |
| 54 | // Note: when DWARF2_LINE_MIN_INSN_LENGTH == 1 which is the current setting, |
| 55 | // this routine is a nop and will be optimized away. |
Bill Wendling | a8c9e6a | 2011-06-23 07:44:54 +0000 | [diff] [blame] | 56 | static inline uint64_t ScaleAddrDelta(uint64_t AddrDelta) { |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 57 | if (DWARF2_LINE_MIN_INSN_LENGTH == 1) |
| 58 | return AddrDelta; |
| 59 | if (AddrDelta % DWARF2_LINE_MIN_INSN_LENGTH != 0) { |
| 60 | // TODO: report this error, but really only once. |
| 61 | ; |
| 62 | } |
| 63 | return AddrDelta / DWARF2_LINE_MIN_INSN_LENGTH; |
| 64 | } |
| 65 | |
| 66 | // |
| 67 | // This is called when an instruction is assembled into the specified section |
| 68 | // and if there is information from the last .loc directive that has yet to have |
| 69 | // a line entry made for it is made. |
| 70 | // |
Rafael Espindola | 195a0ce | 2010-11-19 02:26:16 +0000 | [diff] [blame] | 71 | void MCLineEntry::Make(MCStreamer *MCOS, const MCSection *Section) { |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 72 | if (!MCOS->getContext().getDwarfLocSeen()) |
| 73 | return; |
| 74 | |
| 75 | // Create a symbol at in the current section for use in the line entry. |
| 76 | MCSymbol *LineSym = MCOS->getContext().CreateTempSymbol(); |
| 77 | // Set the value of the symbol to use for the MCLineEntry. |
| 78 | MCOS->EmitLabel(LineSym); |
| 79 | |
| 80 | // Get the current .loc info saved in the context. |
| 81 | const MCDwarfLoc &DwarfLoc = MCOS->getContext().getCurrentDwarfLoc(); |
| 82 | |
| 83 | // Create a (local) line entry with the symbol and the current .loc info. |
| 84 | MCLineEntry LineEntry(LineSym, DwarfLoc); |
| 85 | |
| 86 | // clear DwarfLocSeen saying the current .loc info is now used. |
Kevin Enderby | 3f55c24 | 2010-10-04 20:17:24 +0000 | [diff] [blame] | 87 | MCOS->getContext().ClearDwarfLocSeen(); |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 88 | |
| 89 | // Get the MCLineSection for this section, if one does not exist for this |
| 90 | // section create it. |
Rafael Espindola | 17fd7bd | 2010-11-19 07:41:23 +0000 | [diff] [blame] | 91 | const DenseMap<const MCSection *, MCLineSection *> &MCLineSections = |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 92 | MCOS->getContext().getMCLineSections(); |
Rafael Espindola | 17fd7bd | 2010-11-19 07:41:23 +0000 | [diff] [blame] | 93 | MCLineSection *LineSection = MCLineSections.lookup(Section); |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 94 | if (!LineSection) { |
| 95 | // Create a new MCLineSection. This will be deleted after the dwarf line |
| 96 | // table is created using it by iterating through the MCLineSections |
| 97 | // DenseMap. |
| 98 | LineSection = new MCLineSection; |
| 99 | // Save a pointer to the new LineSection into the MCLineSections DenseMap. |
Rafael Espindola | 17fd7bd | 2010-11-19 07:41:23 +0000 | [diff] [blame] | 100 | MCOS->getContext().addMCLineSection(Section, LineSection); |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | // Add the line entry to this section's entries. |
Manman Ren | 43213cf | 2013-02-05 21:52:47 +0000 | [diff] [blame] | 104 | LineSection->addLineEntry(LineEntry, |
| 105 | MCOS->getContext().getDwarfCompileUnitID()); |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | // |
| 109 | // This helper routine returns an expression of End - Start + IntVal . |
Jim Grosbach | 2684d9e | 2012-05-11 01:41:30 +0000 | [diff] [blame] | 110 | // |
Rafael Espindola | 5fad7a9 | 2010-12-09 23:08:35 +0000 | [diff] [blame] | 111 | static inline const MCExpr *MakeStartMinusEndExpr(const MCStreamer &MCOS, |
| 112 | const MCSymbol &Start, |
| 113 | const MCSymbol &End, |
| 114 | int IntVal) { |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 115 | MCSymbolRefExpr::VariantKind Variant = MCSymbolRefExpr::VK_None; |
| 116 | const MCExpr *Res = |
Rafael Espindola | 5fad7a9 | 2010-12-09 23:08:35 +0000 | [diff] [blame] | 117 | MCSymbolRefExpr::Create(&End, Variant, MCOS.getContext()); |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 118 | const MCExpr *RHS = |
Rafael Espindola | 5fad7a9 | 2010-12-09 23:08:35 +0000 | [diff] [blame] | 119 | MCSymbolRefExpr::Create(&Start, Variant, MCOS.getContext()); |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 120 | const MCExpr *Res1 = |
Rafael Espindola | 5fad7a9 | 2010-12-09 23:08:35 +0000 | [diff] [blame] | 121 | MCBinaryExpr::Create(MCBinaryExpr::Sub, Res, RHS, MCOS.getContext()); |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 122 | const MCExpr *Res2 = |
Rafael Espindola | 5fad7a9 | 2010-12-09 23:08:35 +0000 | [diff] [blame] | 123 | MCConstantExpr::Create(IntVal, MCOS.getContext()); |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 124 | const MCExpr *Res3 = |
Rafael Espindola | 5fad7a9 | 2010-12-09 23:08:35 +0000 | [diff] [blame] | 125 | MCBinaryExpr::Create(MCBinaryExpr::Sub, Res1, Res2, MCOS.getContext()); |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 126 | return Res3; |
| 127 | } |
| 128 | |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 129 | // |
| 130 | // This emits the Dwarf line table for the specified section from the entries |
| 131 | // in the LineSection. |
| 132 | // |
Rafael Espindola | 195a0ce | 2010-11-19 02:26:16 +0000 | [diff] [blame] | 133 | static inline void EmitDwarfLineTable(MCStreamer *MCOS, |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 134 | const MCSection *Section, |
Manman Ren | 43213cf | 2013-02-05 21:52:47 +0000 | [diff] [blame] | 135 | const MCLineSection *LineSection, |
| 136 | unsigned CUID) { |
| 137 | // This LineSection does not contain any LineEntry for the given Compile Unit. |
| 138 | if (!LineSection->containEntriesForID(CUID)) |
| 139 | return; |
| 140 | |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 141 | unsigned FileNum = 1; |
| 142 | unsigned LastLine = 1; |
| 143 | unsigned Column = 0; |
| 144 | unsigned Flags = DWARF2_LINE_DEFAULT_IS_STMT ? DWARF2_FLAG_IS_STMT : 0; |
| 145 | unsigned Isa = 0; |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 146 | MCSymbol *LastLabel = NULL; |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 147 | |
| 148 | // Loop through each MCLineEntry and encode the dwarf line number table. |
Rafael Espindola | 17fd7bd | 2010-11-19 07:41:23 +0000 | [diff] [blame] | 149 | for (MCLineSection::const_iterator |
Manman Ren | 43213cf | 2013-02-05 21:52:47 +0000 | [diff] [blame] | 150 | it = LineSection->getMCLineEntries(CUID).begin(), |
| 151 | ie = LineSection->getMCLineEntries(CUID).end(); it != ie; ++it) { |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 152 | |
| 153 | if (FileNum != it->getFileNum()) { |
| 154 | FileNum = it->getFileNum(); |
| 155 | MCOS->EmitIntValue(dwarf::DW_LNS_set_file, 1); |
Rafael Espindola | 3ff5709 | 2010-11-02 17:22:24 +0000 | [diff] [blame] | 156 | MCOS->EmitULEB128IntValue(FileNum); |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 157 | } |
| 158 | if (Column != it->getColumn()) { |
| 159 | Column = it->getColumn(); |
| 160 | MCOS->EmitIntValue(dwarf::DW_LNS_set_column, 1); |
Rafael Espindola | 3ff5709 | 2010-11-02 17:22:24 +0000 | [diff] [blame] | 161 | MCOS->EmitULEB128IntValue(Column); |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 162 | } |
| 163 | if (Isa != it->getIsa()) { |
| 164 | Isa = it->getIsa(); |
| 165 | MCOS->EmitIntValue(dwarf::DW_LNS_set_isa, 1); |
Rafael Espindola | 3ff5709 | 2010-11-02 17:22:24 +0000 | [diff] [blame] | 166 | MCOS->EmitULEB128IntValue(Isa); |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 167 | } |
| 168 | if ((it->getFlags() ^ Flags) & DWARF2_FLAG_IS_STMT) { |
| 169 | Flags = it->getFlags(); |
| 170 | MCOS->EmitIntValue(dwarf::DW_LNS_negate_stmt, 1); |
| 171 | } |
| 172 | if (it->getFlags() & DWARF2_FLAG_BASIC_BLOCK) |
| 173 | MCOS->EmitIntValue(dwarf::DW_LNS_set_basic_block, 1); |
| 174 | if (it->getFlags() & DWARF2_FLAG_PROLOGUE_END) |
| 175 | MCOS->EmitIntValue(dwarf::DW_LNS_set_prologue_end, 1); |
| 176 | if (it->getFlags() & DWARF2_FLAG_EPILOGUE_BEGIN) |
| 177 | MCOS->EmitIntValue(dwarf::DW_LNS_set_epilogue_begin, 1); |
| 178 | |
Rafael Espindola | 64185cc | 2010-11-13 01:06:27 +0000 | [diff] [blame] | 179 | int64_t LineDelta = static_cast<int64_t>(it->getLine()) - LastLine; |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 180 | MCSymbol *Label = it->getLabel(); |
| 181 | |
| 182 | // At this point we want to emit/create the sequence to encode the delta in |
| 183 | // line numbers and the increment of the address from the previous Label |
| 184 | // and the current Label. |
Evan Cheng | 1be0e27 | 2011-07-15 02:09:41 +0000 | [diff] [blame] | 185 | const MCAsmInfo &asmInfo = MCOS->getContext().getAsmInfo(); |
Evan Cheng | 672b93a | 2011-07-14 05:43:07 +0000 | [diff] [blame] | 186 | MCOS->EmitDwarfAdvanceLineAddr(LineDelta, LastLabel, Label, |
| 187 | asmInfo.getPointerSize()); |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 188 | |
| 189 | LastLine = it->getLine(); |
| 190 | LastLabel = Label; |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | // Emit a DW_LNE_end_sequence for the end of the section. |
| 194 | // Using the pointer Section create a temporary label at the end of the |
| 195 | // section and use that and the LastLabel to compute the address delta |
| 196 | // and use INT64_MAX as the line delta which is the signal that this is |
| 197 | // actually a DW_LNE_end_sequence. |
| 198 | |
| 199 | // Switch to the section to be able to create a symbol at its end. |
| 200 | MCOS->SwitchSection(Section); |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 201 | |
| 202 | MCContext &context = MCOS->getContext(); |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 203 | // Create a symbol at the end of the section. |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 204 | MCSymbol *SectionEnd = context.CreateTempSymbol(); |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 205 | // Set the value of the symbol, as we are at the end of the section. |
| 206 | MCOS->EmitLabel(SectionEnd); |
| 207 | |
Sylvestre Ledru | c8e41c5 | 2012-07-23 08:51:15 +0000 | [diff] [blame] | 208 | // Switch back the dwarf line section. |
Evan Cheng | e76a33b | 2011-07-20 05:58:47 +0000 | [diff] [blame] | 209 | MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfLineSection()); |
Rafael Espindola | 195a0ce | 2010-11-19 02:26:16 +0000 | [diff] [blame] | 210 | |
Evan Cheng | 1be0e27 | 2011-07-15 02:09:41 +0000 | [diff] [blame] | 211 | const MCAsmInfo &asmInfo = MCOS->getContext().getAsmInfo(); |
Evan Cheng | 672b93a | 2011-07-14 05:43:07 +0000 | [diff] [blame] | 212 | MCOS->EmitDwarfAdvanceLineAddr(INT64_MAX, LastLabel, SectionEnd, |
| 213 | asmInfo.getPointerSize()); |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | // |
| 217 | // This emits the Dwarf file and the line tables. |
| 218 | // |
Rafael Espindola | 489d679 | 2012-02-28 21:13:05 +0000 | [diff] [blame] | 219 | const MCSymbol *MCDwarfFileTable::Emit(MCStreamer *MCOS) { |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 220 | MCContext &context = MCOS->getContext(); |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 221 | // Switch to the section where the table will be emitted into. |
Evan Cheng | e76a33b | 2011-07-20 05:58:47 +0000 | [diff] [blame] | 222 | MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfLineSection()); |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 223 | |
Manman Ren | 43213cf | 2013-02-05 21:52:47 +0000 | [diff] [blame] | 224 | const DenseMap<unsigned, MCSymbol *> &MCLineTableSymbols = |
| 225 | MCOS->getContext().getMCLineTableSymbols(); |
| 226 | // CUID and MCLineTableSymbols are set in DwarfDebug, when DwarfDebug does |
| 227 | // not exist, CUID will be 0 and MCLineTableSymbols will be empty. |
| 228 | // Handle Compile Unit 0, the line table start symbol is the section symbol. |
| 229 | const MCSymbol *LineStartSym = EmitCU(MCOS, 0); |
| 230 | // Handle the rest of the Compile Units. |
| 231 | for (unsigned Is = 1, Ie = MCLineTableSymbols.size(); Is < Ie; Is++) |
| 232 | EmitCU(MCOS, Is); |
| 233 | |
| 234 | // Now delete the MCLineSections that were created in MCLineEntry::Make() |
| 235 | // and used to emit the line table. |
| 236 | const DenseMap<const MCSection *, MCLineSection *> &MCLineSections = |
| 237 | MCOS->getContext().getMCLineSections(); |
| 238 | for (DenseMap<const MCSection *, MCLineSection *>::const_iterator it = |
| 239 | MCLineSections.begin(), ie = MCLineSections.end(); it != ie; |
| 240 | ++it) |
| 241 | delete it->second; |
| 242 | |
| 243 | return LineStartSym; |
| 244 | } |
| 245 | |
| 246 | const MCSymbol *MCDwarfFileTable::EmitCU(MCStreamer *MCOS, unsigned CUID) { |
| 247 | MCContext &context = MCOS->getContext(); |
| 248 | |
| 249 | // Create a symbol at the beginning of the line table. |
| 250 | MCSymbol *LineStartSym = MCOS->getContext().getMCLineTableSymbol(CUID); |
| 251 | if (!LineStartSym) |
| 252 | LineStartSym = context.CreateTempSymbol(); |
| 253 | // Set the value of the symbol, as we are at the start of the line table. |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 254 | MCOS->EmitLabel(LineStartSym); |
| 255 | |
| 256 | // Create a symbol for the end of the section (to be set when we get there). |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 257 | MCSymbol *LineEndSym = context.CreateTempSymbol(); |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 258 | |
| 259 | // The first 4 bytes is the total length of the information for this |
| 260 | // compilation unit (not including these 4 bytes for the length). |
Rafael Espindola | 5fad7a9 | 2010-12-09 23:08:35 +0000 | [diff] [blame] | 261 | MCOS->EmitAbsValue(MakeStartMinusEndExpr(*MCOS, *LineStartSym, *LineEndSym,4), |
Rafael Espindola | 0bbe0b4 | 2010-12-06 17:27:56 +0000 | [diff] [blame] | 262 | 4); |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 263 | |
| 264 | // Next 2 bytes is the Version, which is Dwarf 2. |
| 265 | MCOS->EmitIntValue(2, 2); |
| 266 | |
| 267 | // Create a symbol for the end of the prologue (to be set when we get there). |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 268 | MCSymbol *ProEndSym = context.CreateTempSymbol(); // Lprologue_end |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 269 | |
| 270 | // Length of the prologue, is the next 4 bytes. Which is the start of the |
| 271 | // section to the end of the prologue. Not including the 4 bytes for the |
| 272 | // total length, the 2 bytes for the version, and these 4 bytes for the |
| 273 | // length of the prologue. |
Rafael Espindola | 5fad7a9 | 2010-12-09 23:08:35 +0000 | [diff] [blame] | 274 | MCOS->EmitAbsValue(MakeStartMinusEndExpr(*MCOS, *LineStartSym, *ProEndSym, |
Eric Christopher | e0501e8 | 2013-02-07 21:19:56 +0000 | [diff] [blame] | 275 | (4 + 2 + 4)), 4, 0); |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 276 | |
| 277 | // Parameters of the state machine, are next. |
| 278 | MCOS->EmitIntValue(DWARF2_LINE_MIN_INSN_LENGTH, 1); |
| 279 | MCOS->EmitIntValue(DWARF2_LINE_DEFAULT_IS_STMT, 1); |
| 280 | MCOS->EmitIntValue(DWARF2_LINE_BASE, 1); |
| 281 | MCOS->EmitIntValue(DWARF2_LINE_RANGE, 1); |
| 282 | MCOS->EmitIntValue(DWARF2_LINE_OPCODE_BASE, 1); |
| 283 | |
| 284 | // Standard opcode lengths |
| 285 | MCOS->EmitIntValue(0, 1); // length of DW_LNS_copy |
| 286 | MCOS->EmitIntValue(1, 1); // length of DW_LNS_advance_pc |
| 287 | MCOS->EmitIntValue(1, 1); // length of DW_LNS_advance_line |
| 288 | MCOS->EmitIntValue(1, 1); // length of DW_LNS_set_file |
| 289 | MCOS->EmitIntValue(1, 1); // length of DW_LNS_set_column |
| 290 | MCOS->EmitIntValue(0, 1); // length of DW_LNS_negate_stmt |
| 291 | MCOS->EmitIntValue(0, 1); // length of DW_LNS_set_basic_block |
| 292 | MCOS->EmitIntValue(0, 1); // length of DW_LNS_const_add_pc |
| 293 | MCOS->EmitIntValue(1, 1); // length of DW_LNS_fixed_advance_pc |
| 294 | MCOS->EmitIntValue(0, 1); // length of DW_LNS_set_prologue_end |
| 295 | MCOS->EmitIntValue(0, 1); // length of DW_LNS_set_epilogue_begin |
| 296 | MCOS->EmitIntValue(1, 1); // DW_LNS_set_isa |
| 297 | |
| 298 | // Put out the directory and file tables. |
| 299 | |
| 300 | // First the directory table. |
| 301 | const std::vector<StringRef> &MCDwarfDirs = |
Manman Ren | 3de61b4 | 2013-03-07 01:42:00 +0000 | [diff] [blame] | 302 | context.getMCDwarfDirs(CUID); |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 303 | for (unsigned i = 0; i < MCDwarfDirs.size(); i++) { |
Eric Christopher | 68ca562 | 2013-01-09 01:57:54 +0000 | [diff] [blame] | 304 | MCOS->EmitBytes(MCDwarfDirs[i]); // the DirectoryName |
| 305 | MCOS->EmitBytes(StringRef("\0", 1)); // the null term. of the string |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 306 | } |
| 307 | MCOS->EmitIntValue(0, 1); // Terminate the directory list |
| 308 | |
| 309 | // Second the file table. |
| 310 | const std::vector<MCDwarfFile *> &MCDwarfFiles = |
Manman Ren | 3de61b4 | 2013-03-07 01:42:00 +0000 | [diff] [blame] | 311 | MCOS->getContext().getMCDwarfFiles(CUID); |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 312 | for (unsigned i = 1; i < MCDwarfFiles.size(); i++) { |
Eric Christopher | 68ca562 | 2013-01-09 01:57:54 +0000 | [diff] [blame] | 313 | MCOS->EmitBytes(MCDwarfFiles[i]->getName()); // FileName |
| 314 | MCOS->EmitBytes(StringRef("\0", 1)); // the null term. of the string |
Rafael Espindola | 3ff5709 | 2010-11-02 17:22:24 +0000 | [diff] [blame] | 315 | // the Directory num |
| 316 | MCOS->EmitULEB128IntValue(MCDwarfFiles[i]->getDirIndex()); |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 317 | MCOS->EmitIntValue(0, 1); // last modification timestamp (always 0) |
| 318 | MCOS->EmitIntValue(0, 1); // filesize (always 0) |
| 319 | } |
| 320 | MCOS->EmitIntValue(0, 1); // Terminate the file list |
| 321 | |
| 322 | // This is the end of the prologue, so set the value of the symbol at the |
| 323 | // end of the prologue (that was used in a previous expression). |
| 324 | MCOS->EmitLabel(ProEndSym); |
| 325 | |
| 326 | // Put out the line tables. |
Rafael Espindola | 17fd7bd | 2010-11-19 07:41:23 +0000 | [diff] [blame] | 327 | const DenseMap<const MCSection *, MCLineSection *> &MCLineSections = |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 328 | MCOS->getContext().getMCLineSections(); |
Rafael Espindola | 17fd7bd | 2010-11-19 07:41:23 +0000 | [diff] [blame] | 329 | const std::vector<const MCSection *> &MCLineSectionOrder = |
| 330 | MCOS->getContext().getMCLineSectionOrder(); |
| 331 | for (std::vector<const MCSection*>::const_iterator it = |
Bill Wendling | c388216 | 2011-06-30 23:59:38 +0000 | [diff] [blame] | 332 | MCLineSectionOrder.begin(), ie = MCLineSectionOrder.end(); it != ie; |
Rafael Espindola | 17fd7bd | 2010-11-19 07:41:23 +0000 | [diff] [blame] | 333 | ++it) { |
| 334 | const MCSection *Sec = *it; |
| 335 | const MCLineSection *Line = MCLineSections.lookup(Sec); |
Manman Ren | 43213cf | 2013-02-05 21:52:47 +0000 | [diff] [blame] | 336 | EmitDwarfLineTable(MCOS, Sec, Line, CUID); |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 337 | } |
| 338 | |
Rafael Espindola | 767b1be | 2010-12-04 00:31:13 +0000 | [diff] [blame] | 339 | if (MCOS->getContext().getAsmInfo().getLinkerRequiresNonEmptyDwarfLines() |
| 340 | && MCLineSectionOrder.begin() == MCLineSectionOrder.end()) { |
Rafael Espindola | a8de83c | 2010-12-03 23:36:59 +0000 | [diff] [blame] | 341 | // The darwin9 linker has a bug (see PR8715). For for 32-bit architectures |
Jim Grosbach | 2684d9e | 2012-05-11 01:41:30 +0000 | [diff] [blame] | 342 | // it requires: |
Rafael Espindola | a8de83c | 2010-12-03 23:36:59 +0000 | [diff] [blame] | 343 | // total_length >= prologue_length + 10 |
| 344 | // We are 4 bytes short, since we have total_length = 51 and |
| 345 | // prologue_length = 45 |
Devang Patel | 5113cdb | 2010-12-03 00:10:48 +0000 | [diff] [blame] | 346 | |
Rafael Espindola | a8de83c | 2010-12-03 23:36:59 +0000 | [diff] [blame] | 347 | // The regular end_sequence should be sufficient. |
| 348 | MCDwarfLineAddr::Emit(MCOS, INT64_MAX, 0); |
Devang Patel | 5113cdb | 2010-12-03 00:10:48 +0000 | [diff] [blame] | 349 | } |
| 350 | |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 351 | // This is the end of the section, so set the value of the symbol at the end |
| 352 | // of this section (that was used in a previous expression). |
| 353 | MCOS->EmitLabel(LineEndSym); |
Rafael Espindola | 489d679 | 2012-02-28 21:13:05 +0000 | [diff] [blame] | 354 | |
| 355 | return LineStartSym; |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 356 | } |
| 357 | |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 358 | /// Utility function to write the encoding to an object writer. |
| 359 | void MCDwarfLineAddr::Write(MCObjectWriter *OW, int64_t LineDelta, |
| 360 | uint64_t AddrDelta) { |
| 361 | SmallString<256> Tmp; |
| 362 | raw_svector_ostream OS(Tmp); |
| 363 | MCDwarfLineAddr::Encode(LineDelta, AddrDelta, OS); |
| 364 | OW->WriteBytes(OS.str()); |
| 365 | } |
| 366 | |
| 367 | /// Utility function to emit the encoding to a streamer. |
Rafael Espindola | 195a0ce | 2010-11-19 02:26:16 +0000 | [diff] [blame] | 368 | void MCDwarfLineAddr::Emit(MCStreamer *MCOS, int64_t LineDelta, |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 369 | uint64_t AddrDelta) { |
| 370 | SmallString<256> Tmp; |
| 371 | raw_svector_ostream OS(Tmp); |
| 372 | MCDwarfLineAddr::Encode(LineDelta, AddrDelta, OS); |
Eric Christopher | 68ca562 | 2013-01-09 01:57:54 +0000 | [diff] [blame] | 373 | MCOS->EmitBytes(OS.str()); |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | /// Utility function to encode a Dwarf pair of LineDelta and AddrDeltas. |
| 377 | void MCDwarfLineAddr::Encode(int64_t LineDelta, uint64_t AddrDelta, |
| 378 | raw_ostream &OS) { |
| 379 | uint64_t Temp, Opcode; |
| 380 | bool NeedCopy = false; |
| 381 | |
| 382 | // Scale the address delta by the minimum instruction length. |
| 383 | AddrDelta = ScaleAddrDelta(AddrDelta); |
| 384 | |
| 385 | // A LineDelta of INT64_MAX is a signal that this is actually a |
Jim Grosbach | 2684d9e | 2012-05-11 01:41:30 +0000 | [diff] [blame] | 386 | // DW_LNE_end_sequence. We cannot use special opcodes here, since we want the |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 387 | // end_sequence to emit the matrix entry. |
| 388 | if (LineDelta == INT64_MAX) { |
| 389 | if (AddrDelta == MAX_SPECIAL_ADDR_DELTA) |
| 390 | OS << char(dwarf::DW_LNS_const_add_pc); |
| 391 | else { |
| 392 | OS << char(dwarf::DW_LNS_advance_pc); |
Jim Grosbach | 2d39a0e | 2012-08-08 23:56:06 +0000 | [diff] [blame] | 393 | encodeULEB128(AddrDelta, OS); |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 394 | } |
| 395 | OS << char(dwarf::DW_LNS_extended_op); |
| 396 | OS << char(1); |
| 397 | OS << char(dwarf::DW_LNE_end_sequence); |
| 398 | return; |
| 399 | } |
| 400 | |
| 401 | // Bias the line delta by the base. |
| 402 | Temp = LineDelta - DWARF2_LINE_BASE; |
| 403 | |
| 404 | // If the line increment is out of range of a special opcode, we must encode |
| 405 | // it with DW_LNS_advance_line. |
| 406 | if (Temp >= DWARF2_LINE_RANGE) { |
| 407 | OS << char(dwarf::DW_LNS_advance_line); |
Jim Grosbach | 2d39a0e | 2012-08-08 23:56:06 +0000 | [diff] [blame] | 408 | encodeSLEB128(LineDelta, OS); |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 409 | |
| 410 | LineDelta = 0; |
| 411 | Temp = 0 - DWARF2_LINE_BASE; |
| 412 | NeedCopy = true; |
| 413 | } |
| 414 | |
| 415 | // Use DW_LNS_copy instead of a "line +0, addr +0" special opcode. |
| 416 | if (LineDelta == 0 && AddrDelta == 0) { |
| 417 | OS << char(dwarf::DW_LNS_copy); |
| 418 | return; |
| 419 | } |
| 420 | |
| 421 | // Bias the opcode by the special opcode base. |
| 422 | Temp += DWARF2_LINE_OPCODE_BASE; |
| 423 | |
| 424 | // Avoid overflow when addr_delta is large. |
| 425 | if (AddrDelta < 256 + MAX_SPECIAL_ADDR_DELTA) { |
| 426 | // Try using a special opcode. |
| 427 | Opcode = Temp + AddrDelta * DWARF2_LINE_RANGE; |
| 428 | if (Opcode <= 255) { |
| 429 | OS << char(Opcode); |
| 430 | return; |
| 431 | } |
| 432 | |
| 433 | // Try using DW_LNS_const_add_pc followed by special op. |
| 434 | Opcode = Temp + (AddrDelta - MAX_SPECIAL_ADDR_DELTA) * DWARF2_LINE_RANGE; |
| 435 | if (Opcode <= 255) { |
| 436 | OS << char(dwarf::DW_LNS_const_add_pc); |
| 437 | OS << char(Opcode); |
| 438 | return; |
| 439 | } |
| 440 | } |
| 441 | |
| 442 | // Otherwise use DW_LNS_advance_pc. |
| 443 | OS << char(dwarf::DW_LNS_advance_pc); |
Jim Grosbach | 2d39a0e | 2012-08-08 23:56:06 +0000 | [diff] [blame] | 444 | encodeULEB128(AddrDelta, OS); |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 445 | |
| 446 | if (NeedCopy) |
| 447 | OS << char(dwarf::DW_LNS_copy); |
| 448 | else |
| 449 | OS << char(Temp); |
| 450 | } |
| 451 | |
Kevin Enderby | 7cbf73a | 2010-07-28 20:55:35 +0000 | [diff] [blame] | 452 | void MCDwarfFile::print(raw_ostream &OS) const { |
| 453 | OS << '"' << getName() << '"'; |
| 454 | } |
| 455 | |
Manman Ren | 286c4dc | 2012-09-12 05:06:18 +0000 | [diff] [blame] | 456 | #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) |
Kevin Enderby | 7cbf73a | 2010-07-28 20:55:35 +0000 | [diff] [blame] | 457 | void MCDwarfFile::dump() const { |
| 458 | print(dbgs()); |
| 459 | } |
Manman Ren | cc77eec | 2012-09-06 19:55:56 +0000 | [diff] [blame] | 460 | #endif |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 461 | |
Kevin Enderby | 94c2e85 | 2011-12-09 18:09:40 +0000 | [diff] [blame] | 462 | // Utility function to write a tuple for .debug_abbrev. |
| 463 | static void EmitAbbrev(MCStreamer *MCOS, uint64_t Name, uint64_t Form) { |
| 464 | MCOS->EmitULEB128IntValue(Name); |
| 465 | MCOS->EmitULEB128IntValue(Form); |
| 466 | } |
| 467 | |
| 468 | // When generating dwarf for assembly source files this emits |
| 469 | // the data for .debug_abbrev section which contains three DIEs. |
| 470 | static void EmitGenDwarfAbbrev(MCStreamer *MCOS) { |
| 471 | MCContext &context = MCOS->getContext(); |
| 472 | MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfAbbrevSection()); |
| 473 | |
| 474 | // DW_TAG_compile_unit DIE abbrev (1). |
| 475 | MCOS->EmitULEB128IntValue(1); |
| 476 | MCOS->EmitULEB128IntValue(dwarf::DW_TAG_compile_unit); |
| 477 | MCOS->EmitIntValue(dwarf::DW_CHILDREN_yes, 1); |
| 478 | EmitAbbrev(MCOS, dwarf::DW_AT_stmt_list, dwarf::DW_FORM_data4); |
| 479 | EmitAbbrev(MCOS, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr); |
| 480 | EmitAbbrev(MCOS, dwarf::DW_AT_high_pc, dwarf::DW_FORM_addr); |
| 481 | EmitAbbrev(MCOS, dwarf::DW_AT_name, dwarf::DW_FORM_string); |
| 482 | EmitAbbrev(MCOS, dwarf::DW_AT_comp_dir, dwarf::DW_FORM_string); |
| 483 | StringRef DwarfDebugFlags = context.getDwarfDebugFlags(); |
| 484 | if (!DwarfDebugFlags.empty()) |
| 485 | EmitAbbrev(MCOS, dwarf::DW_AT_APPLE_flags, dwarf::DW_FORM_string); |
| 486 | EmitAbbrev(MCOS, dwarf::DW_AT_producer, dwarf::DW_FORM_string); |
| 487 | EmitAbbrev(MCOS, dwarf::DW_AT_language, dwarf::DW_FORM_data2); |
| 488 | EmitAbbrev(MCOS, 0, 0); |
| 489 | |
Kevin Enderby | 38fdb7d | 2012-01-10 17:52:29 +0000 | [diff] [blame] | 490 | // DW_TAG_label DIE abbrev (2). |
Kevin Enderby | 94c2e85 | 2011-12-09 18:09:40 +0000 | [diff] [blame] | 491 | MCOS->EmitULEB128IntValue(2); |
Kevin Enderby | 38fdb7d | 2012-01-10 17:52:29 +0000 | [diff] [blame] | 492 | MCOS->EmitULEB128IntValue(dwarf::DW_TAG_label); |
Kevin Enderby | 94c2e85 | 2011-12-09 18:09:40 +0000 | [diff] [blame] | 493 | MCOS->EmitIntValue(dwarf::DW_CHILDREN_yes, 1); |
| 494 | EmitAbbrev(MCOS, dwarf::DW_AT_name, dwarf::DW_FORM_string); |
| 495 | EmitAbbrev(MCOS, dwarf::DW_AT_decl_file, dwarf::DW_FORM_data4); |
| 496 | EmitAbbrev(MCOS, dwarf::DW_AT_decl_line, dwarf::DW_FORM_data4); |
| 497 | EmitAbbrev(MCOS, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr); |
Kevin Enderby | 94c2e85 | 2011-12-09 18:09:40 +0000 | [diff] [blame] | 498 | EmitAbbrev(MCOS, dwarf::DW_AT_prototyped, dwarf::DW_FORM_flag); |
| 499 | EmitAbbrev(MCOS, 0, 0); |
| 500 | |
| 501 | // DW_TAG_unspecified_parameters DIE abbrev (3). |
| 502 | MCOS->EmitULEB128IntValue(3); |
| 503 | MCOS->EmitULEB128IntValue(dwarf::DW_TAG_unspecified_parameters); |
| 504 | MCOS->EmitIntValue(dwarf::DW_CHILDREN_no, 1); |
| 505 | EmitAbbrev(MCOS, 0, 0); |
| 506 | |
| 507 | // Terminate the abbreviations for this compilation unit. |
| 508 | MCOS->EmitIntValue(0, 1); |
| 509 | } |
| 510 | |
| 511 | // When generating dwarf for assembly source files this emits the data for |
| 512 | // .debug_aranges section. Which contains a header and a table of pairs of |
| 513 | // PointerSize'ed values for the address and size of section(s) with line table |
| 514 | // entries (just the default .text in our case) and a terminating pair of zeros. |
Alexey Samsonov | 15ab115 | 2012-11-14 09:55:38 +0000 | [diff] [blame] | 515 | static void EmitGenDwarfAranges(MCStreamer *MCOS, |
| 516 | const MCSymbol *InfoSectionSymbol) { |
Kevin Enderby | 94c2e85 | 2011-12-09 18:09:40 +0000 | [diff] [blame] | 517 | MCContext &context = MCOS->getContext(); |
| 518 | |
| 519 | // Create a symbol at the end of the section that we are creating the dwarf |
| 520 | // debugging info to use later in here as part of the expression to calculate |
| 521 | // the size of the section for the table. |
| 522 | MCOS->SwitchSection(context.getGenDwarfSection()); |
| 523 | MCSymbol *SectionEndSym = context.CreateTempSymbol(); |
| 524 | MCOS->EmitLabel(SectionEndSym); |
| 525 | context.setGenDwarfSectionEndSym(SectionEndSym); |
| 526 | |
| 527 | MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfARangesSection()); |
| 528 | |
| 529 | // This will be the length of the .debug_aranges section, first account for |
| 530 | // the size of each item in the header (see below where we emit these items). |
| 531 | int Length = 4 + 2 + 4 + 1 + 1; |
| 532 | |
| 533 | // Figure the padding after the header before the table of address and size |
| 534 | // pairs who's values are PointerSize'ed. |
| 535 | const MCAsmInfo &asmInfo = context.getAsmInfo(); |
| 536 | int AddrSize = asmInfo.getPointerSize(); |
| 537 | int Pad = 2 * AddrSize - (Length & (2 * AddrSize - 1)); |
| 538 | if (Pad == 2 * AddrSize) |
| 539 | Pad = 0; |
| 540 | Length += Pad; |
| 541 | |
| 542 | // Add the size of the pair of PointerSize'ed values for the address and size |
| 543 | // of the one default .text section we have in the table. |
| 544 | Length += 2 * AddrSize; |
| 545 | // And the pair of terminating zeros. |
| 546 | Length += 2 * AddrSize; |
| 547 | |
| 548 | |
| 549 | // Emit the header for this section. |
| 550 | // The 4 byte length not including the 4 byte value for the length. |
| 551 | MCOS->EmitIntValue(Length - 4, 4); |
| 552 | // The 2 byte version, which is 2. |
| 553 | MCOS->EmitIntValue(2, 2); |
| 554 | // The 4 byte offset to the compile unit in the .debug_info from the start |
Alexey Samsonov | 15ab115 | 2012-11-14 09:55:38 +0000 | [diff] [blame] | 555 | // of the .debug_info. |
| 556 | if (InfoSectionSymbol) |
| 557 | MCOS->EmitSymbolValue(InfoSectionSymbol, 4); |
| 558 | else |
| 559 | MCOS->EmitIntValue(0, 4); |
Kevin Enderby | 94c2e85 | 2011-12-09 18:09:40 +0000 | [diff] [blame] | 560 | // The 1 byte size of an address. |
| 561 | MCOS->EmitIntValue(AddrSize, 1); |
| 562 | // The 1 byte size of a segment descriptor, we use a value of zero. |
| 563 | MCOS->EmitIntValue(0, 1); |
| 564 | // Align the header with the padding if needed, before we put out the table. |
| 565 | for(int i = 0; i < Pad; i++) |
| 566 | MCOS->EmitIntValue(0, 1); |
| 567 | |
| 568 | // Now emit the table of pairs of PointerSize'ed values for the section(s) |
| 569 | // address and size, in our case just the one default .text section. |
| 570 | const MCExpr *Addr = MCSymbolRefExpr::Create( |
| 571 | context.getGenDwarfSectionStartSym(), MCSymbolRefExpr::VK_None, context); |
| 572 | const MCExpr *Size = MakeStartMinusEndExpr(*MCOS, |
| 573 | *context.getGenDwarfSectionStartSym(), *SectionEndSym, 0); |
| 574 | MCOS->EmitAbsValue(Addr, AddrSize); |
| 575 | MCOS->EmitAbsValue(Size, AddrSize); |
| 576 | |
| 577 | // And finally the pair of terminating zeros. |
| 578 | MCOS->EmitIntValue(0, AddrSize); |
| 579 | MCOS->EmitIntValue(0, AddrSize); |
| 580 | } |
| 581 | |
| 582 | // When generating dwarf for assembly source files this emits the data for |
| 583 | // .debug_info section which contains three parts. The header, the compile_unit |
Kevin Enderby | 38fdb7d | 2012-01-10 17:52:29 +0000 | [diff] [blame] | 584 | // DIE and a list of label DIEs. |
Rafael Espindola | 489d679 | 2012-02-28 21:13:05 +0000 | [diff] [blame] | 585 | static void EmitGenDwarfInfo(MCStreamer *MCOS, |
| 586 | const MCSymbol *AbbrevSectionSymbol, |
| 587 | const MCSymbol *LineSectionSymbol) { |
Kevin Enderby | 94c2e85 | 2011-12-09 18:09:40 +0000 | [diff] [blame] | 588 | MCContext &context = MCOS->getContext(); |
| 589 | |
Jim Grosbach | 2684d9e | 2012-05-11 01:41:30 +0000 | [diff] [blame] | 590 | MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfInfoSection()); |
Kevin Enderby | 94c2e85 | 2011-12-09 18:09:40 +0000 | [diff] [blame] | 591 | |
| 592 | // Create a symbol at the start and end of this section used in here for the |
| 593 | // expression to calculate the length in the header. |
| 594 | MCSymbol *InfoStart = context.CreateTempSymbol(); |
| 595 | MCOS->EmitLabel(InfoStart); |
| 596 | MCSymbol *InfoEnd = context.CreateTempSymbol(); |
| 597 | |
| 598 | // First part: the header. |
| 599 | |
| 600 | // The 4 byte total length of the information for this compilation unit, not |
| 601 | // including these 4 bytes. |
| 602 | const MCExpr *Length = MakeStartMinusEndExpr(*MCOS, *InfoStart, *InfoEnd, 4); |
| 603 | MCOS->EmitAbsValue(Length, 4); |
| 604 | |
| 605 | // The 2 byte DWARF version, which is 2. |
| 606 | MCOS->EmitIntValue(2, 2); |
| 607 | |
| 608 | // The 4 byte offset to the debug abbrevs from the start of the .debug_abbrev, |
| 609 | // it is at the start of that section so this is zero. |
Rafael Espindola | 489d679 | 2012-02-28 21:13:05 +0000 | [diff] [blame] | 610 | if (AbbrevSectionSymbol) { |
| 611 | MCOS->EmitSymbolValue(AbbrevSectionSymbol, 4); |
| 612 | } else { |
| 613 | MCOS->EmitIntValue(0, 4); |
| 614 | } |
Kevin Enderby | 94c2e85 | 2011-12-09 18:09:40 +0000 | [diff] [blame] | 615 | |
| 616 | const MCAsmInfo &asmInfo = context.getAsmInfo(); |
| 617 | int AddrSize = asmInfo.getPointerSize(); |
| 618 | // The 1 byte size of an address. |
| 619 | MCOS->EmitIntValue(AddrSize, 1); |
| 620 | |
| 621 | // Second part: the compile_unit DIE. |
| 622 | |
| 623 | // The DW_TAG_compile_unit DIE abbrev (1). |
| 624 | MCOS->EmitULEB128IntValue(1); |
| 625 | |
| 626 | // DW_AT_stmt_list, a 4 byte offset from the start of the .debug_line section, |
| 627 | // which is at the start of that section so this is zero. |
Rafael Espindola | 489d679 | 2012-02-28 21:13:05 +0000 | [diff] [blame] | 628 | if (LineSectionSymbol) { |
| 629 | MCOS->EmitSymbolValue(LineSectionSymbol, 4); |
| 630 | } else { |
| 631 | MCOS->EmitIntValue(0, 4); |
| 632 | } |
Kevin Enderby | 94c2e85 | 2011-12-09 18:09:40 +0000 | [diff] [blame] | 633 | |
| 634 | // AT_low_pc, the first address of the default .text section. |
| 635 | const MCExpr *Start = MCSymbolRefExpr::Create( |
| 636 | context.getGenDwarfSectionStartSym(), MCSymbolRefExpr::VK_None, context); |
| 637 | MCOS->EmitAbsValue(Start, AddrSize); |
| 638 | |
| 639 | // AT_high_pc, the last address of the default .text section. |
| 640 | const MCExpr *End = MCSymbolRefExpr::Create( |
| 641 | context.getGenDwarfSectionEndSym(), MCSymbolRefExpr::VK_None, context); |
| 642 | MCOS->EmitAbsValue(End, AddrSize); |
| 643 | |
| 644 | // AT_name, the name of the source file. Reconstruct from the first directory |
| 645 | // and file table entries. |
| 646 | const std::vector<StringRef> &MCDwarfDirs = |
| 647 | context.getMCDwarfDirs(); |
| 648 | if (MCDwarfDirs.size() > 0) { |
Eric Christopher | 68ca562 | 2013-01-09 01:57:54 +0000 | [diff] [blame] | 649 | MCOS->EmitBytes(MCDwarfDirs[0]); |
| 650 | MCOS->EmitBytes("/"); |
Kevin Enderby | 94c2e85 | 2011-12-09 18:09:40 +0000 | [diff] [blame] | 651 | } |
| 652 | const std::vector<MCDwarfFile *> &MCDwarfFiles = |
| 653 | MCOS->getContext().getMCDwarfFiles(); |
Eric Christopher | 68ca562 | 2013-01-09 01:57:54 +0000 | [diff] [blame] | 654 | MCOS->EmitBytes(MCDwarfFiles[1]->getName()); |
Kevin Enderby | 94c2e85 | 2011-12-09 18:09:40 +0000 | [diff] [blame] | 655 | MCOS->EmitIntValue(0, 1); // NULL byte to terminate the string. |
| 656 | |
| 657 | // AT_comp_dir, the working directory the assembly was done in. |
Eric Christopher | 68ca562 | 2013-01-09 01:57:54 +0000 | [diff] [blame] | 658 | MCOS->EmitBytes(context.getCompilationDir()); |
Kevin Enderby | 94c2e85 | 2011-12-09 18:09:40 +0000 | [diff] [blame] | 659 | MCOS->EmitIntValue(0, 1); // NULL byte to terminate the string. |
| 660 | |
| 661 | // AT_APPLE_flags, the command line arguments of the assembler tool. |
| 662 | StringRef DwarfDebugFlags = context.getDwarfDebugFlags(); |
| 663 | if (!DwarfDebugFlags.empty()){ |
Eric Christopher | 68ca562 | 2013-01-09 01:57:54 +0000 | [diff] [blame] | 664 | MCOS->EmitBytes(DwarfDebugFlags); |
Kevin Enderby | 94c2e85 | 2011-12-09 18:09:40 +0000 | [diff] [blame] | 665 | MCOS->EmitIntValue(0, 1); // NULL byte to terminate the string. |
| 666 | } |
| 667 | |
| 668 | // AT_producer, the version of the assembler tool. |
Kevin Enderby | 75c9b93 | 2013-01-16 17:46:23 +0000 | [diff] [blame] | 669 | StringRef DwarfDebugProducer = context.getDwarfDebugProducer(); |
| 670 | if (!DwarfDebugProducer.empty()){ |
| 671 | MCOS->EmitBytes(DwarfDebugProducer); |
| 672 | } |
| 673 | else { |
| 674 | MCOS->EmitBytes(StringRef("llvm-mc (based on LLVM ")); |
| 675 | MCOS->EmitBytes(StringRef(PACKAGE_VERSION)); |
| 676 | MCOS->EmitBytes(StringRef(")")); |
| 677 | } |
Kevin Enderby | 94c2e85 | 2011-12-09 18:09:40 +0000 | [diff] [blame] | 678 | MCOS->EmitIntValue(0, 1); // NULL byte to terminate the string. |
| 679 | |
| 680 | // AT_language, a 4 byte value. We use DW_LANG_Mips_Assembler as the dwarf2 |
| 681 | // draft has no standard code for assembler. |
| 682 | MCOS->EmitIntValue(dwarf::DW_LANG_Mips_Assembler, 2); |
| 683 | |
Kevin Enderby | 38fdb7d | 2012-01-10 17:52:29 +0000 | [diff] [blame] | 684 | // Third part: the list of label DIEs. |
Kevin Enderby | 94c2e85 | 2011-12-09 18:09:40 +0000 | [diff] [blame] | 685 | |
Kevin Enderby | 11c2def | 2012-01-10 21:12:34 +0000 | [diff] [blame] | 686 | // Loop on saved info for dwarf labels and create the DIEs for them. |
| 687 | const std::vector<const MCGenDwarfLabelEntry *> &Entries = |
| 688 | MCOS->getContext().getMCGenDwarfLabelEntries(); |
| 689 | for (std::vector<const MCGenDwarfLabelEntry *>::const_iterator it = |
Kevin Enderby | 94c2e85 | 2011-12-09 18:09:40 +0000 | [diff] [blame] | 690 | Entries.begin(), ie = Entries.end(); it != ie; |
| 691 | ++it) { |
Kevin Enderby | 11c2def | 2012-01-10 21:12:34 +0000 | [diff] [blame] | 692 | const MCGenDwarfLabelEntry *Entry = *it; |
Kevin Enderby | 94c2e85 | 2011-12-09 18:09:40 +0000 | [diff] [blame] | 693 | |
Kevin Enderby | 38fdb7d | 2012-01-10 17:52:29 +0000 | [diff] [blame] | 694 | // The DW_TAG_label DIE abbrev (2). |
Kevin Enderby | 94c2e85 | 2011-12-09 18:09:40 +0000 | [diff] [blame] | 695 | MCOS->EmitULEB128IntValue(2); |
| 696 | |
| 697 | // AT_name, of the label without any leading underbar. |
Eric Christopher | 68ca562 | 2013-01-09 01:57:54 +0000 | [diff] [blame] | 698 | MCOS->EmitBytes(Entry->getName()); |
Kevin Enderby | 94c2e85 | 2011-12-09 18:09:40 +0000 | [diff] [blame] | 699 | MCOS->EmitIntValue(0, 1); // NULL byte to terminate the string. |
| 700 | |
| 701 | // AT_decl_file, index into the file table. |
| 702 | MCOS->EmitIntValue(Entry->getFileNumber(), 4); |
| 703 | |
| 704 | // AT_decl_line, source line number. |
| 705 | MCOS->EmitIntValue(Entry->getLineNumber(), 4); |
| 706 | |
| 707 | // AT_low_pc, start address of the label. |
| 708 | const MCExpr *AT_low_pc = MCSymbolRefExpr::Create(Entry->getLabel(), |
| 709 | MCSymbolRefExpr::VK_None, context); |
| 710 | MCOS->EmitAbsValue(AT_low_pc, AddrSize); |
| 711 | |
Kevin Enderby | 94c2e85 | 2011-12-09 18:09:40 +0000 | [diff] [blame] | 712 | // DW_AT_prototyped, a one byte flag value of 0 saying we have no prototype. |
| 713 | MCOS->EmitIntValue(0, 1); |
| 714 | |
| 715 | // The DW_TAG_unspecified_parameters DIE abbrev (3). |
| 716 | MCOS->EmitULEB128IntValue(3); |
| 717 | |
| 718 | // Add the NULL DIE terminating the DW_TAG_unspecified_parameters DIE's. |
| 719 | MCOS->EmitIntValue(0, 1); |
| 720 | } |
Kevin Enderby | 11c2def | 2012-01-10 21:12:34 +0000 | [diff] [blame] | 721 | // Deallocate the MCGenDwarfLabelEntry classes that saved away the info |
| 722 | // for the dwarf labels. |
| 723 | for (std::vector<const MCGenDwarfLabelEntry *>::const_iterator it = |
Kevin Enderby | 94c2e85 | 2011-12-09 18:09:40 +0000 | [diff] [blame] | 724 | Entries.begin(), ie = Entries.end(); it != ie; |
| 725 | ++it) { |
Kevin Enderby | 11c2def | 2012-01-10 21:12:34 +0000 | [diff] [blame] | 726 | const MCGenDwarfLabelEntry *Entry = *it; |
Kevin Enderby | 94c2e85 | 2011-12-09 18:09:40 +0000 | [diff] [blame] | 727 | delete Entry; |
| 728 | } |
| 729 | |
| 730 | // Add the NULL DIE terminating the Compile Unit DIE's. |
| 731 | MCOS->EmitIntValue(0, 1); |
| 732 | |
| 733 | // Now set the value of the symbol at the end of the info section. |
| 734 | MCOS->EmitLabel(InfoEnd); |
| 735 | } |
| 736 | |
| 737 | // |
| 738 | // When generating dwarf for assembly source files this emits the Dwarf |
| 739 | // sections. |
| 740 | // |
Rafael Espindola | 489d679 | 2012-02-28 21:13:05 +0000 | [diff] [blame] | 741 | void MCGenDwarfInfo::Emit(MCStreamer *MCOS, const MCSymbol *LineSectionSymbol) { |
Kevin Enderby | 94c2e85 | 2011-12-09 18:09:40 +0000 | [diff] [blame] | 742 | // Create the dwarf sections in this order (.debug_line already created). |
| 743 | MCContext &context = MCOS->getContext(); |
Rafael Espindola | 489d679 | 2012-02-28 21:13:05 +0000 | [diff] [blame] | 744 | const MCAsmInfo &AsmInfo = context.getAsmInfo(); |
Alexey Samsonov | 15ab115 | 2012-11-14 09:55:38 +0000 | [diff] [blame] | 745 | bool CreateDwarfSectionSymbols = |
| 746 | AsmInfo.doesDwarfUseRelocationsAcrossSections(); |
| 747 | if (!CreateDwarfSectionSymbols) |
| 748 | LineSectionSymbol = NULL; |
| 749 | MCSymbol *AbbrevSectionSymbol = NULL; |
| 750 | MCSymbol *InfoSectionSymbol = NULL; |
Kevin Enderby | 94c2e85 | 2011-12-09 18:09:40 +0000 | [diff] [blame] | 751 | MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfInfoSection()); |
Alexey Samsonov | 15ab115 | 2012-11-14 09:55:38 +0000 | [diff] [blame] | 752 | if (CreateDwarfSectionSymbols) { |
| 753 | InfoSectionSymbol = context.CreateTempSymbol(); |
| 754 | MCOS->EmitLabel(InfoSectionSymbol); |
| 755 | } |
Kevin Enderby | 94c2e85 | 2011-12-09 18:09:40 +0000 | [diff] [blame] | 756 | MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfAbbrevSection()); |
Alexey Samsonov | 15ab115 | 2012-11-14 09:55:38 +0000 | [diff] [blame] | 757 | if (CreateDwarfSectionSymbols) { |
Rafael Espindola | 489d679 | 2012-02-28 21:13:05 +0000 | [diff] [blame] | 758 | AbbrevSectionSymbol = context.CreateTempSymbol(); |
| 759 | MCOS->EmitLabel(AbbrevSectionSymbol); |
Rafael Espindola | 489d679 | 2012-02-28 21:13:05 +0000 | [diff] [blame] | 760 | } |
Kevin Enderby | 94c2e85 | 2011-12-09 18:09:40 +0000 | [diff] [blame] | 761 | MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfARangesSection()); |
| 762 | |
| 763 | // If there are no line table entries then do not emit any section contents. |
| 764 | if (context.getMCLineSections().empty()) |
| 765 | return; |
| 766 | |
| 767 | // Output the data for .debug_aranges section. |
Alexey Samsonov | 15ab115 | 2012-11-14 09:55:38 +0000 | [diff] [blame] | 768 | EmitGenDwarfAranges(MCOS, InfoSectionSymbol); |
Kevin Enderby | 94c2e85 | 2011-12-09 18:09:40 +0000 | [diff] [blame] | 769 | |
| 770 | // Output the data for .debug_abbrev section. |
| 771 | EmitGenDwarfAbbrev(MCOS); |
| 772 | |
| 773 | // Output the data for .debug_info section. |
Rafael Espindola | 489d679 | 2012-02-28 21:13:05 +0000 | [diff] [blame] | 774 | EmitGenDwarfInfo(MCOS, AbbrevSectionSymbol, LineSectionSymbol); |
Kevin Enderby | 94c2e85 | 2011-12-09 18:09:40 +0000 | [diff] [blame] | 775 | } |
| 776 | |
| 777 | // |
| 778 | // When generating dwarf for assembly source files this is called when symbol |
| 779 | // for a label is created. If this symbol is not a temporary and is in the |
| 780 | // section that dwarf is being generated for, save the needed info to create |
Kevin Enderby | 11c2def | 2012-01-10 21:12:34 +0000 | [diff] [blame] | 781 | // a dwarf label. |
Kevin Enderby | 94c2e85 | 2011-12-09 18:09:40 +0000 | [diff] [blame] | 782 | // |
Kevin Enderby | 11c2def | 2012-01-10 21:12:34 +0000 | [diff] [blame] | 783 | void MCGenDwarfLabelEntry::Make(MCSymbol *Symbol, MCStreamer *MCOS, |
Kevin Enderby | 94c2e85 | 2011-12-09 18:09:40 +0000 | [diff] [blame] | 784 | SourceMgr &SrcMgr, SMLoc &Loc) { |
Eric Christopher | 3c3cdcc | 2012-02-25 01:02:44 +0000 | [diff] [blame] | 785 | // We won't create dwarf labels for temporary symbols or symbols not in |
Kevin Enderby | 94c2e85 | 2011-12-09 18:09:40 +0000 | [diff] [blame] | 786 | // the default text. |
| 787 | if (Symbol->isTemporary()) |
| 788 | return; |
| 789 | MCContext &context = MCOS->getContext(); |
| 790 | if (context.getGenDwarfSection() != MCOS->getCurrentSection()) |
| 791 | return; |
| 792 | |
Kevin Enderby | 11c2def | 2012-01-10 21:12:34 +0000 | [diff] [blame] | 793 | // The dwarf label's name does not have the symbol name's leading |
Kevin Enderby | 94c2e85 | 2011-12-09 18:09:40 +0000 | [diff] [blame] | 794 | // underbar if any. |
| 795 | StringRef Name = Symbol->getName(); |
| 796 | if (Name.startswith("_")) |
| 797 | Name = Name.substr(1, Name.size()-1); |
| 798 | |
Kevin Enderby | 11c2def | 2012-01-10 21:12:34 +0000 | [diff] [blame] | 799 | // Get the dwarf file number to be used for the dwarf label. |
Kevin Enderby | 94c2e85 | 2011-12-09 18:09:40 +0000 | [diff] [blame] | 800 | unsigned FileNumber = context.getGenDwarfFileNumber(); |
| 801 | |
| 802 | // Finding the line number is the expensive part which is why we just don't |
Kevin Enderby | 11c2def | 2012-01-10 21:12:34 +0000 | [diff] [blame] | 803 | // pass it in as for some symbols we won't create a dwarf label. |
Kevin Enderby | 94c2e85 | 2011-12-09 18:09:40 +0000 | [diff] [blame] | 804 | int CurBuffer = SrcMgr.FindBufferContainingLoc(Loc); |
| 805 | unsigned LineNumber = SrcMgr.FindLineNumber(Loc, CurBuffer); |
| 806 | |
| 807 | // We create a temporary symbol for use for the AT_high_pc and AT_low_pc |
| 808 | // values so that they don't have things like an ARM thumb bit from the |
| 809 | // original symbol. So when used they won't get a low bit set after |
| 810 | // relocation. |
| 811 | MCSymbol *Label = context.CreateTempSymbol(); |
| 812 | MCOS->EmitLabel(Label); |
| 813 | |
| 814 | // Create and entry for the info and add it to the other entries. |
Jim Grosbach | 2684d9e | 2012-05-11 01:41:30 +0000 | [diff] [blame] | 815 | MCGenDwarfLabelEntry *Entry = |
Kevin Enderby | 11c2def | 2012-01-10 21:12:34 +0000 | [diff] [blame] | 816 | new MCGenDwarfLabelEntry(Name, FileNumber, LineNumber, Label); |
| 817 | MCOS->getContext().addMCGenDwarfLabelEntry(Entry); |
Kevin Enderby | 94c2e85 | 2011-12-09 18:09:40 +0000 | [diff] [blame] | 818 | } |
| 819 | |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 820 | static int getDataAlignmentFactor(MCStreamer &streamer) { |
| 821 | MCContext &context = streamer.getContext(); |
Evan Cheng | 1be0e27 | 2011-07-15 02:09:41 +0000 | [diff] [blame] | 822 | const MCAsmInfo &asmInfo = context.getAsmInfo(); |
Eli Bendersky | 9dd2a3b | 2013-01-22 18:02:49 +0000 | [diff] [blame] | 823 | int size = asmInfo.getCalleeSaveStackSlotSize(); |
Evan Cheng | 1be0e27 | 2011-07-15 02:09:41 +0000 | [diff] [blame] | 824 | if (asmInfo.isStackGrowthDirectionUp()) |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 825 | return size; |
Evan Cheng | 1be0e27 | 2011-07-15 02:09:41 +0000 | [diff] [blame] | 826 | else |
| 827 | return -size; |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 828 | } |
| 829 | |
Rafael Espindola | abf9af6 | 2011-04-22 00:08:43 +0000 | [diff] [blame] | 830 | static unsigned getSizeForEncoding(MCStreamer &streamer, |
| 831 | unsigned symbolEncoding) { |
Rafael Espindola | bdc3167 | 2010-12-27 15:56:22 +0000 | [diff] [blame] | 832 | MCContext &context = streamer.getContext(); |
Rafael Espindola | bdc3167 | 2010-12-27 15:56:22 +0000 | [diff] [blame] | 833 | unsigned format = symbolEncoding & 0x0f; |
Rafael Espindola | bdc3167 | 2010-12-27 15:56:22 +0000 | [diff] [blame] | 834 | switch (format) { |
Craig Topper | 8581438 | 2012-02-07 05:05:23 +0000 | [diff] [blame] | 835 | default: llvm_unreachable("Unknown Encoding"); |
Rafael Espindola | bdc3167 | 2010-12-27 15:56:22 +0000 | [diff] [blame] | 836 | case dwarf::DW_EH_PE_absptr: |
| 837 | case dwarf::DW_EH_PE_signed: |
Evan Cheng | 1be0e27 | 2011-07-15 02:09:41 +0000 | [diff] [blame] | 838 | return context.getAsmInfo().getPointerSize(); |
Rafael Espindola | bdc3167 | 2010-12-27 15:56:22 +0000 | [diff] [blame] | 839 | case dwarf::DW_EH_PE_udata2: |
| 840 | case dwarf::DW_EH_PE_sdata2: |
Rafael Espindola | abf9af6 | 2011-04-22 00:08:43 +0000 | [diff] [blame] | 841 | return 2; |
Rafael Espindola | bdc3167 | 2010-12-27 15:56:22 +0000 | [diff] [blame] | 842 | case dwarf::DW_EH_PE_udata4: |
| 843 | case dwarf::DW_EH_PE_sdata4: |
Rafael Espindola | abf9af6 | 2011-04-22 00:08:43 +0000 | [diff] [blame] | 844 | return 4; |
Rafael Espindola | bdc3167 | 2010-12-27 15:56:22 +0000 | [diff] [blame] | 845 | case dwarf::DW_EH_PE_udata8: |
| 846 | case dwarf::DW_EH_PE_sdata8: |
Rafael Espindola | abf9af6 | 2011-04-22 00:08:43 +0000 | [diff] [blame] | 847 | return 8; |
Rafael Espindola | bdc3167 | 2010-12-27 15:56:22 +0000 | [diff] [blame] | 848 | } |
Rafael Espindola | abf9af6 | 2011-04-22 00:08:43 +0000 | [diff] [blame] | 849 | } |
| 850 | |
| 851 | static void EmitSymbol(MCStreamer &streamer, const MCSymbol &symbol, |
Bill Wendling | 2541c41 | 2011-06-30 22:02:20 +0000 | [diff] [blame] | 852 | unsigned symbolEncoding, const char *comment = 0) { |
Rafael Espindola | a0057ca | 2011-04-28 21:04:39 +0000 | [diff] [blame] | 853 | MCContext &context = streamer.getContext(); |
| 854 | const MCAsmInfo &asmInfo = context.getAsmInfo(); |
| 855 | const MCExpr *v = asmInfo.getExprForFDESymbol(&symbol, |
Rafael Espindola | debd7e4 | 2011-05-01 03:50:49 +0000 | [diff] [blame] | 856 | symbolEncoding, |
Rafael Espindola | a0057ca | 2011-04-28 21:04:39 +0000 | [diff] [blame] | 857 | streamer); |
Rafael Espindola | abf9af6 | 2011-04-22 00:08:43 +0000 | [diff] [blame] | 858 | unsigned size = getSizeForEncoding(streamer, symbolEncoding); |
Bill Wendling | 2541c41 | 2011-06-30 22:02:20 +0000 | [diff] [blame] | 859 | if (streamer.isVerboseAsm() && comment) streamer.AddComment(comment); |
Rafael Espindola | debd7e4 | 2011-05-01 03:50:49 +0000 | [diff] [blame] | 860 | streamer.EmitAbsValue(v, size); |
Rafael Espindola | bdc3167 | 2010-12-27 15:56:22 +0000 | [diff] [blame] | 861 | } |
| 862 | |
Rafael Espindola | bfa27cc | 2011-04-28 16:09:09 +0000 | [diff] [blame] | 863 | static void EmitPersonality(MCStreamer &streamer, const MCSymbol &symbol, |
| 864 | unsigned symbolEncoding) { |
| 865 | MCContext &context = streamer.getContext(); |
| 866 | const MCAsmInfo &asmInfo = context.getAsmInfo(); |
Rafael Espindola | debd7e4 | 2011-05-01 03:50:49 +0000 | [diff] [blame] | 867 | const MCExpr *v = asmInfo.getExprForPersonalitySymbol(&symbol, |
| 868 | symbolEncoding, |
| 869 | streamer); |
Rafael Espindola | bfa27cc | 2011-04-28 16:09:09 +0000 | [diff] [blame] | 870 | unsigned size = getSizeForEncoding(streamer, symbolEncoding); |
Rafael Espindola | debd7e4 | 2011-05-01 03:50:49 +0000 | [diff] [blame] | 871 | streamer.EmitValue(v, size); |
Rafael Espindola | bfa27cc | 2011-04-28 16:09:09 +0000 | [diff] [blame] | 872 | } |
| 873 | |
Rafael Espindola | b40a71f | 2010-12-29 01:42:56 +0000 | [diff] [blame] | 874 | static const MachineLocation TranslateMachineLocation( |
Evan Cheng | 0e6a052 | 2011-07-18 20:57:22 +0000 | [diff] [blame] | 875 | const MCRegisterInfo &MRI, |
Rafael Espindola | b40a71f | 2010-12-29 01:42:56 +0000 | [diff] [blame] | 876 | const MachineLocation &Loc) { |
| 877 | unsigned Reg = Loc.getReg() == MachineLocation::VirtualFP ? |
| 878 | MachineLocation::VirtualFP : |
Evan Cheng | 0e6a052 | 2011-07-18 20:57:22 +0000 | [diff] [blame] | 879 | unsigned(MRI.getDwarfRegNum(Loc.getReg(), true)); |
Rafael Espindola | b40a71f | 2010-12-29 01:42:56 +0000 | [diff] [blame] | 880 | const MachineLocation &NewLoc = Loc.isReg() ? |
| 881 | MachineLocation(Reg) : MachineLocation(Reg, Loc.getOffset()); |
| 882 | return NewLoc; |
| 883 | } |
| 884 | |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 885 | namespace { |
| 886 | class FrameEmitterImpl { |
| 887 | int CFAOffset; |
Rafael Espindola | 514cecc | 2011-04-28 03:26:11 +0000 | [diff] [blame] | 888 | int CIENum; |
Rafael Espindola | 5426a9e | 2011-05-01 04:49:54 +0000 | [diff] [blame] | 889 | bool UsingCFI; |
Rafael Espindola | 40a7dbb | 2011-05-10 03:54:12 +0000 | [diff] [blame] | 890 | bool IsEH; |
Rafael Espindola | e3a0e98 | 2011-05-10 20:59:42 +0000 | [diff] [blame] | 891 | const MCSymbol *SectionStart; |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 892 | public: |
Bill Wendling | 1424c3c | 2011-07-22 21:18:59 +0000 | [diff] [blame] | 893 | FrameEmitterImpl(bool usingCFI, bool isEH) |
| 894 | : CFAOffset(0), CIENum(0), UsingCFI(usingCFI), IsEH(isEH), |
| 895 | SectionStart(0) {} |
| 896 | |
| 897 | void setSectionStart(const MCSymbol *Label) { SectionStart = Label; } |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 898 | |
Bill Wendling | e3cd13f | 2011-06-23 01:06:23 +0000 | [diff] [blame] | 899 | /// EmitCompactUnwind - Emit the unwind information in a compact way. If |
| 900 | /// we're successful, return 'true'. Otherwise, return 'false' and it will |
| 901 | /// emit the normal CIE and FDE. |
| 902 | bool EmitCompactUnwind(MCStreamer &streamer, |
| 903 | const MCDwarfFrameInfo &frame); |
| 904 | |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 905 | const MCSymbol &EmitCIE(MCStreamer &streamer, |
| 906 | const MCSymbol *personality, |
| 907 | unsigned personalityEncoding, |
| 908 | const MCSymbol *lsda, |
Rafael Espindola | 16d7d43 | 2012-01-23 21:51:52 +0000 | [diff] [blame] | 909 | bool IsSignalFrame, |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 910 | unsigned lsdaEncoding); |
| 911 | MCSymbol *EmitFDE(MCStreamer &streamer, |
| 912 | const MCSymbol &cieStart, |
Rafael Espindola | 9f270da | 2011-05-10 03:01:39 +0000 | [diff] [blame] | 913 | const MCDwarfFrameInfo &frame); |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 914 | void EmitCFIInstructions(MCStreamer &streamer, |
| 915 | const std::vector<MCCFIInstruction> &Instrs, |
| 916 | MCSymbol *BaseLabel); |
| 917 | void EmitCFIInstruction(MCStreamer &Streamer, |
| 918 | const MCCFIInstruction &Instr); |
| 919 | }; |
Bill Wendling | 3c163cf | 2011-06-30 21:25:51 +0000 | [diff] [blame] | 920 | |
| 921 | } // end anonymous namespace |
| 922 | |
| 923 | static void EmitEncodingByte(MCStreamer &Streamer, unsigned Encoding, |
| 924 | StringRef Prefix) { |
| 925 | if (Streamer.isVerboseAsm()) { |
Benjamin Kramer | eb9fa66 | 2012-01-20 14:42:37 +0000 | [diff] [blame] | 926 | const char *EncStr; |
Bill Wendling | 3c163cf | 2011-06-30 21:25:51 +0000 | [diff] [blame] | 927 | switch (Encoding) { |
Benjamin Kramer | eb9fa66 | 2012-01-20 14:42:37 +0000 | [diff] [blame] | 928 | default: EncStr = "<unknown encoding>"; break; |
| 929 | case dwarf::DW_EH_PE_absptr: EncStr = "absptr"; break; |
| 930 | case dwarf::DW_EH_PE_omit: EncStr = "omit"; break; |
| 931 | case dwarf::DW_EH_PE_pcrel: EncStr = "pcrel"; break; |
| 932 | case dwarf::DW_EH_PE_udata4: EncStr = "udata4"; break; |
| 933 | case dwarf::DW_EH_PE_udata8: EncStr = "udata8"; break; |
| 934 | case dwarf::DW_EH_PE_sdata4: EncStr = "sdata4"; break; |
| 935 | case dwarf::DW_EH_PE_sdata8: EncStr = "sdata8"; break; |
| 936 | case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata4: |
| 937 | EncStr = "pcrel udata4"; |
| 938 | break; |
| 939 | case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4: |
| 940 | EncStr = "pcrel sdata4"; |
| 941 | break; |
| 942 | case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8: |
| 943 | EncStr = "pcrel udata8"; |
| 944 | break; |
| 945 | case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8: |
| 946 | EncStr = "screl sdata8"; |
| 947 | break; |
Bill Wendling | 3c163cf | 2011-06-30 21:25:51 +0000 | [diff] [blame] | 948 | case dwarf::DW_EH_PE_indirect |dwarf::DW_EH_PE_pcrel|dwarf::DW_EH_PE_udata4: |
| 949 | EncStr = "indirect pcrel udata4"; |
Benjamin Kramer | eb9fa66 | 2012-01-20 14:42:37 +0000 | [diff] [blame] | 950 | break; |
Bill Wendling | 3c163cf | 2011-06-30 21:25:51 +0000 | [diff] [blame] | 951 | case dwarf::DW_EH_PE_indirect |dwarf::DW_EH_PE_pcrel|dwarf::DW_EH_PE_sdata4: |
| 952 | EncStr = "indirect pcrel sdata4"; |
Benjamin Kramer | eb9fa66 | 2012-01-20 14:42:37 +0000 | [diff] [blame] | 953 | break; |
Bill Wendling | 3c163cf | 2011-06-30 21:25:51 +0000 | [diff] [blame] | 954 | case dwarf::DW_EH_PE_indirect |dwarf::DW_EH_PE_pcrel|dwarf::DW_EH_PE_udata8: |
| 955 | EncStr = "indirect pcrel udata8"; |
Benjamin Kramer | eb9fa66 | 2012-01-20 14:42:37 +0000 | [diff] [blame] | 956 | break; |
Bill Wendling | 3c163cf | 2011-06-30 21:25:51 +0000 | [diff] [blame] | 957 | case dwarf::DW_EH_PE_indirect |dwarf::DW_EH_PE_pcrel|dwarf::DW_EH_PE_sdata8: |
| 958 | EncStr = "indirect pcrel sdata8"; |
Benjamin Kramer | eb9fa66 | 2012-01-20 14:42:37 +0000 | [diff] [blame] | 959 | break; |
Bill Wendling | 3c163cf | 2011-06-30 21:25:51 +0000 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | Streamer.AddComment(Twine(Prefix) + " = " + EncStr); |
| 963 | } |
| 964 | |
| 965 | Streamer.EmitIntValue(Encoding, 1); |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 966 | } |
| 967 | |
| 968 | void FrameEmitterImpl::EmitCFIInstruction(MCStreamer &Streamer, |
| 969 | const MCCFIInstruction &Instr) { |
| 970 | int dataAlignmentFactor = getDataAlignmentFactor(Streamer); |
Bill Wendling | efd24dd | 2011-06-30 21:45:12 +0000 | [diff] [blame] | 971 | bool VerboseAsm = Streamer.isVerboseAsm(); |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 972 | |
| 973 | switch (Instr.getOperation()) { |
Rafael Espindola | f4f14f6 | 2012-11-25 15:14:49 +0000 | [diff] [blame] | 974 | case MCCFIInstruction::OpRegister: { |
| 975 | unsigned Reg1 = Instr.getRegister(); |
| 976 | unsigned Reg2 = Instr.getRegister2(); |
| 977 | if (VerboseAsm) { |
| 978 | Streamer.AddComment("DW_CFA_register"); |
| 979 | Streamer.AddComment(Twine("Reg1 ") + Twine(Reg1)); |
| 980 | Streamer.AddComment(Twine("Reg2 ") + Twine(Reg2)); |
| 981 | } |
| 982 | Streamer.EmitIntValue(dwarf::DW_CFA_register, 1); |
| 983 | Streamer.EmitULEB128IntValue(Reg1); |
| 984 | Streamer.EmitULEB128IntValue(Reg2); |
| 985 | return; |
| 986 | } |
Rafael Espindola | 7f74d2c | 2012-11-24 03:10:54 +0000 | [diff] [blame] | 987 | case MCCFIInstruction::OpUndefined: { |
Rafael Espindola | ff233c9 | 2012-11-24 04:33:48 +0000 | [diff] [blame] | 988 | unsigned Reg = Instr.getRegister(); |
Rafael Espindola | c8fec7e | 2012-11-23 16:59:41 +0000 | [diff] [blame] | 989 | if (VerboseAsm) { |
| 990 | Streamer.AddComment("DW_CFA_undefined"); |
| 991 | Streamer.AddComment(Twine("Reg ") + Twine(Reg)); |
| 992 | } |
| 993 | Streamer.EmitIntValue(dwarf::DW_CFA_undefined, 1); |
| 994 | Streamer.EmitULEB128IntValue(Reg); |
| 995 | return; |
| 996 | } |
Rafael Espindola | 7f74d2c | 2012-11-24 03:10:54 +0000 | [diff] [blame] | 997 | case MCCFIInstruction::OpAdjustCfaOffset: |
| 998 | case MCCFIInstruction::OpDefCfaOffset: { |
Rafael Espindola | 7f74d2c | 2012-11-24 03:10:54 +0000 | [diff] [blame] | 999 | const bool IsRelative = |
| 1000 | Instr.getOperation() == MCCFIInstruction::OpAdjustCfaOffset; |
| 1001 | |
| 1002 | if (VerboseAsm) |
| 1003 | Streamer.AddComment("DW_CFA_def_cfa_offset"); |
| 1004 | Streamer.EmitIntValue(dwarf::DW_CFA_def_cfa_offset, 1); |
| 1005 | |
| 1006 | if (IsRelative) |
Rafael Espindola | ff233c9 | 2012-11-24 04:33:48 +0000 | [diff] [blame] | 1007 | CFAOffset += Instr.getOffset(); |
Rafael Espindola | 7f74d2c | 2012-11-24 03:10:54 +0000 | [diff] [blame] | 1008 | else |
Rafael Espindola | ff233c9 | 2012-11-24 04:33:48 +0000 | [diff] [blame] | 1009 | CFAOffset = -Instr.getOffset(); |
Rafael Espindola | 7f74d2c | 2012-11-24 03:10:54 +0000 | [diff] [blame] | 1010 | |
| 1011 | if (VerboseAsm) |
| 1012 | Streamer.AddComment(Twine("Offset " + Twine(CFAOffset))); |
| 1013 | Streamer.EmitULEB128IntValue(CFAOffset); |
| 1014 | |
| 1015 | return; |
| 1016 | } |
| 1017 | case MCCFIInstruction::OpDefCfa: { |
Rafael Espindola | 7f74d2c | 2012-11-24 03:10:54 +0000 | [diff] [blame] | 1018 | if (VerboseAsm) |
| 1019 | Streamer.AddComment("DW_CFA_def_cfa"); |
| 1020 | Streamer.EmitIntValue(dwarf::DW_CFA_def_cfa, 1); |
| 1021 | |
| 1022 | if (VerboseAsm) |
Rafael Espindola | ff233c9 | 2012-11-24 04:33:48 +0000 | [diff] [blame] | 1023 | Streamer.AddComment(Twine("Reg ") + Twine(Instr.getRegister())); |
| 1024 | Streamer.EmitULEB128IntValue(Instr.getRegister()); |
Rafael Espindola | 7f74d2c | 2012-11-24 03:10:54 +0000 | [diff] [blame] | 1025 | |
Rafael Espindola | ff233c9 | 2012-11-24 04:33:48 +0000 | [diff] [blame] | 1026 | CFAOffset = -Instr.getOffset(); |
Rafael Espindola | 7f74d2c | 2012-11-24 03:10:54 +0000 | [diff] [blame] | 1027 | |
| 1028 | if (VerboseAsm) |
| 1029 | Streamer.AddComment(Twine("Offset " + Twine(CFAOffset))); |
| 1030 | Streamer.EmitULEB128IntValue(CFAOffset); |
| 1031 | |
| 1032 | return; |
| 1033 | } |
| 1034 | |
| 1035 | case MCCFIInstruction::OpDefCfaRegister: { |
Rafael Espindola | 7f74d2c | 2012-11-24 03:10:54 +0000 | [diff] [blame] | 1036 | if (VerboseAsm) |
| 1037 | Streamer.AddComment("DW_CFA_def_cfa_register"); |
| 1038 | Streamer.EmitIntValue(dwarf::DW_CFA_def_cfa_register, 1); |
| 1039 | |
| 1040 | if (VerboseAsm) |
Rafael Espindola | ff233c9 | 2012-11-24 04:33:48 +0000 | [diff] [blame] | 1041 | Streamer.AddComment(Twine("Reg ") + Twine(Instr.getRegister())); |
| 1042 | Streamer.EmitULEB128IntValue(Instr.getRegister()); |
Rafael Espindola | 7f74d2c | 2012-11-24 03:10:54 +0000 | [diff] [blame] | 1043 | |
| 1044 | return; |
| 1045 | } |
| 1046 | |
| 1047 | case MCCFIInstruction::OpOffset: |
| 1048 | case MCCFIInstruction::OpRelOffset: { |
Rafael Espindola | 7f74d2c | 2012-11-24 03:10:54 +0000 | [diff] [blame] | 1049 | const bool IsRelative = |
| 1050 | Instr.getOperation() == MCCFIInstruction::OpRelOffset; |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 1051 | |
Rafael Espindola | ff233c9 | 2012-11-24 04:33:48 +0000 | [diff] [blame] | 1052 | unsigned Reg = Instr.getRegister(); |
| 1053 | int Offset = Instr.getOffset(); |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 1054 | if (IsRelative) |
| 1055 | Offset -= CFAOffset; |
| 1056 | Offset = Offset / dataAlignmentFactor; |
| 1057 | |
| 1058 | if (Offset < 0) { |
Bill Wendling | efd24dd | 2011-06-30 21:45:12 +0000 | [diff] [blame] | 1059 | if (VerboseAsm) Streamer.AddComment("DW_CFA_offset_extended_sf"); |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 1060 | Streamer.EmitIntValue(dwarf::DW_CFA_offset_extended_sf, 1); |
Bill Wendling | efd24dd | 2011-06-30 21:45:12 +0000 | [diff] [blame] | 1061 | if (VerboseAsm) Streamer.AddComment(Twine("Reg ") + Twine(Reg)); |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 1062 | Streamer.EmitULEB128IntValue(Reg); |
Bill Wendling | efd24dd | 2011-06-30 21:45:12 +0000 | [diff] [blame] | 1063 | if (VerboseAsm) Streamer.AddComment(Twine("Offset ") + Twine(Offset)); |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 1064 | Streamer.EmitSLEB128IntValue(Offset); |
| 1065 | } else if (Reg < 64) { |
Bill Wendling | e08d433 | 2011-06-30 23:47:40 +0000 | [diff] [blame] | 1066 | if (VerboseAsm) Streamer.AddComment(Twine("DW_CFA_offset + Reg(") + |
| 1067 | Twine(Reg) + ")"); |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 1068 | Streamer.EmitIntValue(dwarf::DW_CFA_offset + Reg, 1); |
Bill Wendling | efd24dd | 2011-06-30 21:45:12 +0000 | [diff] [blame] | 1069 | if (VerboseAsm) Streamer.AddComment(Twine("Offset ") + Twine(Offset)); |
Rafael Espindola | eccbad7 | 2011-04-21 23:26:40 +0000 | [diff] [blame] | 1070 | Streamer.EmitULEB128IntValue(Offset); |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 1071 | } else { |
Bill Wendling | efd24dd | 2011-06-30 21:45:12 +0000 | [diff] [blame] | 1072 | if (VerboseAsm) Streamer.AddComment("DW_CFA_offset_extended"); |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 1073 | Streamer.EmitIntValue(dwarf::DW_CFA_offset_extended, 1); |
Bill Wendling | efd24dd | 2011-06-30 21:45:12 +0000 | [diff] [blame] | 1074 | if (VerboseAsm) Streamer.AddComment(Twine("Reg ") + Twine(Reg)); |
Rafael Espindola | eccbad7 | 2011-04-21 23:26:40 +0000 | [diff] [blame] | 1075 | Streamer.EmitULEB128IntValue(Reg); |
Bill Wendling | efd24dd | 2011-06-30 21:45:12 +0000 | [diff] [blame] | 1076 | if (VerboseAsm) Streamer.AddComment(Twine("Offset ") + Twine(Offset)); |
Rafael Espindola | eccbad7 | 2011-04-21 23:26:40 +0000 | [diff] [blame] | 1077 | Streamer.EmitULEB128IntValue(Offset); |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 1078 | } |
| 1079 | return; |
| 1080 | } |
Rafael Espindola | 7f74d2c | 2012-11-24 03:10:54 +0000 | [diff] [blame] | 1081 | case MCCFIInstruction::OpRememberState: |
Bill Wendling | efd24dd | 2011-06-30 21:45:12 +0000 | [diff] [blame] | 1082 | if (VerboseAsm) Streamer.AddComment("DW_CFA_remember_state"); |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 1083 | Streamer.EmitIntValue(dwarf::DW_CFA_remember_state, 1); |
| 1084 | return; |
Rafael Espindola | 7f74d2c | 2012-11-24 03:10:54 +0000 | [diff] [blame] | 1085 | case MCCFIInstruction::OpRestoreState: |
Bill Wendling | efd24dd | 2011-06-30 21:45:12 +0000 | [diff] [blame] | 1086 | if (VerboseAsm) Streamer.AddComment("DW_CFA_restore_state"); |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 1087 | Streamer.EmitIntValue(dwarf::DW_CFA_restore_state, 1); |
| 1088 | return; |
Rafael Espindola | 7f74d2c | 2012-11-24 03:10:54 +0000 | [diff] [blame] | 1089 | case MCCFIInstruction::OpSameValue: { |
Rafael Espindola | ff233c9 | 2012-11-24 04:33:48 +0000 | [diff] [blame] | 1090 | unsigned Reg = Instr.getRegister(); |
Bill Wendling | efd24dd | 2011-06-30 21:45:12 +0000 | [diff] [blame] | 1091 | if (VerboseAsm) Streamer.AddComment("DW_CFA_same_value"); |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 1092 | Streamer.EmitIntValue(dwarf::DW_CFA_same_value, 1); |
Bill Wendling | efd24dd | 2011-06-30 21:45:12 +0000 | [diff] [blame] | 1093 | if (VerboseAsm) Streamer.AddComment(Twine("Reg ") + Twine(Reg)); |
Rafael Espindola | e8cfbd8 | 2011-04-21 23:39:26 +0000 | [diff] [blame] | 1094 | Streamer.EmitULEB128IntValue(Reg); |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 1095 | return; |
| 1096 | } |
Rafael Espindola | 7f74d2c | 2012-11-24 03:10:54 +0000 | [diff] [blame] | 1097 | case MCCFIInstruction::OpRestore: { |
Rafael Espindola | ff233c9 | 2012-11-24 04:33:48 +0000 | [diff] [blame] | 1098 | unsigned Reg = Instr.getRegister(); |
Rafael Espindola | ed23bdb | 2011-12-29 21:43:03 +0000 | [diff] [blame] | 1099 | if (VerboseAsm) { |
| 1100 | Streamer.AddComment("DW_CFA_restore"); |
| 1101 | Streamer.AddComment(Twine("Reg ") + Twine(Reg)); |
| 1102 | } |
| 1103 | Streamer.EmitIntValue(dwarf::DW_CFA_restore | Reg, 1); |
| 1104 | return; |
| 1105 | } |
Rafael Espindola | 7f74d2c | 2012-11-24 03:10:54 +0000 | [diff] [blame] | 1106 | case MCCFIInstruction::OpEscape: |
Rafael Espindola | 6f0b181 | 2011-12-29 20:24:47 +0000 | [diff] [blame] | 1107 | if (VerboseAsm) Streamer.AddComment("Escape bytes"); |
Eric Christopher | 68ca562 | 2013-01-09 01:57:54 +0000 | [diff] [blame] | 1108 | Streamer.EmitBytes(Instr.getValues()); |
Rafael Espindola | 6f0b181 | 2011-12-29 20:24:47 +0000 | [diff] [blame] | 1109 | return; |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 1110 | } |
| 1111 | llvm_unreachable("Unhandled case in switch"); |
| 1112 | } |
| 1113 | |
| 1114 | /// EmitFrameMoves - Emit frame instructions to describe the layout of the |
| 1115 | /// frame. |
| 1116 | void FrameEmitterImpl::EmitCFIInstructions(MCStreamer &streamer, |
| 1117 | const std::vector<MCCFIInstruction> &Instrs, |
| 1118 | MCSymbol *BaseLabel) { |
| 1119 | for (unsigned i = 0, N = Instrs.size(); i < N; ++i) { |
| 1120 | const MCCFIInstruction &Instr = Instrs[i]; |
| 1121 | MCSymbol *Label = Instr.getLabel(); |
| 1122 | // Throw out move if the label is invalid. |
| 1123 | if (Label && !Label->isDefined()) continue; // Not emitted, in dead code. |
| 1124 | |
| 1125 | // Advance row if new location. |
| 1126 | if (BaseLabel && Label) { |
| 1127 | MCSymbol *ThisSym = Label; |
| 1128 | if (ThisSym != BaseLabel) { |
Bill Wendling | d221cd6 | 2011-06-30 22:35:49 +0000 | [diff] [blame] | 1129 | if (streamer.isVerboseAsm()) streamer.AddComment("DW_CFA_advance_loc4"); |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 1130 | streamer.EmitDwarfAdvanceFrameAddr(BaseLabel, ThisSym); |
| 1131 | BaseLabel = ThisSym; |
| 1132 | } |
| 1133 | } |
| 1134 | |
| 1135 | EmitCFIInstruction(streamer, Instr); |
| 1136 | } |
| 1137 | } |
| 1138 | |
Bill Wendling | e3cd13f | 2011-06-23 01:06:23 +0000 | [diff] [blame] | 1139 | /// EmitCompactUnwind - Emit the unwind information in a compact way. If we're |
| 1140 | /// successful, return 'true'. Otherwise, return 'false' and it will emit the |
| 1141 | /// normal CIE and FDE. |
| 1142 | bool FrameEmitterImpl::EmitCompactUnwind(MCStreamer &Streamer, |
| 1143 | const MCDwarfFrameInfo &Frame) { |
Bill Wendling | e3cd13f | 2011-06-23 01:06:23 +0000 | [diff] [blame] | 1144 | MCContext &Context = Streamer.getContext(); |
Evan Cheng | e76a33b | 2011-07-20 05:58:47 +0000 | [diff] [blame] | 1145 | const MCObjectFileInfo *MOFI = Context.getObjectFileInfo(); |
Bill Wendling | 3c163cf | 2011-06-30 21:25:51 +0000 | [diff] [blame] | 1146 | bool VerboseAsm = Streamer.isVerboseAsm(); |
Bill Wendling | e3cd13f | 2011-06-23 01:06:23 +0000 | [diff] [blame] | 1147 | |
Bill Wendling | e3cd13f | 2011-06-23 01:06:23 +0000 | [diff] [blame] | 1148 | // range-start range-length compact-unwind-enc personality-func lsda |
| 1149 | // _foo LfooEnd-_foo 0x00000023 0 0 |
| 1150 | // _bar LbarEnd-_bar 0x00000025 __gxx_personality except_tab1 |
| 1151 | // |
| 1152 | // .section __LD,__compact_unwind,regular,debug |
| 1153 | // |
| 1154 | // # compact unwind for _foo |
| 1155 | // .quad _foo |
| 1156 | // .set L1,LfooEnd-_foo |
| 1157 | // .long L1 |
| 1158 | // .long 0x01010001 |
| 1159 | // .quad 0 |
| 1160 | // .quad 0 |
| 1161 | // |
| 1162 | // # compact unwind for _bar |
| 1163 | // .quad _bar |
| 1164 | // .set L2,LbarEnd-_bar |
| 1165 | // .long L2 |
| 1166 | // .long 0x01020011 |
| 1167 | // .quad __gxx_personality |
| 1168 | // .quad except_tab1 |
| 1169 | |
Bill Wendling | e52e3f2 | 2011-07-19 00:06:12 +0000 | [diff] [blame] | 1170 | uint32_t Encoding = Frame.CompactUnwindEncoding; |
Bill Wendling | 6a6b8c3 | 2011-07-07 00:54:13 +0000 | [diff] [blame] | 1171 | if (!Encoding) return false; |
| 1172 | |
Bill Wendling | 4bb5b03 | 2011-07-14 23:34:45 +0000 | [diff] [blame] | 1173 | // The encoding needs to know we have an LSDA. |
| 1174 | if (Frame.Lsda) |
| 1175 | Encoding |= 0x40000000; |
| 1176 | |
Evan Cheng | e76a33b | 2011-07-20 05:58:47 +0000 | [diff] [blame] | 1177 | Streamer.SwitchSection(MOFI->getCompactUnwindSection()); |
Bill Wendling | 3c163cf | 2011-06-30 21:25:51 +0000 | [diff] [blame] | 1178 | |
Bill Wendling | e3cd13f | 2011-06-23 01:06:23 +0000 | [diff] [blame] | 1179 | // Range Start |
Evan Cheng | 203576a | 2011-07-20 19:50:42 +0000 | [diff] [blame] | 1180 | unsigned FDEEncoding = MOFI->getFDEEncoding(UsingCFI); |
Bill Wendling | 9056e90 | 2011-06-29 23:49:12 +0000 | [diff] [blame] | 1181 | unsigned Size = getSizeForEncoding(Streamer, FDEEncoding); |
Bill Wendling | 3c163cf | 2011-06-30 21:25:51 +0000 | [diff] [blame] | 1182 | if (VerboseAsm) Streamer.AddComment("Range Start"); |
Bill Wendling | 9056e90 | 2011-06-29 23:49:12 +0000 | [diff] [blame] | 1183 | Streamer.EmitSymbolValue(Frame.Function, Size); |
Bill Wendling | e3cd13f | 2011-06-23 01:06:23 +0000 | [diff] [blame] | 1184 | |
| 1185 | // Range Length |
| 1186 | const MCExpr *Range = MakeStartMinusEndExpr(Streamer, *Frame.Begin, |
| 1187 | *Frame.End, 0); |
Bill Wendling | 3c163cf | 2011-06-30 21:25:51 +0000 | [diff] [blame] | 1188 | if (VerboseAsm) Streamer.AddComment("Range Length"); |
Bill Wendling | 9287a6e | 2011-06-30 00:30:52 +0000 | [diff] [blame] | 1189 | Streamer.EmitAbsValue(Range, 4); |
| 1190 | |
Bill Wendling | 9287a6e | 2011-06-30 00:30:52 +0000 | [diff] [blame] | 1191 | // Compact Encoding |
Bill Wendling | 9287a6e | 2011-06-30 00:30:52 +0000 | [diff] [blame] | 1192 | Size = getSizeForEncoding(Streamer, dwarf::DW_EH_PE_udata4); |
Benjamin Kramer | 70be28a | 2011-11-07 21:00:59 +0000 | [diff] [blame] | 1193 | if (VerboseAsm) Streamer.AddComment("Compact Unwind Encoding: 0x" + |
| 1194 | Twine::utohexstr(Encoding)); |
Bill Wendling | 9287a6e | 2011-06-30 00:30:52 +0000 | [diff] [blame] | 1195 | Streamer.EmitIntValue(Encoding, Size); |
| 1196 | |
Bill Wendling | e52e3f2 | 2011-07-19 00:06:12 +0000 | [diff] [blame] | 1197 | |
Bill Wendling | 9056e90 | 2011-06-29 23:49:12 +0000 | [diff] [blame] | 1198 | // Personality Function |
Bill Wendling | 4bb5b03 | 2011-07-14 23:34:45 +0000 | [diff] [blame] | 1199 | Size = getSizeForEncoding(Streamer, dwarf::DW_EH_PE_absptr); |
Bill Wendling | 3c163cf | 2011-06-30 21:25:51 +0000 | [diff] [blame] | 1200 | if (VerboseAsm) Streamer.AddComment("Personality Function"); |
Bill Wendling | 4498d39 | 2011-06-29 23:53:16 +0000 | [diff] [blame] | 1201 | if (Frame.Personality) |
Bill Wendling | 9056e90 | 2011-06-29 23:49:12 +0000 | [diff] [blame] | 1202 | Streamer.EmitSymbolValue(Frame.Personality, Size); |
Bill Wendling | 4498d39 | 2011-06-29 23:53:16 +0000 | [diff] [blame] | 1203 | else |
| 1204 | Streamer.EmitIntValue(0, Size); // No personality fn |
Bill Wendling | 9056e90 | 2011-06-29 23:49:12 +0000 | [diff] [blame] | 1205 | |
| 1206 | // LSDA |
Bill Wendling | 4498d39 | 2011-06-29 23:53:16 +0000 | [diff] [blame] | 1207 | Size = getSizeForEncoding(Streamer, Frame.LsdaEncoding); |
Bill Wendling | 3c163cf | 2011-06-30 21:25:51 +0000 | [diff] [blame] | 1208 | if (VerboseAsm) Streamer.AddComment("LSDA"); |
Bill Wendling | 4498d39 | 2011-06-29 23:53:16 +0000 | [diff] [blame] | 1209 | if (Frame.Lsda) |
Bill Wendling | 9056e90 | 2011-06-29 23:49:12 +0000 | [diff] [blame] | 1210 | Streamer.EmitSymbolValue(Frame.Lsda, Size); |
Bill Wendling | 4498d39 | 2011-06-29 23:53:16 +0000 | [diff] [blame] | 1211 | else |
| 1212 | Streamer.EmitIntValue(0, Size); // No LSDA |
Bill Wendling | 9056e90 | 2011-06-29 23:49:12 +0000 | [diff] [blame] | 1213 | |
Bill Wendling | e3cd13f | 2011-06-23 01:06:23 +0000 | [diff] [blame] | 1214 | return true; |
Bill Wendling | e3cd13f | 2011-06-23 01:06:23 +0000 | [diff] [blame] | 1215 | } |
| 1216 | |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 1217 | const MCSymbol &FrameEmitterImpl::EmitCIE(MCStreamer &streamer, |
| 1218 | const MCSymbol *personality, |
| 1219 | unsigned personalityEncoding, |
| 1220 | const MCSymbol *lsda, |
Rafael Espindola | 16d7d43 | 2012-01-23 21:51:52 +0000 | [diff] [blame] | 1221 | bool IsSignalFrame, |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 1222 | unsigned lsdaEncoding) { |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 1223 | MCContext &context = streamer.getContext(); |
Evan Cheng | 0e6a052 | 2011-07-18 20:57:22 +0000 | [diff] [blame] | 1224 | const MCRegisterInfo &MRI = context.getRegisterInfo(); |
Evan Cheng | e76a33b | 2011-07-20 05:58:47 +0000 | [diff] [blame] | 1225 | const MCObjectFileInfo *MOFI = context.getObjectFileInfo(); |
Bill Wendling | 3c163cf | 2011-06-30 21:25:51 +0000 | [diff] [blame] | 1226 | bool verboseAsm = streamer.isVerboseAsm(); |
Rafael Espindola | 514cecc | 2011-04-28 03:26:11 +0000 | [diff] [blame] | 1227 | |
| 1228 | MCSymbol *sectionStart; |
Evan Cheng | e76a33b | 2011-07-20 05:58:47 +0000 | [diff] [blame] | 1229 | if (MOFI->isFunctionEHFrameSymbolPrivate() || !IsEH) |
Rafael Espindola | 514cecc | 2011-04-28 03:26:11 +0000 | [diff] [blame] | 1230 | sectionStart = context.CreateTempSymbol(); |
| 1231 | else |
| 1232 | sectionStart = context.GetOrCreateSymbol(Twine("EH_frame") + Twine(CIENum)); |
| 1233 | |
Bill Wendling | 3c163cf | 2011-06-30 21:25:51 +0000 | [diff] [blame] | 1234 | streamer.EmitLabel(sectionStart); |
Rafael Espindola | 514cecc | 2011-04-28 03:26:11 +0000 | [diff] [blame] | 1235 | CIENum++; |
| 1236 | |
Bill Wendling | 6a6b8c3 | 2011-07-07 00:54:13 +0000 | [diff] [blame] | 1237 | MCSymbol *sectionEnd = context.CreateTempSymbol(); |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 1238 | |
| 1239 | // Length |
| 1240 | const MCExpr *Length = MakeStartMinusEndExpr(streamer, *sectionStart, |
| 1241 | *sectionEnd, 4); |
Bill Wendling | 3c163cf | 2011-06-30 21:25:51 +0000 | [diff] [blame] | 1242 | if (verboseAsm) streamer.AddComment("CIE Length"); |
Rafael Espindola | 9266cc4 | 2011-04-27 01:43:49 +0000 | [diff] [blame] | 1243 | streamer.EmitAbsValue(Length, 4); |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 1244 | |
| 1245 | // CIE ID |
Rafael Espindola | 40a7dbb | 2011-05-10 03:54:12 +0000 | [diff] [blame] | 1246 | unsigned CIE_ID = IsEH ? 0 : -1; |
Bill Wendling | 3c163cf | 2011-06-30 21:25:51 +0000 | [diff] [blame] | 1247 | if (verboseAsm) streamer.AddComment("CIE ID Tag"); |
Rafael Espindola | 40a7dbb | 2011-05-10 03:54:12 +0000 | [diff] [blame] | 1248 | streamer.EmitIntValue(CIE_ID, 4); |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 1249 | |
| 1250 | // Version |
Bill Wendling | 3c163cf | 2011-06-30 21:25:51 +0000 | [diff] [blame] | 1251 | if (verboseAsm) streamer.AddComment("DW_CIE_VERSION"); |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 1252 | streamer.EmitIntValue(dwarf::DW_CIE_VERSION, 1); |
| 1253 | |
| 1254 | // Augmentation String |
| 1255 | SmallString<8> Augmentation; |
Rafael Espindola | 40a7dbb | 2011-05-10 03:54:12 +0000 | [diff] [blame] | 1256 | if (IsEH) { |
Bill Wendling | 3c163cf | 2011-06-30 21:25:51 +0000 | [diff] [blame] | 1257 | if (verboseAsm) streamer.AddComment("CIE Augmentation"); |
Rafael Espindola | 40a7dbb | 2011-05-10 03:54:12 +0000 | [diff] [blame] | 1258 | Augmentation += "z"; |
| 1259 | if (personality) |
| 1260 | Augmentation += "P"; |
| 1261 | if (lsda) |
| 1262 | Augmentation += "L"; |
| 1263 | Augmentation += "R"; |
Rafael Espindola | 16d7d43 | 2012-01-23 21:51:52 +0000 | [diff] [blame] | 1264 | if (IsSignalFrame) |
| 1265 | Augmentation += "S"; |
Eric Christopher | 68ca562 | 2013-01-09 01:57:54 +0000 | [diff] [blame] | 1266 | streamer.EmitBytes(Augmentation.str()); |
Rafael Espindola | 40a7dbb | 2011-05-10 03:54:12 +0000 | [diff] [blame] | 1267 | } |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 1268 | streamer.EmitIntValue(0, 1); |
| 1269 | |
| 1270 | // Code Alignment Factor |
Bill Wendling | 3c163cf | 2011-06-30 21:25:51 +0000 | [diff] [blame] | 1271 | if (verboseAsm) streamer.AddComment("CIE Code Alignment Factor"); |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 1272 | streamer.EmitULEB128IntValue(1); |
| 1273 | |
| 1274 | // Data Alignment Factor |
Bill Wendling | 3c163cf | 2011-06-30 21:25:51 +0000 | [diff] [blame] | 1275 | if (verboseAsm) streamer.AddComment("CIE Data Alignment Factor"); |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 1276 | streamer.EmitSLEB128IntValue(getDataAlignmentFactor(streamer)); |
| 1277 | |
| 1278 | // Return Address Register |
Bill Wendling | 3c163cf | 2011-06-30 21:25:51 +0000 | [diff] [blame] | 1279 | if (verboseAsm) streamer.AddComment("CIE Return Address Column"); |
Evan Cheng | 0e6a052 | 2011-07-18 20:57:22 +0000 | [diff] [blame] | 1280 | streamer.EmitULEB128IntValue(MRI.getDwarfRegNum(MRI.getRARegister(), true)); |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 1281 | |
| 1282 | // Augmentation Data Length (optional) |
Rafael Espindola | 1f6c875 | 2011-04-29 21:50:57 +0000 | [diff] [blame] | 1283 | |
| 1284 | unsigned augmentationLength = 0; |
Rafael Espindola | 40a7dbb | 2011-05-10 03:54:12 +0000 | [diff] [blame] | 1285 | if (IsEH) { |
| 1286 | if (personality) { |
| 1287 | // Personality Encoding |
| 1288 | augmentationLength += 1; |
| 1289 | // Personality |
| 1290 | augmentationLength += getSizeForEncoding(streamer, personalityEncoding); |
| 1291 | } |
| 1292 | if (lsda) |
| 1293 | augmentationLength += 1; |
| 1294 | // Encoding of the FDE pointers |
Rafael Espindola | 1f6c875 | 2011-04-29 21:50:57 +0000 | [diff] [blame] | 1295 | augmentationLength += 1; |
Rafael Espindola | 1f6c875 | 2011-04-29 21:50:57 +0000 | [diff] [blame] | 1296 | |
Bill Wendling | 3c163cf | 2011-06-30 21:25:51 +0000 | [diff] [blame] | 1297 | if (verboseAsm) streamer.AddComment("Augmentation Size"); |
Rafael Espindola | 40a7dbb | 2011-05-10 03:54:12 +0000 | [diff] [blame] | 1298 | streamer.EmitULEB128IntValue(augmentationLength); |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 1299 | |
Rafael Espindola | 40a7dbb | 2011-05-10 03:54:12 +0000 | [diff] [blame] | 1300 | // Augmentation Data (optional) |
| 1301 | if (personality) { |
| 1302 | // Personality Encoding |
Bill Wendling | 3c163cf | 2011-06-30 21:25:51 +0000 | [diff] [blame] | 1303 | EmitEncodingByte(streamer, personalityEncoding, |
| 1304 | "Personality Encoding"); |
Rafael Espindola | 40a7dbb | 2011-05-10 03:54:12 +0000 | [diff] [blame] | 1305 | // Personality |
Bill Wendling | 3c163cf | 2011-06-30 21:25:51 +0000 | [diff] [blame] | 1306 | if (verboseAsm) streamer.AddComment("Personality"); |
Rafael Espindola | 40a7dbb | 2011-05-10 03:54:12 +0000 | [diff] [blame] | 1307 | EmitPersonality(streamer, *personality, personalityEncoding); |
| 1308 | } |
Bill Wendling | 3c163cf | 2011-06-30 21:25:51 +0000 | [diff] [blame] | 1309 | |
Rafael Espindola | 40a7dbb | 2011-05-10 03:54:12 +0000 | [diff] [blame] | 1310 | if (lsda) |
Bill Wendling | 3c163cf | 2011-06-30 21:25:51 +0000 | [diff] [blame] | 1311 | EmitEncodingByte(streamer, lsdaEncoding, "LSDA Encoding"); |
| 1312 | |
Rafael Espindola | 40a7dbb | 2011-05-10 03:54:12 +0000 | [diff] [blame] | 1313 | // Encoding of the FDE pointers |
Evan Cheng | 203576a | 2011-07-20 19:50:42 +0000 | [diff] [blame] | 1314 | EmitEncodingByte(streamer, MOFI->getFDEEncoding(UsingCFI), |
Bill Wendling | 3c163cf | 2011-06-30 21:25:51 +0000 | [diff] [blame] | 1315 | "FDE Encoding"); |
Rafael Espindola | bdc3167 | 2010-12-27 15:56:22 +0000 | [diff] [blame] | 1316 | } |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 1317 | |
| 1318 | // Initial Instructions |
| 1319 | |
Evan Cheng | 2d28617 | 2011-07-18 22:29:13 +0000 | [diff] [blame] | 1320 | const MCAsmInfo &MAI = context.getAsmInfo(); |
| 1321 | const std::vector<MachineMove> &Moves = MAI.getInitialFrameState(); |
Rafael Espindola | fe024d0 | 2010-12-28 18:36:23 +0000 | [diff] [blame] | 1322 | std::vector<MCCFIInstruction> Instructions; |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 1323 | |
Rafael Espindola | fe024d0 | 2010-12-28 18:36:23 +0000 | [diff] [blame] | 1324 | for (int i = 0, n = Moves.size(); i != n; ++i) { |
Rafael Espindola | b40a71f | 2010-12-29 01:42:56 +0000 | [diff] [blame] | 1325 | MCSymbol *Label = Moves[i].getLabel(); |
| 1326 | const MachineLocation &Dst = |
Evan Cheng | 0e6a052 | 2011-07-18 20:57:22 +0000 | [diff] [blame] | 1327 | TranslateMachineLocation(MRI, Moves[i].getDestination()); |
Rafael Espindola | b40a71f | 2010-12-29 01:42:56 +0000 | [diff] [blame] | 1328 | const MachineLocation &Src = |
Evan Cheng | 0e6a052 | 2011-07-18 20:57:22 +0000 | [diff] [blame] | 1329 | TranslateMachineLocation(MRI, Moves[i].getSource()); |
Rafael Espindola | 28c9ea3 | 2012-11-24 02:01:08 +0000 | [diff] [blame] | 1330 | |
| 1331 | if (Dst.isReg()) { |
| 1332 | assert(Dst.getReg() == MachineLocation::VirtualFP); |
| 1333 | assert(!Src.isReg()); |
| 1334 | MCCFIInstruction Inst = |
| 1335 | MCCFIInstruction::createDefCfa(Label, Src.getReg(), -Src.getOffset()); |
| 1336 | Instructions.push_back(Inst); |
| 1337 | } else { |
| 1338 | assert(Src.isReg()); |
| 1339 | unsigned Reg = Src.getReg(); |
| 1340 | int Offset = Dst.getOffset(); |
| 1341 | MCCFIInstruction Inst = |
Rafael Espindola | 7f74d2c | 2012-11-24 03:10:54 +0000 | [diff] [blame] | 1342 | MCCFIInstruction::createOffset(Label, Reg, Offset); |
Rafael Espindola | 28c9ea3 | 2012-11-24 02:01:08 +0000 | [diff] [blame] | 1343 | Instructions.push_back(Inst); |
| 1344 | } |
Rafael Espindola | fe024d0 | 2010-12-28 18:36:23 +0000 | [diff] [blame] | 1345 | } |
| 1346 | |
Rafael Espindola | b40a71f | 2010-12-29 01:42:56 +0000 | [diff] [blame] | 1347 | EmitCFIInstructions(streamer, Instructions, NULL); |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 1348 | |
| 1349 | // Padding |
Evan Cheng | 1be0e27 | 2011-07-15 02:09:41 +0000 | [diff] [blame] | 1350 | streamer.EmitValueToAlignment(IsEH |
| 1351 | ? 4 : context.getAsmInfo().getPointerSize()); |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 1352 | |
| 1353 | streamer.EmitLabel(sectionEnd); |
| 1354 | return *sectionStart; |
| 1355 | } |
| 1356 | |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 1357 | MCSymbol *FrameEmitterImpl::EmitFDE(MCStreamer &streamer, |
| 1358 | const MCSymbol &cieStart, |
Rafael Espindola | 9f270da | 2011-05-10 03:01:39 +0000 | [diff] [blame] | 1359 | const MCDwarfFrameInfo &frame) { |
Rafael Espindola | bdc3167 | 2010-12-27 15:56:22 +0000 | [diff] [blame] | 1360 | MCContext &context = streamer.getContext(); |
| 1361 | MCSymbol *fdeStart = context.CreateTempSymbol(); |
| 1362 | MCSymbol *fdeEnd = context.CreateTempSymbol(); |
Evan Cheng | e76a33b | 2011-07-20 05:58:47 +0000 | [diff] [blame] | 1363 | const MCObjectFileInfo *MOFI = context.getObjectFileInfo(); |
Bill Wendling | 2541c41 | 2011-06-30 22:02:20 +0000 | [diff] [blame] | 1364 | bool verboseAsm = streamer.isVerboseAsm(); |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 1365 | |
Evan Cheng | 5fbe5e7 | 2011-08-24 22:31:37 +0000 | [diff] [blame] | 1366 | if (IsEH && frame.Function && !MOFI->isFunctionEHFrameSymbolPrivate()) { |
Bill Wendling | 2541c41 | 2011-06-30 22:02:20 +0000 | [diff] [blame] | 1367 | MCSymbol *EHSym = |
| 1368 | context.GetOrCreateSymbol(frame.Function->getName() + Twine(".eh")); |
Rafael Espindola | 8bca410 | 2011-04-28 12:50:37 +0000 | [diff] [blame] | 1369 | streamer.EmitEHSymAttributes(frame.Function, EHSym); |
Rafael Espindola | a8cfb87 | 2011-04-28 02:46:42 +0000 | [diff] [blame] | 1370 | streamer.EmitLabel(EHSym); |
| 1371 | } |
| 1372 | |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 1373 | // Length |
| 1374 | const MCExpr *Length = MakeStartMinusEndExpr(streamer, *fdeStart, *fdeEnd, 0); |
Bill Wendling | 2541c41 | 2011-06-30 22:02:20 +0000 | [diff] [blame] | 1375 | if (verboseAsm) streamer.AddComment("FDE Length"); |
Rafael Espindola | 9266cc4 | 2011-04-27 01:43:49 +0000 | [diff] [blame] | 1376 | streamer.EmitAbsValue(Length, 4); |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 1377 | |
| 1378 | streamer.EmitLabel(fdeStart); |
Rafael Espindola | e3a0e98 | 2011-05-10 20:59:42 +0000 | [diff] [blame] | 1379 | |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 1380 | // CIE Pointer |
Rafael Espindola | e3a0e98 | 2011-05-10 20:59:42 +0000 | [diff] [blame] | 1381 | const MCAsmInfo &asmInfo = context.getAsmInfo(); |
Rafael Espindola | 0d450dc | 2011-05-10 15:20:23 +0000 | [diff] [blame] | 1382 | if (IsEH) { |
| 1383 | const MCExpr *offset = MakeStartMinusEndExpr(streamer, cieStart, *fdeStart, |
| 1384 | 0); |
Bill Wendling | 2541c41 | 2011-06-30 22:02:20 +0000 | [diff] [blame] | 1385 | if (verboseAsm) streamer.AddComment("FDE CIE Offset"); |
Rafael Espindola | 0d450dc | 2011-05-10 15:20:23 +0000 | [diff] [blame] | 1386 | streamer.EmitAbsValue(offset, 4); |
Rafael Espindola | 2241e51 | 2012-06-22 13:24:07 +0000 | [diff] [blame] | 1387 | } else if (!asmInfo.doesDwarfUseRelocationsAcrossSections()) { |
Rafael Espindola | e3a0e98 | 2011-05-10 20:59:42 +0000 | [diff] [blame] | 1388 | const MCExpr *offset = MakeStartMinusEndExpr(streamer, *SectionStart, |
| 1389 | cieStart, 0); |
| 1390 | streamer.EmitAbsValue(offset, 4); |
Rafael Espindola | 0d450dc | 2011-05-10 15:20:23 +0000 | [diff] [blame] | 1391 | } else { |
| 1392 | streamer.EmitSymbolValue(&cieStart, 4); |
| 1393 | } |
Bill Wendling | 2541c41 | 2011-06-30 22:02:20 +0000 | [diff] [blame] | 1394 | |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 1395 | // PC Begin |
Nick Lewycky | 0c5602d | 2012-08-12 08:09:45 +0000 | [diff] [blame] | 1396 | unsigned PCEncoding = IsEH ? MOFI->getFDEEncoding(UsingCFI) |
| 1397 | : (unsigned)dwarf::DW_EH_PE_absptr; |
| 1398 | unsigned PCSize = getSizeForEncoding(streamer, PCEncoding); |
| 1399 | EmitSymbol(streamer, *frame.Begin, PCEncoding, "FDE initial location"); |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 1400 | |
| 1401 | // PC Range |
| 1402 | const MCExpr *Range = MakeStartMinusEndExpr(streamer, *frame.Begin, |
| 1403 | *frame.End, 0); |
Bill Wendling | 2541c41 | 2011-06-30 22:02:20 +0000 | [diff] [blame] | 1404 | if (verboseAsm) streamer.AddComment("FDE address range"); |
Nick Lewycky | 0c5602d | 2012-08-12 08:09:45 +0000 | [diff] [blame] | 1405 | streamer.EmitAbsValue(Range, PCSize); |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 1406 | |
Rafael Espindola | 40a7dbb | 2011-05-10 03:54:12 +0000 | [diff] [blame] | 1407 | if (IsEH) { |
| 1408 | // Augmentation Data Length |
| 1409 | unsigned augmentationLength = 0; |
Rafael Espindola | 1f6c875 | 2011-04-29 21:50:57 +0000 | [diff] [blame] | 1410 | |
Rafael Espindola | 40a7dbb | 2011-05-10 03:54:12 +0000 | [diff] [blame] | 1411 | if (frame.Lsda) |
| 1412 | augmentationLength += getSizeForEncoding(streamer, frame.LsdaEncoding); |
Rafael Espindola | 1f6c875 | 2011-04-29 21:50:57 +0000 | [diff] [blame] | 1413 | |
Bill Wendling | 2541c41 | 2011-06-30 22:02:20 +0000 | [diff] [blame] | 1414 | if (verboseAsm) streamer.AddComment("Augmentation size"); |
Rafael Espindola | 40a7dbb | 2011-05-10 03:54:12 +0000 | [diff] [blame] | 1415 | streamer.EmitULEB128IntValue(augmentationLength); |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 1416 | |
Rafael Espindola | 40a7dbb | 2011-05-10 03:54:12 +0000 | [diff] [blame] | 1417 | // Augmentation Data |
| 1418 | if (frame.Lsda) |
Bill Wendling | 2541c41 | 2011-06-30 22:02:20 +0000 | [diff] [blame] | 1419 | EmitSymbol(streamer, *frame.Lsda, frame.LsdaEncoding, |
| 1420 | "Language Specific Data Area"); |
Rafael Espindola | 40a7dbb | 2011-05-10 03:54:12 +0000 | [diff] [blame] | 1421 | } |
Rafael Espindola | 4892dff | 2011-04-29 03:06:29 +0000 | [diff] [blame] | 1422 | |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 1423 | // Call Frame Instructions |
| 1424 | |
Rafael Espindola | b40a71f | 2010-12-29 01:42:56 +0000 | [diff] [blame] | 1425 | EmitCFIInstructions(streamer, frame.Instructions, frame.Begin); |
Rafael Espindola | 5bba084 | 2010-12-28 04:15:37 +0000 | [diff] [blame] | 1426 | |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 1427 | // Padding |
Nick Lewycky | 0c5602d | 2012-08-12 08:09:45 +0000 | [diff] [blame] | 1428 | streamer.EmitValueToAlignment(PCSize); |
Rafael Espindola | dfe125c | 2010-12-17 00:28:02 +0000 | [diff] [blame] | 1429 | |
| 1430 | return fdeEnd; |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 1431 | } |
| 1432 | |
Benjamin Kramer | 1928236 | 2010-12-30 22:34:44 +0000 | [diff] [blame] | 1433 | namespace { |
| 1434 | struct CIEKey { |
Rafael Espindola | 16d7d43 | 2012-01-23 21:51:52 +0000 | [diff] [blame] | 1435 | static const CIEKey getEmptyKey() { return CIEKey(0, 0, -1, false); } |
| 1436 | static const CIEKey getTombstoneKey() { return CIEKey(0, -1, 0, false); } |
Rafael Espindola | bdc3167 | 2010-12-27 15:56:22 +0000 | [diff] [blame] | 1437 | |
Benjamin Kramer | 1928236 | 2010-12-30 22:34:44 +0000 | [diff] [blame] | 1438 | CIEKey(const MCSymbol* Personality_, unsigned PersonalityEncoding_, |
Rafael Espindola | 16d7d43 | 2012-01-23 21:51:52 +0000 | [diff] [blame] | 1439 | unsigned LsdaEncoding_, bool IsSignalFrame_) : |
| 1440 | Personality(Personality_), PersonalityEncoding(PersonalityEncoding_), |
| 1441 | LsdaEncoding(LsdaEncoding_), IsSignalFrame(IsSignalFrame_) { |
Benjamin Kramer | 1928236 | 2010-12-30 22:34:44 +0000 | [diff] [blame] | 1442 | } |
| 1443 | const MCSymbol* Personality; |
| 1444 | unsigned PersonalityEncoding; |
| 1445 | unsigned LsdaEncoding; |
Rafael Espindola | 16d7d43 | 2012-01-23 21:51:52 +0000 | [diff] [blame] | 1446 | bool IsSignalFrame; |
Benjamin Kramer | 1928236 | 2010-12-30 22:34:44 +0000 | [diff] [blame] | 1447 | }; |
| 1448 | } |
Rafael Espindola | bdc3167 | 2010-12-27 15:56:22 +0000 | [diff] [blame] | 1449 | |
| 1450 | namespace llvm { |
| 1451 | template <> |
| 1452 | struct DenseMapInfo<CIEKey> { |
| 1453 | static CIEKey getEmptyKey() { |
Benjamin Kramer | 1928236 | 2010-12-30 22:34:44 +0000 | [diff] [blame] | 1454 | return CIEKey::getEmptyKey(); |
Rafael Espindola | bdc3167 | 2010-12-27 15:56:22 +0000 | [diff] [blame] | 1455 | } |
| 1456 | static CIEKey getTombstoneKey() { |
Benjamin Kramer | 1928236 | 2010-12-30 22:34:44 +0000 | [diff] [blame] | 1457 | return CIEKey::getTombstoneKey(); |
Rafael Espindola | bdc3167 | 2010-12-27 15:56:22 +0000 | [diff] [blame] | 1458 | } |
| 1459 | static unsigned getHashValue(const CIEKey &Key) { |
Benjamin Kramer | 7484920 | 2012-04-11 14:06:39 +0000 | [diff] [blame] | 1460 | return static_cast<unsigned>(hash_combine(Key.Personality, |
| 1461 | Key.PersonalityEncoding, |
| 1462 | Key.LsdaEncoding, |
| 1463 | Key.IsSignalFrame)); |
Rafael Espindola | bdc3167 | 2010-12-27 15:56:22 +0000 | [diff] [blame] | 1464 | } |
| 1465 | static bool isEqual(const CIEKey &LHS, |
| 1466 | const CIEKey &RHS) { |
| 1467 | return LHS.Personality == RHS.Personality && |
| 1468 | LHS.PersonalityEncoding == RHS.PersonalityEncoding && |
Rafael Espindola | 16d7d43 | 2012-01-23 21:51:52 +0000 | [diff] [blame] | 1469 | LHS.LsdaEncoding == RHS.LsdaEncoding && |
| 1470 | LHS.IsSignalFrame == RHS.IsSignalFrame; |
Rafael Espindola | bdc3167 | 2010-12-27 15:56:22 +0000 | [diff] [blame] | 1471 | } |
| 1472 | }; |
| 1473 | } |
| 1474 | |
Bill Wendling | a8c9e6a | 2011-06-23 07:44:54 +0000 | [diff] [blame] | 1475 | void MCDwarfFrameEmitter::Emit(MCStreamer &Streamer, |
| 1476 | bool UsingCFI, |
| 1477 | bool IsEH) { |
| 1478 | MCContext &Context = Streamer.getContext(); |
Evan Cheng | e76a33b | 2011-07-20 05:58:47 +0000 | [diff] [blame] | 1479 | MCObjectFileInfo *MOFI = |
| 1480 | const_cast<MCObjectFileInfo*>(Context.getObjectFileInfo()); |
Bill Wendling | 1424c3c | 2011-07-22 21:18:59 +0000 | [diff] [blame] | 1481 | FrameEmitterImpl Emitter(UsingCFI, IsEH); |
Bill Wendling | d8ab8e9 | 2011-09-06 18:37:11 +0000 | [diff] [blame] | 1482 | ArrayRef<MCDwarfFrameInfo> FrameArray = Streamer.getFrameInfos(); |
Bill Wendling | 1424c3c | 2011-07-22 21:18:59 +0000 | [diff] [blame] | 1483 | |
Bill Wendling | d8ab8e9 | 2011-09-06 18:37:11 +0000 | [diff] [blame] | 1484 | // Emit the compact unwind info if available. |
Bill Wendling | 7a13b72 | 2011-12-15 00:14:24 +0000 | [diff] [blame] | 1485 | if (IsEH && MOFI->getCompactUnwindSection()) |
Bill Wendling | 1424c3c | 2011-07-22 21:18:59 +0000 | [diff] [blame] | 1486 | for (unsigned i = 0, n = Streamer.getNumFrameInfos(); i < n; ++i) { |
| 1487 | const MCDwarfFrameInfo &Frame = Streamer.getFrameInfo(i); |
Bill Wendling | a2ff3e2 | 2011-11-08 22:23:43 +0000 | [diff] [blame] | 1488 | if (Frame.CompactUnwindEncoding) |
Bill Wendling | d8ab8e9 | 2011-09-06 18:37:11 +0000 | [diff] [blame] | 1489 | Emitter.EmitCompactUnwind(Streamer, Frame); |
Bill Wendling | 1424c3c | 2011-07-22 21:18:59 +0000 | [diff] [blame] | 1490 | } |
| 1491 | |
Evan Cheng | e76a33b | 2011-07-20 05:58:47 +0000 | [diff] [blame] | 1492 | const MCSection &Section = IsEH ? *MOFI->getEHFrameSection() : |
| 1493 | *MOFI->getDwarfFrameSection(); |
Bill Wendling | a8c9e6a | 2011-06-23 07:44:54 +0000 | [diff] [blame] | 1494 | Streamer.SwitchSection(&Section); |
| 1495 | MCSymbol *SectionStart = Context.CreateTempSymbol(); |
| 1496 | Streamer.EmitLabel(SectionStart); |
Bill Wendling | 1424c3c | 2011-07-22 21:18:59 +0000 | [diff] [blame] | 1497 | Emitter.setSectionStart(SectionStart); |
Rafael Espindola | 9099813 | 2011-04-29 02:42:28 +0000 | [diff] [blame] | 1498 | |
Bill Wendling | a8c9e6a | 2011-06-23 07:44:54 +0000 | [diff] [blame] | 1499 | MCSymbol *FDEEnd = NULL; |
Rafael Espindola | bdc3167 | 2010-12-27 15:56:22 +0000 | [diff] [blame] | 1500 | DenseMap<CIEKey, const MCSymbol*> CIEStarts; |
Rafael Espindola | d7c8cca | 2010-12-26 20:20:31 +0000 | [diff] [blame] | 1501 | |
Rafael Espindola | 40a7dbb | 2011-05-10 03:54:12 +0000 | [diff] [blame] | 1502 | const MCSymbol *DummyDebugKey = NULL; |
Bill Wendling | 1424c3c | 2011-07-22 21:18:59 +0000 | [diff] [blame] | 1503 | for (unsigned i = 0, n = FrameArray.size(); i < n; ++i) { |
| 1504 | const MCDwarfFrameInfo &Frame = FrameArray[i]; |
Bill Wendling | a8c9e6a | 2011-06-23 07:44:54 +0000 | [diff] [blame] | 1505 | CIEKey Key(Frame.Personality, Frame.PersonalityEncoding, |
Rafael Espindola | 16d7d43 | 2012-01-23 21:51:52 +0000 | [diff] [blame] | 1506 | Frame.LsdaEncoding, Frame.IsSignalFrame); |
Bill Wendling | a8c9e6a | 2011-06-23 07:44:54 +0000 | [diff] [blame] | 1507 | const MCSymbol *&CIEStart = IsEH ? CIEStarts[Key] : DummyDebugKey; |
| 1508 | if (!CIEStart) |
| 1509 | CIEStart = &Emitter.EmitCIE(Streamer, Frame.Personality, |
| 1510 | Frame.PersonalityEncoding, Frame.Lsda, |
Rafael Espindola | 16d7d43 | 2012-01-23 21:51:52 +0000 | [diff] [blame] | 1511 | Frame.IsSignalFrame, |
Bill Wendling | a8c9e6a | 2011-06-23 07:44:54 +0000 | [diff] [blame] | 1512 | Frame.LsdaEncoding); |
Bill Wendling | e3cd13f | 2011-06-23 01:06:23 +0000 | [diff] [blame] | 1513 | |
Bill Wendling | a8c9e6a | 2011-06-23 07:44:54 +0000 | [diff] [blame] | 1514 | FDEEnd = Emitter.EmitFDE(Streamer, *CIEStart, Frame); |
Bill Wendling | e3cd13f | 2011-06-23 01:06:23 +0000 | [diff] [blame] | 1515 | |
Rafael Espindola | dfe125c | 2010-12-17 00:28:02 +0000 | [diff] [blame] | 1516 | if (i != n - 1) |
Bill Wendling | a8c9e6a | 2011-06-23 07:44:54 +0000 | [diff] [blame] | 1517 | Streamer.EmitLabel(FDEEnd); |
Rafael Espindola | dfe125c | 2010-12-17 00:28:02 +0000 | [diff] [blame] | 1518 | } |
Rafael Espindola | d7c8cca | 2010-12-26 20:20:31 +0000 | [diff] [blame] | 1519 | |
Evan Cheng | 1be0e27 | 2011-07-15 02:09:41 +0000 | [diff] [blame] | 1520 | Streamer.EmitValueToAlignment(Context.getAsmInfo().getPointerSize()); |
Bill Wendling | a8c9e6a | 2011-06-23 07:44:54 +0000 | [diff] [blame] | 1521 | if (FDEEnd) |
| 1522 | Streamer.EmitLabel(FDEEnd); |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 1523 | } |
Rafael Espindola | 245a1e2 | 2010-12-28 05:39:27 +0000 | [diff] [blame] | 1524 | |
| 1525 | void MCDwarfFrameEmitter::EmitAdvanceLoc(MCStreamer &Streamer, |
| 1526 | uint64_t AddrDelta) { |
| 1527 | SmallString<256> Tmp; |
| 1528 | raw_svector_ostream OS(Tmp); |
Rafael Espindola | 4eafe10 | 2011-05-08 14:35:21 +0000 | [diff] [blame] | 1529 | MCDwarfFrameEmitter::EncodeAdvanceLoc(AddrDelta, OS); |
Eric Christopher | 68ca562 | 2013-01-09 01:57:54 +0000 | [diff] [blame] | 1530 | Streamer.EmitBytes(OS.str()); |
Rafael Espindola | 245a1e2 | 2010-12-28 05:39:27 +0000 | [diff] [blame] | 1531 | } |
| 1532 | |
| 1533 | void MCDwarfFrameEmitter::EncodeAdvanceLoc(uint64_t AddrDelta, |
Rafael Espindola | 4eafe10 | 2011-05-08 14:35:21 +0000 | [diff] [blame] | 1534 | raw_ostream &OS) { |
Rafael Espindola | 245a1e2 | 2010-12-28 05:39:27 +0000 | [diff] [blame] | 1535 | // FIXME: Assumes the code alignment factor is 1. |
Rafael Espindola | 3b78cdc | 2010-12-28 23:38:03 +0000 | [diff] [blame] | 1536 | if (AddrDelta == 0) { |
Rafael Espindola | 4eafe10 | 2011-05-08 14:35:21 +0000 | [diff] [blame] | 1537 | } else if (isUIntN(6, AddrDelta)) { |
Rafael Espindola | 245a1e2 | 2010-12-28 05:39:27 +0000 | [diff] [blame] | 1538 | uint8_t Opcode = dwarf::DW_CFA_advance_loc | AddrDelta; |
| 1539 | OS << Opcode; |
Rafael Espindola | 4eafe10 | 2011-05-08 14:35:21 +0000 | [diff] [blame] | 1540 | } else if (isUInt<8>(AddrDelta)) { |
Rafael Espindola | 245a1e2 | 2010-12-28 05:39:27 +0000 | [diff] [blame] | 1541 | OS << uint8_t(dwarf::DW_CFA_advance_loc1); |
| 1542 | OS << uint8_t(AddrDelta); |
Rafael Espindola | 4eafe10 | 2011-05-08 14:35:21 +0000 | [diff] [blame] | 1543 | } else if (isUInt<16>(AddrDelta)) { |
Rafael Espindola | a7e4505 | 2010-12-29 02:30:49 +0000 | [diff] [blame] | 1544 | // FIXME: check what is the correct behavior on a big endian machine. |
Rafael Espindola | 245a1e2 | 2010-12-28 05:39:27 +0000 | [diff] [blame] | 1545 | OS << uint8_t(dwarf::DW_CFA_advance_loc2); |
Rafael Espindola | a7e4505 | 2010-12-29 02:30:49 +0000 | [diff] [blame] | 1546 | OS << uint8_t( AddrDelta & 0xff); |
| 1547 | OS << uint8_t((AddrDelta >> 8) & 0xff); |
Rafael Espindola | 245a1e2 | 2010-12-28 05:39:27 +0000 | [diff] [blame] | 1548 | } else { |
Rafael Espindola | a7e4505 | 2010-12-29 02:30:49 +0000 | [diff] [blame] | 1549 | // FIXME: check what is the correct behavior on a big endian machine. |
Rafael Espindola | 245a1e2 | 2010-12-28 05:39:27 +0000 | [diff] [blame] | 1550 | assert(isUInt<32>(AddrDelta)); |
| 1551 | OS << uint8_t(dwarf::DW_CFA_advance_loc4); |
Rafael Espindola | a7e4505 | 2010-12-29 02:30:49 +0000 | [diff] [blame] | 1552 | OS << uint8_t( AddrDelta & 0xff); |
| 1553 | OS << uint8_t((AddrDelta >> 8) & 0xff); |
| 1554 | OS << uint8_t((AddrDelta >> 16) & 0xff); |
| 1555 | OS << uint8_t((AddrDelta >> 24) & 0xff); |
| 1556 | |
Rafael Espindola | 245a1e2 | 2010-12-28 05:39:27 +0000 | [diff] [blame] | 1557 | } |
| 1558 | } |