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 | |
Rafael Espindola | 767b1be | 2010-12-04 00:31:13 +0000 | [diff] [blame] | 10 | #include "llvm/MC/MCAsmInfo.h" |
Kevin Enderby | 7cbf73a | 2010-07-28 20:55:35 +0000 | [diff] [blame] | 11 | #include "llvm/MC/MCDwarf.h" |
Rafael Espindola | ad8aaa0 | 2010-11-22 11:53:17 +0000 | [diff] [blame] | 12 | #include "llvm/MC/MCStreamer.h" |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 13 | #include "llvm/MC/MCSymbol.h" |
| 14 | #include "llvm/MC/MCExpr.h" |
| 15 | #include "llvm/MC/MCContext.h" |
| 16 | #include "llvm/MC/MCObjectWriter.h" |
Kevin Enderby | 7cbf73a | 2010-07-28 20:55:35 +0000 | [diff] [blame] | 17 | #include "llvm/Support/Debug.h" |
Rafael Espindola | fe024d0 | 2010-12-28 18:36:23 +0000 | [diff] [blame] | 18 | #include "llvm/Support/ErrorHandling.h" |
Kevin Enderby | 7cbf73a | 2010-07-28 20:55:35 +0000 | [diff] [blame] | 19 | #include "llvm/Support/raw_ostream.h" |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 20 | #include "llvm/Target/TargetAsmInfo.h" |
Bill Wendling | 2b2dc7c | 2011-07-06 22:52:32 +0000 | [diff] [blame^] | 21 | #include "llvm/ADT/FoldingSet.h" |
| 22 | #include "llvm/ADT/SmallString.h" |
| 23 | #include "llvm/ADT/StringExtras.h" |
| 24 | #include "llvm/ADT/Twine.h" |
Kevin Enderby | 7cbf73a | 2010-07-28 20:55:35 +0000 | [diff] [blame] | 25 | using namespace llvm; |
| 26 | |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 27 | // Given a special op, return the address skip amount (in units of |
| 28 | // DWARF2_LINE_MIN_INSN_LENGTH. |
| 29 | #define SPECIAL_ADDR(op) (((op) - DWARF2_LINE_OPCODE_BASE)/DWARF2_LINE_RANGE) |
| 30 | |
| 31 | // 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] | 32 | #define MAX_SPECIAL_ADDR_DELTA SPECIAL_ADDR(255) |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 33 | |
| 34 | // First special line opcode - leave room for the standard opcodes. |
| 35 | // Note: If you want to change this, you'll have to update the |
| 36 | // "standard_opcode_lengths" table that is emitted in DwarfFileTable::Emit(). |
Bill Wendling | c388216 | 2011-06-30 23:59:38 +0000 | [diff] [blame] | 37 | #define DWARF2_LINE_OPCODE_BASE 13 |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 38 | |
| 39 | // Minimum line offset in a special line info. opcode. This value |
| 40 | // was chosen to give a reasonable range of values. |
Bill Wendling | c388216 | 2011-06-30 23:59:38 +0000 | [diff] [blame] | 41 | #define DWARF2_LINE_BASE -5 |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 42 | |
| 43 | // Range of line offsets in a special line info. opcode. |
Bill Wendling | c388216 | 2011-06-30 23:59:38 +0000 | [diff] [blame] | 44 | #define DWARF2_LINE_RANGE 14 |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 45 | |
| 46 | // Define the architecture-dependent minimum instruction length (in bytes). |
| 47 | // This value should be rather too small than too big. |
Bill Wendling | c388216 | 2011-06-30 23:59:38 +0000 | [diff] [blame] | 48 | #define DWARF2_LINE_MIN_INSN_LENGTH 1 |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 49 | |
| 50 | // Note: when DWARF2_LINE_MIN_INSN_LENGTH == 1 which is the current setting, |
| 51 | // this routine is a nop and will be optimized away. |
Bill Wendling | a8c9e6a | 2011-06-23 07:44:54 +0000 | [diff] [blame] | 52 | static inline uint64_t ScaleAddrDelta(uint64_t AddrDelta) { |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 53 | if (DWARF2_LINE_MIN_INSN_LENGTH == 1) |
| 54 | return AddrDelta; |
| 55 | if (AddrDelta % DWARF2_LINE_MIN_INSN_LENGTH != 0) { |
| 56 | // TODO: report this error, but really only once. |
| 57 | ; |
| 58 | } |
| 59 | return AddrDelta / DWARF2_LINE_MIN_INSN_LENGTH; |
| 60 | } |
| 61 | |
| 62 | // |
| 63 | // This is called when an instruction is assembled into the specified section |
| 64 | // and if there is information from the last .loc directive that has yet to have |
| 65 | // a line entry made for it is made. |
| 66 | // |
Rafael Espindola | 195a0ce | 2010-11-19 02:26:16 +0000 | [diff] [blame] | 67 | void MCLineEntry::Make(MCStreamer *MCOS, const MCSection *Section) { |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 68 | if (!MCOS->getContext().getDwarfLocSeen()) |
| 69 | return; |
| 70 | |
| 71 | // Create a symbol at in the current section for use in the line entry. |
| 72 | MCSymbol *LineSym = MCOS->getContext().CreateTempSymbol(); |
| 73 | // Set the value of the symbol to use for the MCLineEntry. |
| 74 | MCOS->EmitLabel(LineSym); |
| 75 | |
| 76 | // Get the current .loc info saved in the context. |
| 77 | const MCDwarfLoc &DwarfLoc = MCOS->getContext().getCurrentDwarfLoc(); |
| 78 | |
| 79 | // Create a (local) line entry with the symbol and the current .loc info. |
| 80 | MCLineEntry LineEntry(LineSym, DwarfLoc); |
| 81 | |
| 82 | // clear DwarfLocSeen saying the current .loc info is now used. |
Kevin Enderby | 3f55c24 | 2010-10-04 20:17:24 +0000 | [diff] [blame] | 83 | MCOS->getContext().ClearDwarfLocSeen(); |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 84 | |
| 85 | // Get the MCLineSection for this section, if one does not exist for this |
| 86 | // section create it. |
Rafael Espindola | 17fd7bd | 2010-11-19 07:41:23 +0000 | [diff] [blame] | 87 | const DenseMap<const MCSection *, MCLineSection *> &MCLineSections = |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 88 | MCOS->getContext().getMCLineSections(); |
Rafael Espindola | 17fd7bd | 2010-11-19 07:41:23 +0000 | [diff] [blame] | 89 | MCLineSection *LineSection = MCLineSections.lookup(Section); |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 90 | if (!LineSection) { |
| 91 | // Create a new MCLineSection. This will be deleted after the dwarf line |
| 92 | // table is created using it by iterating through the MCLineSections |
| 93 | // DenseMap. |
| 94 | LineSection = new MCLineSection; |
| 95 | // Save a pointer to the new LineSection into the MCLineSections DenseMap. |
Rafael Espindola | 17fd7bd | 2010-11-19 07:41:23 +0000 | [diff] [blame] | 96 | MCOS->getContext().addMCLineSection(Section, LineSection); |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | // Add the line entry to this section's entries. |
| 100 | LineSection->addLineEntry(LineEntry); |
| 101 | } |
| 102 | |
| 103 | // |
| 104 | // This helper routine returns an expression of End - Start + IntVal . |
| 105 | // |
Rafael Espindola | 5fad7a9 | 2010-12-09 23:08:35 +0000 | [diff] [blame] | 106 | static inline const MCExpr *MakeStartMinusEndExpr(const MCStreamer &MCOS, |
| 107 | const MCSymbol &Start, |
| 108 | const MCSymbol &End, |
| 109 | int IntVal) { |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 110 | MCSymbolRefExpr::VariantKind Variant = MCSymbolRefExpr::VK_None; |
| 111 | const MCExpr *Res = |
Rafael Espindola | 5fad7a9 | 2010-12-09 23:08:35 +0000 | [diff] [blame] | 112 | MCSymbolRefExpr::Create(&End, Variant, MCOS.getContext()); |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 113 | const MCExpr *RHS = |
Rafael Espindola | 5fad7a9 | 2010-12-09 23:08:35 +0000 | [diff] [blame] | 114 | MCSymbolRefExpr::Create(&Start, Variant, MCOS.getContext()); |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 115 | const MCExpr *Res1 = |
Rafael Espindola | 5fad7a9 | 2010-12-09 23:08:35 +0000 | [diff] [blame] | 116 | MCBinaryExpr::Create(MCBinaryExpr::Sub, Res, RHS, MCOS.getContext()); |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 117 | const MCExpr *Res2 = |
Rafael Espindola | 5fad7a9 | 2010-12-09 23:08:35 +0000 | [diff] [blame] | 118 | MCConstantExpr::Create(IntVal, MCOS.getContext()); |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 119 | const MCExpr *Res3 = |
Rafael Espindola | 5fad7a9 | 2010-12-09 23:08:35 +0000 | [diff] [blame] | 120 | MCBinaryExpr::Create(MCBinaryExpr::Sub, Res1, Res2, MCOS.getContext()); |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 121 | return Res3; |
| 122 | } |
| 123 | |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 124 | // |
| 125 | // This emits the Dwarf line table for the specified section from the entries |
| 126 | // in the LineSection. |
| 127 | // |
Rafael Espindola | 195a0ce | 2010-11-19 02:26:16 +0000 | [diff] [blame] | 128 | static inline void EmitDwarfLineTable(MCStreamer *MCOS, |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 129 | const MCSection *Section, |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 130 | const MCLineSection *LineSection) { |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 131 | unsigned FileNum = 1; |
| 132 | unsigned LastLine = 1; |
| 133 | unsigned Column = 0; |
| 134 | unsigned Flags = DWARF2_LINE_DEFAULT_IS_STMT ? DWARF2_FLAG_IS_STMT : 0; |
| 135 | unsigned Isa = 0; |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 136 | MCSymbol *LastLabel = NULL; |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 137 | |
| 138 | // Loop through each MCLineEntry and encode the dwarf line number table. |
Rafael Espindola | 17fd7bd | 2010-11-19 07:41:23 +0000 | [diff] [blame] | 139 | for (MCLineSection::const_iterator |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 140 | it = LineSection->getMCLineEntries()->begin(), |
| 141 | ie = LineSection->getMCLineEntries()->end(); it != ie; ++it) { |
| 142 | |
| 143 | if (FileNum != it->getFileNum()) { |
| 144 | FileNum = it->getFileNum(); |
| 145 | MCOS->EmitIntValue(dwarf::DW_LNS_set_file, 1); |
Rafael Espindola | 3ff5709 | 2010-11-02 17:22:24 +0000 | [diff] [blame] | 146 | MCOS->EmitULEB128IntValue(FileNum); |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 147 | } |
| 148 | if (Column != it->getColumn()) { |
| 149 | Column = it->getColumn(); |
| 150 | MCOS->EmitIntValue(dwarf::DW_LNS_set_column, 1); |
Rafael Espindola | 3ff5709 | 2010-11-02 17:22:24 +0000 | [diff] [blame] | 151 | MCOS->EmitULEB128IntValue(Column); |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 152 | } |
| 153 | if (Isa != it->getIsa()) { |
| 154 | Isa = it->getIsa(); |
| 155 | MCOS->EmitIntValue(dwarf::DW_LNS_set_isa, 1); |
Rafael Espindola | 3ff5709 | 2010-11-02 17:22:24 +0000 | [diff] [blame] | 156 | MCOS->EmitULEB128IntValue(Isa); |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 157 | } |
| 158 | if ((it->getFlags() ^ Flags) & DWARF2_FLAG_IS_STMT) { |
| 159 | Flags = it->getFlags(); |
| 160 | MCOS->EmitIntValue(dwarf::DW_LNS_negate_stmt, 1); |
| 161 | } |
| 162 | if (it->getFlags() & DWARF2_FLAG_BASIC_BLOCK) |
| 163 | MCOS->EmitIntValue(dwarf::DW_LNS_set_basic_block, 1); |
| 164 | if (it->getFlags() & DWARF2_FLAG_PROLOGUE_END) |
| 165 | MCOS->EmitIntValue(dwarf::DW_LNS_set_prologue_end, 1); |
| 166 | if (it->getFlags() & DWARF2_FLAG_EPILOGUE_BEGIN) |
| 167 | MCOS->EmitIntValue(dwarf::DW_LNS_set_epilogue_begin, 1); |
| 168 | |
Rafael Espindola | 64185cc | 2010-11-13 01:06:27 +0000 | [diff] [blame] | 169 | int64_t LineDelta = static_cast<int64_t>(it->getLine()) - LastLine; |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 170 | MCSymbol *Label = it->getLabel(); |
| 171 | |
| 172 | // At this point we want to emit/create the sequence to encode the delta in |
| 173 | // line numbers and the increment of the address from the previous Label |
| 174 | // and the current Label. |
Rafael Espindola | 32a006e | 2010-12-03 00:55:40 +0000 | [diff] [blame] | 175 | MCOS->EmitDwarfAdvanceLineAddr(LineDelta, LastLabel, Label); |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 176 | |
| 177 | LastLine = it->getLine(); |
| 178 | LastLabel = Label; |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | // Emit a DW_LNE_end_sequence for the end of the section. |
| 182 | // Using the pointer Section create a temporary label at the end of the |
| 183 | // section and use that and the LastLabel to compute the address delta |
| 184 | // and use INT64_MAX as the line delta which is the signal that this is |
| 185 | // actually a DW_LNE_end_sequence. |
| 186 | |
| 187 | // Switch to the section to be able to create a symbol at its end. |
| 188 | MCOS->SwitchSection(Section); |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 189 | |
| 190 | MCContext &context = MCOS->getContext(); |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 191 | // Create a symbol at the end of the section. |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 192 | MCSymbol *SectionEnd = context.CreateTempSymbol(); |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 193 | // Set the value of the symbol, as we are at the end of the section. |
| 194 | MCOS->EmitLabel(SectionEnd); |
| 195 | |
| 196 | // Switch back the the dwarf line section. |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 197 | MCOS->SwitchSection(context.getTargetAsmInfo().getDwarfLineSection()); |
Rafael Espindola | 195a0ce | 2010-11-19 02:26:16 +0000 | [diff] [blame] | 198 | |
Rafael Espindola | 32a006e | 2010-12-03 00:55:40 +0000 | [diff] [blame] | 199 | MCOS->EmitDwarfAdvanceLineAddr(INT64_MAX, LastLabel, SectionEnd); |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | // |
| 203 | // This emits the Dwarf file and the line tables. |
| 204 | // |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 205 | void MCDwarfFileTable::Emit(MCStreamer *MCOS) { |
| 206 | MCContext &context = MCOS->getContext(); |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 207 | // Switch to the section where the table will be emitted into. |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 208 | MCOS->SwitchSection(context.getTargetAsmInfo().getDwarfLineSection()); |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 209 | |
| 210 | // Create a symbol at the beginning of this section. |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 211 | MCSymbol *LineStartSym = context.CreateTempSymbol(); |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 212 | // Set the value of the symbol, as we are at the start of the section. |
| 213 | MCOS->EmitLabel(LineStartSym); |
| 214 | |
| 215 | // 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] | 216 | MCSymbol *LineEndSym = context.CreateTempSymbol(); |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 217 | |
| 218 | // The first 4 bytes is the total length of the information for this |
| 219 | // compilation unit (not including these 4 bytes for the length). |
Rafael Espindola | 5fad7a9 | 2010-12-09 23:08:35 +0000 | [diff] [blame] | 220 | MCOS->EmitAbsValue(MakeStartMinusEndExpr(*MCOS, *LineStartSym, *LineEndSym,4), |
Rafael Espindola | 0bbe0b4 | 2010-12-06 17:27:56 +0000 | [diff] [blame] | 221 | 4); |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 222 | |
| 223 | // Next 2 bytes is the Version, which is Dwarf 2. |
| 224 | MCOS->EmitIntValue(2, 2); |
| 225 | |
| 226 | // 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] | 227 | MCSymbol *ProEndSym = context.CreateTempSymbol(); // Lprologue_end |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 228 | |
| 229 | // Length of the prologue, is the next 4 bytes. Which is the start of the |
| 230 | // section to the end of the prologue. Not including the 4 bytes for the |
| 231 | // total length, the 2 bytes for the version, and these 4 bytes for the |
| 232 | // length of the prologue. |
Rafael Espindola | 5fad7a9 | 2010-12-09 23:08:35 +0000 | [diff] [blame] | 233 | MCOS->EmitAbsValue(MakeStartMinusEndExpr(*MCOS, *LineStartSym, *ProEndSym, |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 234 | (4 + 2 + 4)), |
Rafael Espindola | 5d4918d | 2010-12-04 03:21:47 +0000 | [diff] [blame] | 235 | 4, 0); |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 236 | |
| 237 | // Parameters of the state machine, are next. |
| 238 | MCOS->EmitIntValue(DWARF2_LINE_MIN_INSN_LENGTH, 1); |
| 239 | MCOS->EmitIntValue(DWARF2_LINE_DEFAULT_IS_STMT, 1); |
| 240 | MCOS->EmitIntValue(DWARF2_LINE_BASE, 1); |
| 241 | MCOS->EmitIntValue(DWARF2_LINE_RANGE, 1); |
| 242 | MCOS->EmitIntValue(DWARF2_LINE_OPCODE_BASE, 1); |
| 243 | |
| 244 | // Standard opcode lengths |
| 245 | MCOS->EmitIntValue(0, 1); // length of DW_LNS_copy |
| 246 | MCOS->EmitIntValue(1, 1); // length of DW_LNS_advance_pc |
| 247 | MCOS->EmitIntValue(1, 1); // length of DW_LNS_advance_line |
| 248 | MCOS->EmitIntValue(1, 1); // length of DW_LNS_set_file |
| 249 | MCOS->EmitIntValue(1, 1); // length of DW_LNS_set_column |
| 250 | MCOS->EmitIntValue(0, 1); // length of DW_LNS_negate_stmt |
| 251 | MCOS->EmitIntValue(0, 1); // length of DW_LNS_set_basic_block |
| 252 | MCOS->EmitIntValue(0, 1); // length of DW_LNS_const_add_pc |
| 253 | MCOS->EmitIntValue(1, 1); // length of DW_LNS_fixed_advance_pc |
| 254 | MCOS->EmitIntValue(0, 1); // length of DW_LNS_set_prologue_end |
| 255 | MCOS->EmitIntValue(0, 1); // length of DW_LNS_set_epilogue_begin |
| 256 | MCOS->EmitIntValue(1, 1); // DW_LNS_set_isa |
| 257 | |
| 258 | // Put out the directory and file tables. |
| 259 | |
| 260 | // First the directory table. |
| 261 | const std::vector<StringRef> &MCDwarfDirs = |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 262 | context.getMCDwarfDirs(); |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 263 | for (unsigned i = 0; i < MCDwarfDirs.size(); i++) { |
| 264 | MCOS->EmitBytes(MCDwarfDirs[i], 0); // the DirectoryName |
| 265 | MCOS->EmitBytes(StringRef("\0", 1), 0); // the null term. of the string |
| 266 | } |
| 267 | MCOS->EmitIntValue(0, 1); // Terminate the directory list |
| 268 | |
| 269 | // Second the file table. |
| 270 | const std::vector<MCDwarfFile *> &MCDwarfFiles = |
| 271 | MCOS->getContext().getMCDwarfFiles(); |
| 272 | for (unsigned i = 1; i < MCDwarfFiles.size(); i++) { |
| 273 | MCOS->EmitBytes(MCDwarfFiles[i]->getName(), 0); // FileName |
| 274 | MCOS->EmitBytes(StringRef("\0", 1), 0); // the null term. of the string |
Rafael Espindola | 3ff5709 | 2010-11-02 17:22:24 +0000 | [diff] [blame] | 275 | // the Directory num |
| 276 | MCOS->EmitULEB128IntValue(MCDwarfFiles[i]->getDirIndex()); |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 277 | MCOS->EmitIntValue(0, 1); // last modification timestamp (always 0) |
| 278 | MCOS->EmitIntValue(0, 1); // filesize (always 0) |
| 279 | } |
| 280 | MCOS->EmitIntValue(0, 1); // Terminate the file list |
| 281 | |
| 282 | // This is the end of the prologue, so set the value of the symbol at the |
| 283 | // end of the prologue (that was used in a previous expression). |
| 284 | MCOS->EmitLabel(ProEndSym); |
| 285 | |
| 286 | // Put out the line tables. |
Rafael Espindola | 17fd7bd | 2010-11-19 07:41:23 +0000 | [diff] [blame] | 287 | const DenseMap<const MCSection *, MCLineSection *> &MCLineSections = |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 288 | MCOS->getContext().getMCLineSections(); |
Rafael Espindola | 17fd7bd | 2010-11-19 07:41:23 +0000 | [diff] [blame] | 289 | const std::vector<const MCSection *> &MCLineSectionOrder = |
| 290 | MCOS->getContext().getMCLineSectionOrder(); |
| 291 | for (std::vector<const MCSection*>::const_iterator it = |
Bill Wendling | c388216 | 2011-06-30 23:59:38 +0000 | [diff] [blame] | 292 | MCLineSectionOrder.begin(), ie = MCLineSectionOrder.end(); it != ie; |
Rafael Espindola | 17fd7bd | 2010-11-19 07:41:23 +0000 | [diff] [blame] | 293 | ++it) { |
| 294 | const MCSection *Sec = *it; |
| 295 | const MCLineSection *Line = MCLineSections.lookup(Sec); |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 296 | EmitDwarfLineTable(MCOS, Sec, Line); |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 297 | |
| 298 | // Now delete the MCLineSections that were created in MCLineEntry::Make() |
| 299 | // and used to emit the line table. |
Rafael Espindola | 17fd7bd | 2010-11-19 07:41:23 +0000 | [diff] [blame] | 300 | delete Line; |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 301 | } |
| 302 | |
Rafael Espindola | 767b1be | 2010-12-04 00:31:13 +0000 | [diff] [blame] | 303 | if (MCOS->getContext().getAsmInfo().getLinkerRequiresNonEmptyDwarfLines() |
| 304 | && MCLineSectionOrder.begin() == MCLineSectionOrder.end()) { |
Rafael Espindola | a8de83c | 2010-12-03 23:36:59 +0000 | [diff] [blame] | 305 | // The darwin9 linker has a bug (see PR8715). For for 32-bit architectures |
| 306 | // it requires: |
| 307 | // total_length >= prologue_length + 10 |
| 308 | // We are 4 bytes short, since we have total_length = 51 and |
| 309 | // prologue_length = 45 |
Devang Patel | 5113cdb | 2010-12-03 00:10:48 +0000 | [diff] [blame] | 310 | |
Rafael Espindola | a8de83c | 2010-12-03 23:36:59 +0000 | [diff] [blame] | 311 | // The regular end_sequence should be sufficient. |
| 312 | MCDwarfLineAddr::Emit(MCOS, INT64_MAX, 0); |
Devang Patel | 5113cdb | 2010-12-03 00:10:48 +0000 | [diff] [blame] | 313 | } |
| 314 | |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 315 | // This is the end of the section, so set the value of the symbol at the end |
| 316 | // of this section (that was used in a previous expression). |
| 317 | MCOS->EmitLabel(LineEndSym); |
| 318 | } |
| 319 | |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 320 | /// Utility function to write the encoding to an object writer. |
| 321 | void MCDwarfLineAddr::Write(MCObjectWriter *OW, int64_t LineDelta, |
| 322 | uint64_t AddrDelta) { |
| 323 | SmallString<256> Tmp; |
| 324 | raw_svector_ostream OS(Tmp); |
| 325 | MCDwarfLineAddr::Encode(LineDelta, AddrDelta, OS); |
| 326 | OW->WriteBytes(OS.str()); |
| 327 | } |
| 328 | |
| 329 | /// Utility function to emit the encoding to a streamer. |
Rafael Espindola | 195a0ce | 2010-11-19 02:26:16 +0000 | [diff] [blame] | 330 | void MCDwarfLineAddr::Emit(MCStreamer *MCOS, int64_t LineDelta, |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 331 | uint64_t AddrDelta) { |
| 332 | SmallString<256> Tmp; |
| 333 | raw_svector_ostream OS(Tmp); |
| 334 | MCDwarfLineAddr::Encode(LineDelta, AddrDelta, OS); |
| 335 | MCOS->EmitBytes(OS.str(), /*AddrSpace=*/0); |
| 336 | } |
| 337 | |
| 338 | /// Utility function to encode a Dwarf pair of LineDelta and AddrDeltas. |
| 339 | void MCDwarfLineAddr::Encode(int64_t LineDelta, uint64_t AddrDelta, |
| 340 | raw_ostream &OS) { |
| 341 | uint64_t Temp, Opcode; |
| 342 | bool NeedCopy = false; |
| 343 | |
| 344 | // Scale the address delta by the minimum instruction length. |
| 345 | AddrDelta = ScaleAddrDelta(AddrDelta); |
| 346 | |
| 347 | // A LineDelta of INT64_MAX is a signal that this is actually a |
| 348 | // DW_LNE_end_sequence. We cannot use special opcodes here, since we want the |
| 349 | // end_sequence to emit the matrix entry. |
| 350 | if (LineDelta == INT64_MAX) { |
| 351 | if (AddrDelta == MAX_SPECIAL_ADDR_DELTA) |
| 352 | OS << char(dwarf::DW_LNS_const_add_pc); |
| 353 | else { |
| 354 | OS << char(dwarf::DW_LNS_advance_pc); |
Benjamin Kramer | dcf0e0c | 2011-06-18 14:42:47 +0000 | [diff] [blame] | 355 | MCObjectWriter::EncodeULEB128(AddrDelta, OS); |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 356 | } |
| 357 | OS << char(dwarf::DW_LNS_extended_op); |
| 358 | OS << char(1); |
| 359 | OS << char(dwarf::DW_LNE_end_sequence); |
| 360 | return; |
| 361 | } |
| 362 | |
| 363 | // Bias the line delta by the base. |
| 364 | Temp = LineDelta - DWARF2_LINE_BASE; |
| 365 | |
| 366 | // If the line increment is out of range of a special opcode, we must encode |
| 367 | // it with DW_LNS_advance_line. |
| 368 | if (Temp >= DWARF2_LINE_RANGE) { |
| 369 | OS << char(dwarf::DW_LNS_advance_line); |
| 370 | SmallString<32> Tmp; |
| 371 | raw_svector_ostream OSE(Tmp); |
| 372 | MCObjectWriter::EncodeSLEB128(LineDelta, OSE); |
| 373 | OS << OSE.str(); |
| 374 | |
| 375 | LineDelta = 0; |
| 376 | Temp = 0 - DWARF2_LINE_BASE; |
| 377 | NeedCopy = true; |
| 378 | } |
| 379 | |
| 380 | // Use DW_LNS_copy instead of a "line +0, addr +0" special opcode. |
| 381 | if (LineDelta == 0 && AddrDelta == 0) { |
| 382 | OS << char(dwarf::DW_LNS_copy); |
| 383 | return; |
| 384 | } |
| 385 | |
| 386 | // Bias the opcode by the special opcode base. |
| 387 | Temp += DWARF2_LINE_OPCODE_BASE; |
| 388 | |
| 389 | // Avoid overflow when addr_delta is large. |
| 390 | if (AddrDelta < 256 + MAX_SPECIAL_ADDR_DELTA) { |
| 391 | // Try using a special opcode. |
| 392 | Opcode = Temp + AddrDelta * DWARF2_LINE_RANGE; |
| 393 | if (Opcode <= 255) { |
| 394 | OS << char(Opcode); |
| 395 | return; |
| 396 | } |
| 397 | |
| 398 | // Try using DW_LNS_const_add_pc followed by special op. |
| 399 | Opcode = Temp + (AddrDelta - MAX_SPECIAL_ADDR_DELTA) * DWARF2_LINE_RANGE; |
| 400 | if (Opcode <= 255) { |
| 401 | OS << char(dwarf::DW_LNS_const_add_pc); |
| 402 | OS << char(Opcode); |
| 403 | return; |
| 404 | } |
| 405 | } |
| 406 | |
| 407 | // Otherwise use DW_LNS_advance_pc. |
| 408 | OS << char(dwarf::DW_LNS_advance_pc); |
| 409 | SmallString<32> Tmp; |
| 410 | raw_svector_ostream OSE(Tmp); |
| 411 | MCObjectWriter::EncodeULEB128(AddrDelta, OSE); |
| 412 | OS << OSE.str(); |
| 413 | |
| 414 | if (NeedCopy) |
| 415 | OS << char(dwarf::DW_LNS_copy); |
| 416 | else |
| 417 | OS << char(Temp); |
| 418 | } |
| 419 | |
Kevin Enderby | 7cbf73a | 2010-07-28 20:55:35 +0000 | [diff] [blame] | 420 | void MCDwarfFile::print(raw_ostream &OS) const { |
| 421 | OS << '"' << getName() << '"'; |
| 422 | } |
| 423 | |
| 424 | void MCDwarfFile::dump() const { |
| 425 | print(dbgs()); |
| 426 | } |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 427 | |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 428 | static int getDataAlignmentFactor(MCStreamer &streamer) { |
| 429 | MCContext &context = streamer.getContext(); |
| 430 | const TargetAsmInfo &asmInfo = context.getTargetAsmInfo(); |
| 431 | int size = asmInfo.getPointerSize(); |
Anton Korobeynikov | 16c29b5 | 2011-01-10 12:39:04 +0000 | [diff] [blame] | 432 | if (asmInfo.getStackGrowthDirection() == TargetFrameLowering::StackGrowsUp) |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 433 | return size; |
| 434 | else |
| 435 | return -size; |
| 436 | } |
| 437 | |
Rafael Espindola | abf9af6 | 2011-04-22 00:08:43 +0000 | [diff] [blame] | 438 | static unsigned getSizeForEncoding(MCStreamer &streamer, |
| 439 | unsigned symbolEncoding) { |
Rafael Espindola | bdc3167 | 2010-12-27 15:56:22 +0000 | [diff] [blame] | 440 | MCContext &context = streamer.getContext(); |
| 441 | const TargetAsmInfo &asmInfo = context.getTargetAsmInfo(); |
| 442 | unsigned format = symbolEncoding & 0x0f; |
Rafael Espindola | bdc3167 | 2010-12-27 15:56:22 +0000 | [diff] [blame] | 443 | switch (format) { |
| 444 | default: |
| 445 | assert(0 && "Unknown Encoding"); |
Rafael Espindola | bdc3167 | 2010-12-27 15:56:22 +0000 | [diff] [blame] | 446 | case dwarf::DW_EH_PE_absptr: |
| 447 | case dwarf::DW_EH_PE_signed: |
Rafael Espindola | abf9af6 | 2011-04-22 00:08:43 +0000 | [diff] [blame] | 448 | return asmInfo.getPointerSize(); |
Rafael Espindola | bdc3167 | 2010-12-27 15:56:22 +0000 | [diff] [blame] | 449 | case dwarf::DW_EH_PE_udata2: |
| 450 | case dwarf::DW_EH_PE_sdata2: |
Rafael Espindola | abf9af6 | 2011-04-22 00:08:43 +0000 | [diff] [blame] | 451 | return 2; |
Rafael Espindola | bdc3167 | 2010-12-27 15:56:22 +0000 | [diff] [blame] | 452 | case dwarf::DW_EH_PE_udata4: |
| 453 | case dwarf::DW_EH_PE_sdata4: |
Rafael Espindola | abf9af6 | 2011-04-22 00:08:43 +0000 | [diff] [blame] | 454 | return 4; |
Rafael Espindola | bdc3167 | 2010-12-27 15:56:22 +0000 | [diff] [blame] | 455 | case dwarf::DW_EH_PE_udata8: |
| 456 | case dwarf::DW_EH_PE_sdata8: |
Rafael Espindola | abf9af6 | 2011-04-22 00:08:43 +0000 | [diff] [blame] | 457 | return 8; |
Rafael Espindola | bdc3167 | 2010-12-27 15:56:22 +0000 | [diff] [blame] | 458 | } |
Rafael Espindola | abf9af6 | 2011-04-22 00:08:43 +0000 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | static void EmitSymbol(MCStreamer &streamer, const MCSymbol &symbol, |
Bill Wendling | 2541c41 | 2011-06-30 22:02:20 +0000 | [diff] [blame] | 462 | unsigned symbolEncoding, const char *comment = 0) { |
Rafael Espindola | a0057ca | 2011-04-28 21:04:39 +0000 | [diff] [blame] | 463 | MCContext &context = streamer.getContext(); |
| 464 | const MCAsmInfo &asmInfo = context.getAsmInfo(); |
| 465 | const MCExpr *v = asmInfo.getExprForFDESymbol(&symbol, |
Rafael Espindola | debd7e4 | 2011-05-01 03:50:49 +0000 | [diff] [blame] | 466 | symbolEncoding, |
Rafael Espindola | a0057ca | 2011-04-28 21:04:39 +0000 | [diff] [blame] | 467 | streamer); |
Rafael Espindola | abf9af6 | 2011-04-22 00:08:43 +0000 | [diff] [blame] | 468 | unsigned size = getSizeForEncoding(streamer, symbolEncoding); |
Bill Wendling | 2541c41 | 2011-06-30 22:02:20 +0000 | [diff] [blame] | 469 | if (streamer.isVerboseAsm() && comment) streamer.AddComment(comment); |
Rafael Espindola | debd7e4 | 2011-05-01 03:50:49 +0000 | [diff] [blame] | 470 | streamer.EmitAbsValue(v, size); |
Rafael Espindola | bdc3167 | 2010-12-27 15:56:22 +0000 | [diff] [blame] | 471 | } |
| 472 | |
Rafael Espindola | bfa27cc | 2011-04-28 16:09:09 +0000 | [diff] [blame] | 473 | static void EmitPersonality(MCStreamer &streamer, const MCSymbol &symbol, |
| 474 | unsigned symbolEncoding) { |
| 475 | MCContext &context = streamer.getContext(); |
| 476 | const MCAsmInfo &asmInfo = context.getAsmInfo(); |
Rafael Espindola | debd7e4 | 2011-05-01 03:50:49 +0000 | [diff] [blame] | 477 | const MCExpr *v = asmInfo.getExprForPersonalitySymbol(&symbol, |
| 478 | symbolEncoding, |
| 479 | streamer); |
Rafael Espindola | bfa27cc | 2011-04-28 16:09:09 +0000 | [diff] [blame] | 480 | unsigned size = getSizeForEncoding(streamer, symbolEncoding); |
Rafael Espindola | debd7e4 | 2011-05-01 03:50:49 +0000 | [diff] [blame] | 481 | streamer.EmitValue(v, size); |
Rafael Espindola | bfa27cc | 2011-04-28 16:09:09 +0000 | [diff] [blame] | 482 | } |
| 483 | |
Rafael Espindola | b40a71f | 2010-12-29 01:42:56 +0000 | [diff] [blame] | 484 | static const MachineLocation TranslateMachineLocation( |
| 485 | const TargetAsmInfo &AsmInfo, |
| 486 | const MachineLocation &Loc) { |
| 487 | unsigned Reg = Loc.getReg() == MachineLocation::VirtualFP ? |
| 488 | MachineLocation::VirtualFP : |
| 489 | unsigned(AsmInfo.getDwarfRegNum(Loc.getReg(), true)); |
| 490 | const MachineLocation &NewLoc = Loc.isReg() ? |
| 491 | MachineLocation(Reg) : MachineLocation(Reg, Loc.getOffset()); |
| 492 | return NewLoc; |
| 493 | } |
| 494 | |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 495 | namespace { |
| 496 | class FrameEmitterImpl { |
| 497 | int CFAOffset; |
Rafael Espindola | 514cecc | 2011-04-28 03:26:11 +0000 | [diff] [blame] | 498 | int CIENum; |
Rafael Espindola | 5426a9e | 2011-05-01 04:49:54 +0000 | [diff] [blame] | 499 | bool UsingCFI; |
Rafael Espindola | 40a7dbb | 2011-05-10 03:54:12 +0000 | [diff] [blame] | 500 | bool IsEH; |
Rafael Espindola | e3a0e98 | 2011-05-10 20:59:42 +0000 | [diff] [blame] | 501 | const MCSymbol *SectionStart; |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 502 | |
| 503 | public: |
Rafael Espindola | e3a0e98 | 2011-05-10 20:59:42 +0000 | [diff] [blame] | 504 | FrameEmitterImpl(bool usingCFI, bool isEH, const MCSymbol *sectionStart) : |
| 505 | CFAOffset(0), CIENum(0), UsingCFI(usingCFI), IsEH(isEH), |
| 506 | SectionStart(sectionStart) { |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 507 | } |
| 508 | |
Bill Wendling | e3cd13f | 2011-06-23 01:06:23 +0000 | [diff] [blame] | 509 | /// EmitCompactUnwind - Emit the unwind information in a compact way. If |
| 510 | /// we're successful, return 'true'. Otherwise, return 'false' and it will |
| 511 | /// emit the normal CIE and FDE. |
| 512 | bool EmitCompactUnwind(MCStreamer &streamer, |
| 513 | const MCDwarfFrameInfo &frame); |
| 514 | |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 515 | const MCSymbol &EmitCIE(MCStreamer &streamer, |
| 516 | const MCSymbol *personality, |
| 517 | unsigned personalityEncoding, |
| 518 | const MCSymbol *lsda, |
| 519 | unsigned lsdaEncoding); |
| 520 | MCSymbol *EmitFDE(MCStreamer &streamer, |
| 521 | const MCSymbol &cieStart, |
Rafael Espindola | 9f270da | 2011-05-10 03:01:39 +0000 | [diff] [blame] | 522 | const MCDwarfFrameInfo &frame); |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 523 | void EmitCFIInstructions(MCStreamer &streamer, |
| 524 | const std::vector<MCCFIInstruction> &Instrs, |
| 525 | MCSymbol *BaseLabel); |
| 526 | void EmitCFIInstruction(MCStreamer &Streamer, |
| 527 | const MCCFIInstruction &Instr); |
| 528 | }; |
Bill Wendling | 3c163cf | 2011-06-30 21:25:51 +0000 | [diff] [blame] | 529 | |
| 530 | } // end anonymous namespace |
| 531 | |
| 532 | static void EmitEncodingByte(MCStreamer &Streamer, unsigned Encoding, |
| 533 | StringRef Prefix) { |
| 534 | if (Streamer.isVerboseAsm()) { |
| 535 | const char *EncStr = 0; |
| 536 | switch (Encoding) { |
| 537 | default: EncStr = "<unknown encoding>"; |
| 538 | case dwarf::DW_EH_PE_absptr: EncStr = "absptr"; |
| 539 | case dwarf::DW_EH_PE_omit: EncStr = "omit"; |
| 540 | case dwarf::DW_EH_PE_pcrel: EncStr = "pcrel"; |
| 541 | case dwarf::DW_EH_PE_udata4: EncStr = "udata4"; |
| 542 | case dwarf::DW_EH_PE_udata8: EncStr = "udata8"; |
| 543 | case dwarf::DW_EH_PE_sdata4: EncStr = "sdata4"; |
| 544 | case dwarf::DW_EH_PE_sdata8: EncStr = "sdata8"; |
| 545 | case dwarf::DW_EH_PE_pcrel |dwarf::DW_EH_PE_udata4: EncStr = "pcrel udata4"; |
| 546 | case dwarf::DW_EH_PE_pcrel |dwarf::DW_EH_PE_sdata4: EncStr = "pcrel sdata4"; |
| 547 | case dwarf::DW_EH_PE_pcrel |dwarf::DW_EH_PE_udata8: EncStr = "pcrel udata8"; |
| 548 | case dwarf::DW_EH_PE_pcrel |dwarf::DW_EH_PE_sdata8: EncStr = "pcrel sdata8"; |
| 549 | case dwarf::DW_EH_PE_indirect |dwarf::DW_EH_PE_pcrel|dwarf::DW_EH_PE_udata4: |
| 550 | EncStr = "indirect pcrel udata4"; |
| 551 | case dwarf::DW_EH_PE_indirect |dwarf::DW_EH_PE_pcrel|dwarf::DW_EH_PE_sdata4: |
| 552 | EncStr = "indirect pcrel sdata4"; |
| 553 | case dwarf::DW_EH_PE_indirect |dwarf::DW_EH_PE_pcrel|dwarf::DW_EH_PE_udata8: |
| 554 | EncStr = "indirect pcrel udata8"; |
| 555 | case dwarf::DW_EH_PE_indirect |dwarf::DW_EH_PE_pcrel|dwarf::DW_EH_PE_sdata8: |
| 556 | EncStr = "indirect pcrel sdata8"; |
| 557 | } |
| 558 | |
| 559 | Streamer.AddComment(Twine(Prefix) + " = " + EncStr); |
| 560 | } |
| 561 | |
| 562 | Streamer.EmitIntValue(Encoding, 1); |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | void FrameEmitterImpl::EmitCFIInstruction(MCStreamer &Streamer, |
| 566 | const MCCFIInstruction &Instr) { |
| 567 | int dataAlignmentFactor = getDataAlignmentFactor(Streamer); |
Bill Wendling | efd24dd | 2011-06-30 21:45:12 +0000 | [diff] [blame] | 568 | bool VerboseAsm = Streamer.isVerboseAsm(); |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 569 | |
| 570 | switch (Instr.getOperation()) { |
| 571 | case MCCFIInstruction::Move: |
| 572 | case MCCFIInstruction::RelMove: { |
| 573 | const MachineLocation &Dst = Instr.getDestination(); |
| 574 | const MachineLocation &Src = Instr.getSource(); |
Rafael Espindola | 5d7dcd3 | 2011-04-12 18:53:30 +0000 | [diff] [blame] | 575 | const bool IsRelative = Instr.getOperation() == MCCFIInstruction::RelMove; |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 576 | |
| 577 | // If advancing cfa. |
| 578 | if (Dst.isReg() && Dst.getReg() == MachineLocation::VirtualFP) { |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 579 | if (Src.getReg() == MachineLocation::VirtualFP) { |
Bill Wendling | efd24dd | 2011-06-30 21:45:12 +0000 | [diff] [blame] | 580 | if (VerboseAsm) Streamer.AddComment("DW_CFA_def_cfa_offset"); |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 581 | Streamer.EmitIntValue(dwarf::DW_CFA_def_cfa_offset, 1); |
| 582 | } else { |
Bill Wendling | efd24dd | 2011-06-30 21:45:12 +0000 | [diff] [blame] | 583 | if (VerboseAsm) Streamer.AddComment("DW_CFA_def_cfa"); |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 584 | Streamer.EmitIntValue(dwarf::DW_CFA_def_cfa, 1); |
Bill Wendling | efd24dd | 2011-06-30 21:45:12 +0000 | [diff] [blame] | 585 | if (VerboseAsm) Streamer.AddComment(Twine("Reg ") + |
| 586 | Twine(Src.getReg())); |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 587 | Streamer.EmitULEB128IntValue(Src.getReg()); |
| 588 | } |
| 589 | |
Rafael Espindola | 5d7dcd3 | 2011-04-12 18:53:30 +0000 | [diff] [blame] | 590 | if (IsRelative) |
| 591 | CFAOffset += Src.getOffset(); |
| 592 | else |
| 593 | CFAOffset = -Src.getOffset(); |
| 594 | |
Bill Wendling | efd24dd | 2011-06-30 21:45:12 +0000 | [diff] [blame] | 595 | if (VerboseAsm) Streamer.AddComment(Twine("Offset " + Twine(CFAOffset))); |
Rafael Espindola | e8cfbd8 | 2011-04-21 23:39:26 +0000 | [diff] [blame] | 596 | Streamer.EmitULEB128IntValue(CFAOffset); |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 597 | return; |
| 598 | } |
| 599 | |
| 600 | if (Src.isReg() && Src.getReg() == MachineLocation::VirtualFP) { |
| 601 | assert(Dst.isReg() && "Machine move not supported yet."); |
Bill Wendling | efd24dd | 2011-06-30 21:45:12 +0000 | [diff] [blame] | 602 | if (VerboseAsm) Streamer.AddComment("DW_CFA_def_cfa_register"); |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 603 | Streamer.EmitIntValue(dwarf::DW_CFA_def_cfa_register, 1); |
Bill Wendling | efd24dd | 2011-06-30 21:45:12 +0000 | [diff] [blame] | 604 | if (VerboseAsm) Streamer.AddComment(Twine("Reg ") + Twine(Dst.getReg())); |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 605 | Streamer.EmitULEB128IntValue(Dst.getReg()); |
| 606 | return; |
| 607 | } |
| 608 | |
| 609 | unsigned Reg = Src.getReg(); |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 610 | int Offset = Dst.getOffset(); |
| 611 | if (IsRelative) |
| 612 | Offset -= CFAOffset; |
| 613 | Offset = Offset / dataAlignmentFactor; |
| 614 | |
| 615 | if (Offset < 0) { |
Bill Wendling | efd24dd | 2011-06-30 21:45:12 +0000 | [diff] [blame] | 616 | if (VerboseAsm) Streamer.AddComment("DW_CFA_offset_extended_sf"); |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 617 | Streamer.EmitIntValue(dwarf::DW_CFA_offset_extended_sf, 1); |
Bill Wendling | efd24dd | 2011-06-30 21:45:12 +0000 | [diff] [blame] | 618 | if (VerboseAsm) Streamer.AddComment(Twine("Reg ") + Twine(Reg)); |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 619 | Streamer.EmitULEB128IntValue(Reg); |
Bill Wendling | efd24dd | 2011-06-30 21:45:12 +0000 | [diff] [blame] | 620 | if (VerboseAsm) Streamer.AddComment(Twine("Offset ") + Twine(Offset)); |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 621 | Streamer.EmitSLEB128IntValue(Offset); |
| 622 | } else if (Reg < 64) { |
Bill Wendling | e08d433 | 2011-06-30 23:47:40 +0000 | [diff] [blame] | 623 | if (VerboseAsm) Streamer.AddComment(Twine("DW_CFA_offset + Reg(") + |
| 624 | Twine(Reg) + ")"); |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 625 | Streamer.EmitIntValue(dwarf::DW_CFA_offset + Reg, 1); |
Bill Wendling | efd24dd | 2011-06-30 21:45:12 +0000 | [diff] [blame] | 626 | if (VerboseAsm) Streamer.AddComment(Twine("Offset ") + Twine(Offset)); |
Rafael Espindola | eccbad7 | 2011-04-21 23:26:40 +0000 | [diff] [blame] | 627 | Streamer.EmitULEB128IntValue(Offset); |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 628 | } else { |
Bill Wendling | efd24dd | 2011-06-30 21:45:12 +0000 | [diff] [blame] | 629 | if (VerboseAsm) Streamer.AddComment("DW_CFA_offset_extended"); |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 630 | Streamer.EmitIntValue(dwarf::DW_CFA_offset_extended, 1); |
Bill Wendling | efd24dd | 2011-06-30 21:45:12 +0000 | [diff] [blame] | 631 | if (VerboseAsm) Streamer.AddComment(Twine("Reg ") + Twine(Reg)); |
Rafael Espindola | eccbad7 | 2011-04-21 23:26:40 +0000 | [diff] [blame] | 632 | Streamer.EmitULEB128IntValue(Reg); |
Bill Wendling | efd24dd | 2011-06-30 21:45:12 +0000 | [diff] [blame] | 633 | if (VerboseAsm) Streamer.AddComment(Twine("Offset ") + Twine(Offset)); |
Rafael Espindola | eccbad7 | 2011-04-21 23:26:40 +0000 | [diff] [blame] | 634 | Streamer.EmitULEB128IntValue(Offset); |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 635 | } |
| 636 | return; |
| 637 | } |
| 638 | case MCCFIInstruction::Remember: |
Bill Wendling | efd24dd | 2011-06-30 21:45:12 +0000 | [diff] [blame] | 639 | if (VerboseAsm) Streamer.AddComment("DW_CFA_remember_state"); |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 640 | Streamer.EmitIntValue(dwarf::DW_CFA_remember_state, 1); |
| 641 | return; |
| 642 | case MCCFIInstruction::Restore: |
Bill Wendling | efd24dd | 2011-06-30 21:45:12 +0000 | [diff] [blame] | 643 | if (VerboseAsm) Streamer.AddComment("DW_CFA_restore_state"); |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 644 | Streamer.EmitIntValue(dwarf::DW_CFA_restore_state, 1); |
| 645 | return; |
| 646 | case MCCFIInstruction::SameValue: { |
| 647 | unsigned Reg = Instr.getDestination().getReg(); |
Bill Wendling | efd24dd | 2011-06-30 21:45:12 +0000 | [diff] [blame] | 648 | if (VerboseAsm) Streamer.AddComment("DW_CFA_same_value"); |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 649 | Streamer.EmitIntValue(dwarf::DW_CFA_same_value, 1); |
Bill Wendling | efd24dd | 2011-06-30 21:45:12 +0000 | [diff] [blame] | 650 | if (VerboseAsm) Streamer.AddComment(Twine("Reg ") + Twine(Reg)); |
Rafael Espindola | e8cfbd8 | 2011-04-21 23:39:26 +0000 | [diff] [blame] | 651 | Streamer.EmitULEB128IntValue(Reg); |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 652 | return; |
| 653 | } |
| 654 | } |
| 655 | llvm_unreachable("Unhandled case in switch"); |
| 656 | } |
| 657 | |
| 658 | /// EmitFrameMoves - Emit frame instructions to describe the layout of the |
| 659 | /// frame. |
| 660 | void FrameEmitterImpl::EmitCFIInstructions(MCStreamer &streamer, |
| 661 | const std::vector<MCCFIInstruction> &Instrs, |
| 662 | MCSymbol *BaseLabel) { |
| 663 | for (unsigned i = 0, N = Instrs.size(); i < N; ++i) { |
| 664 | const MCCFIInstruction &Instr = Instrs[i]; |
| 665 | MCSymbol *Label = Instr.getLabel(); |
| 666 | // Throw out move if the label is invalid. |
| 667 | if (Label && !Label->isDefined()) continue; // Not emitted, in dead code. |
| 668 | |
| 669 | // Advance row if new location. |
| 670 | if (BaseLabel && Label) { |
| 671 | MCSymbol *ThisSym = Label; |
| 672 | if (ThisSym != BaseLabel) { |
Bill Wendling | d221cd6 | 2011-06-30 22:35:49 +0000 | [diff] [blame] | 673 | if (streamer.isVerboseAsm()) streamer.AddComment("DW_CFA_advance_loc4"); |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 674 | streamer.EmitDwarfAdvanceFrameAddr(BaseLabel, ThisSym); |
| 675 | BaseLabel = ThisSym; |
| 676 | } |
| 677 | } |
| 678 | |
| 679 | EmitCFIInstruction(streamer, Instr); |
| 680 | } |
| 681 | } |
| 682 | |
Bill Wendling | e3cd13f | 2011-06-23 01:06:23 +0000 | [diff] [blame] | 683 | /// EmitCompactUnwind - Emit the unwind information in a compact way. If we're |
| 684 | /// successful, return 'true'. Otherwise, return 'false' and it will emit the |
| 685 | /// normal CIE and FDE. |
| 686 | bool FrameEmitterImpl::EmitCompactUnwind(MCStreamer &Streamer, |
| 687 | const MCDwarfFrameInfo &Frame) { |
| 688 | #if 1 |
| 689 | return false; |
| 690 | #else |
| 691 | MCContext &Context = Streamer.getContext(); |
| 692 | const TargetAsmInfo &TAI = Context.getTargetAsmInfo(); |
Bill Wendling | 3c163cf | 2011-06-30 21:25:51 +0000 | [diff] [blame] | 693 | bool VerboseAsm = Streamer.isVerboseAsm(); |
Bill Wendling | e3cd13f | 2011-06-23 01:06:23 +0000 | [diff] [blame] | 694 | |
Bill Wendling | e3cd13f | 2011-06-23 01:06:23 +0000 | [diff] [blame] | 695 | // range-start range-length compact-unwind-enc personality-func lsda |
| 696 | // _foo LfooEnd-_foo 0x00000023 0 0 |
| 697 | // _bar LbarEnd-_bar 0x00000025 __gxx_personality except_tab1 |
| 698 | // |
| 699 | // .section __LD,__compact_unwind,regular,debug |
| 700 | // |
| 701 | // # compact unwind for _foo |
| 702 | // .quad _foo |
| 703 | // .set L1,LfooEnd-_foo |
| 704 | // .long L1 |
| 705 | // .long 0x01010001 |
| 706 | // .quad 0 |
| 707 | // .quad 0 |
| 708 | // |
| 709 | // # compact unwind for _bar |
| 710 | // .quad _bar |
| 711 | // .set L2,LbarEnd-_bar |
| 712 | // .long L2 |
| 713 | // .long 0x01020011 |
| 714 | // .quad __gxx_personality |
| 715 | // .quad except_tab1 |
| 716 | |
Bill Wendling | 3c163cf | 2011-06-30 21:25:51 +0000 | [diff] [blame] | 717 | Streamer.SwitchSection(TAI.getCompactUnwindSection()); |
| 718 | |
Bill Wendling | e3cd13f | 2011-06-23 01:06:23 +0000 | [diff] [blame] | 719 | // Range Start |
Bill Wendling | 9056e90 | 2011-06-29 23:49:12 +0000 | [diff] [blame] | 720 | unsigned FDEEncoding = TAI.getFDEEncoding(UsingCFI); |
| 721 | unsigned Size = getSizeForEncoding(Streamer, FDEEncoding); |
Bill Wendling | 3c163cf | 2011-06-30 21:25:51 +0000 | [diff] [blame] | 722 | if (VerboseAsm) Streamer.AddComment("Range Start"); |
Bill Wendling | 9056e90 | 2011-06-29 23:49:12 +0000 | [diff] [blame] | 723 | Streamer.EmitSymbolValue(Frame.Function, Size); |
Bill Wendling | e3cd13f | 2011-06-23 01:06:23 +0000 | [diff] [blame] | 724 | |
| 725 | // Range Length |
| 726 | const MCExpr *Range = MakeStartMinusEndExpr(Streamer, *Frame.Begin, |
| 727 | *Frame.End, 0); |
Bill Wendling | 3c163cf | 2011-06-30 21:25:51 +0000 | [diff] [blame] | 728 | if (VerboseAsm) Streamer.AddComment("Range Length"); |
Bill Wendling | 9287a6e | 2011-06-30 00:30:52 +0000 | [diff] [blame] | 729 | Streamer.EmitAbsValue(Range, 4); |
| 730 | |
| 731 | // FIXME: |
| 732 | // Compact Encoding |
Bill Wendling | 3c163cf | 2011-06-30 21:25:51 +0000 | [diff] [blame] | 733 | const std::vector<MachineMove> &Moves = TAI.getInitialFrameState(); |
Bill Wendling | 9287a6e | 2011-06-30 00:30:52 +0000 | [diff] [blame] | 734 | uint32_t Encoding = 0; |
| 735 | Size = getSizeForEncoding(Streamer, dwarf::DW_EH_PE_udata4); |
Bill Wendling | 3c163cf | 2011-06-30 21:25:51 +0000 | [diff] [blame] | 736 | if (VerboseAsm) Streamer.AddComment("Compact Unwind Encoding"); |
Bill Wendling | 9287a6e | 2011-06-30 00:30:52 +0000 | [diff] [blame] | 737 | Streamer.EmitIntValue(Encoding, Size); |
| 738 | |
Bill Wendling | 9056e90 | 2011-06-29 23:49:12 +0000 | [diff] [blame] | 739 | // Personality Function |
Bill Wendling | 4498d39 | 2011-06-29 23:53:16 +0000 | [diff] [blame] | 740 | Size = getSizeForEncoding(Streamer, Frame.PersonalityEncoding); |
Bill Wendling | 3c163cf | 2011-06-30 21:25:51 +0000 | [diff] [blame] | 741 | if (VerboseAsm) Streamer.AddComment("Personality Function"); |
Bill Wendling | 4498d39 | 2011-06-29 23:53:16 +0000 | [diff] [blame] | 742 | if (Frame.Personality) |
Bill Wendling | 9056e90 | 2011-06-29 23:49:12 +0000 | [diff] [blame] | 743 | Streamer.EmitSymbolValue(Frame.Personality, Size); |
Bill Wendling | 4498d39 | 2011-06-29 23:53:16 +0000 | [diff] [blame] | 744 | else |
| 745 | Streamer.EmitIntValue(0, Size); // No personality fn |
Bill Wendling | 9056e90 | 2011-06-29 23:49:12 +0000 | [diff] [blame] | 746 | |
| 747 | // LSDA |
Bill Wendling | 4498d39 | 2011-06-29 23:53:16 +0000 | [diff] [blame] | 748 | Size = getSizeForEncoding(Streamer, Frame.LsdaEncoding); |
Bill Wendling | 3c163cf | 2011-06-30 21:25:51 +0000 | [diff] [blame] | 749 | if (VerboseAsm) Streamer.AddComment("LSDA"); |
Bill Wendling | 4498d39 | 2011-06-29 23:53:16 +0000 | [diff] [blame] | 750 | if (Frame.Lsda) |
Bill Wendling | 9056e90 | 2011-06-29 23:49:12 +0000 | [diff] [blame] | 751 | Streamer.EmitSymbolValue(Frame.Lsda, Size); |
Bill Wendling | 4498d39 | 2011-06-29 23:53:16 +0000 | [diff] [blame] | 752 | else |
| 753 | Streamer.EmitIntValue(0, Size); // No LSDA |
Bill Wendling | 9056e90 | 2011-06-29 23:49:12 +0000 | [diff] [blame] | 754 | |
Bill Wendling | e3cd13f | 2011-06-23 01:06:23 +0000 | [diff] [blame] | 755 | return true; |
| 756 | #endif |
| 757 | } |
| 758 | |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 759 | const MCSymbol &FrameEmitterImpl::EmitCIE(MCStreamer &streamer, |
| 760 | const MCSymbol *personality, |
| 761 | unsigned personalityEncoding, |
| 762 | const MCSymbol *lsda, |
| 763 | unsigned lsdaEncoding) { |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 764 | MCContext &context = streamer.getContext(); |
| 765 | const TargetAsmInfo &asmInfo = context.getTargetAsmInfo(); |
Bill Wendling | 3c163cf | 2011-06-30 21:25:51 +0000 | [diff] [blame] | 766 | bool verboseAsm = streamer.isVerboseAsm(); |
Rafael Espindola | 514cecc | 2011-04-28 03:26:11 +0000 | [diff] [blame] | 767 | |
| 768 | MCSymbol *sectionStart; |
Rafael Espindola | 12f197b | 2011-05-10 19:51:53 +0000 | [diff] [blame] | 769 | if (asmInfo.isFunctionEHFrameSymbolPrivate() || !IsEH) |
Rafael Espindola | 514cecc | 2011-04-28 03:26:11 +0000 | [diff] [blame] | 770 | sectionStart = context.CreateTempSymbol(); |
| 771 | else |
| 772 | sectionStart = context.GetOrCreateSymbol(Twine("EH_frame") + Twine(CIENum)); |
| 773 | |
Bill Wendling | 3c163cf | 2011-06-30 21:25:51 +0000 | [diff] [blame] | 774 | streamer.EmitLabel(sectionStart); |
Rafael Espindola | 514cecc | 2011-04-28 03:26:11 +0000 | [diff] [blame] | 775 | CIENum++; |
| 776 | |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 777 | MCSymbol *sectionEnd = streamer.getContext().CreateTempSymbol(); |
| 778 | |
| 779 | // Length |
| 780 | const MCExpr *Length = MakeStartMinusEndExpr(streamer, *sectionStart, |
| 781 | *sectionEnd, 4); |
Bill Wendling | 3c163cf | 2011-06-30 21:25:51 +0000 | [diff] [blame] | 782 | if (verboseAsm) streamer.AddComment("CIE Length"); |
Rafael Espindola | 9266cc4 | 2011-04-27 01:43:49 +0000 | [diff] [blame] | 783 | streamer.EmitAbsValue(Length, 4); |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 784 | |
| 785 | // CIE ID |
Rafael Espindola | 40a7dbb | 2011-05-10 03:54:12 +0000 | [diff] [blame] | 786 | unsigned CIE_ID = IsEH ? 0 : -1; |
Bill Wendling | 3c163cf | 2011-06-30 21:25:51 +0000 | [diff] [blame] | 787 | if (verboseAsm) streamer.AddComment("CIE ID Tag"); |
Rafael Espindola | 40a7dbb | 2011-05-10 03:54:12 +0000 | [diff] [blame] | 788 | streamer.EmitIntValue(CIE_ID, 4); |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 789 | |
| 790 | // Version |
Bill Wendling | 3c163cf | 2011-06-30 21:25:51 +0000 | [diff] [blame] | 791 | if (verboseAsm) streamer.AddComment("DW_CIE_VERSION"); |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 792 | streamer.EmitIntValue(dwarf::DW_CIE_VERSION, 1); |
| 793 | |
| 794 | // Augmentation String |
| 795 | SmallString<8> Augmentation; |
Rafael Espindola | 40a7dbb | 2011-05-10 03:54:12 +0000 | [diff] [blame] | 796 | if (IsEH) { |
Bill Wendling | 3c163cf | 2011-06-30 21:25:51 +0000 | [diff] [blame] | 797 | if (verboseAsm) streamer.AddComment("CIE Augmentation"); |
Rafael Espindola | 40a7dbb | 2011-05-10 03:54:12 +0000 | [diff] [blame] | 798 | Augmentation += "z"; |
| 799 | if (personality) |
| 800 | Augmentation += "P"; |
| 801 | if (lsda) |
| 802 | Augmentation += "L"; |
| 803 | Augmentation += "R"; |
| 804 | streamer.EmitBytes(Augmentation.str(), 0); |
| 805 | } |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 806 | streamer.EmitIntValue(0, 1); |
| 807 | |
| 808 | // Code Alignment Factor |
Bill Wendling | 3c163cf | 2011-06-30 21:25:51 +0000 | [diff] [blame] | 809 | if (verboseAsm) streamer.AddComment("CIE Code Alignment Factor"); |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 810 | streamer.EmitULEB128IntValue(1); |
| 811 | |
| 812 | // Data Alignment Factor |
Bill Wendling | 3c163cf | 2011-06-30 21:25:51 +0000 | [diff] [blame] | 813 | if (verboseAsm) streamer.AddComment("CIE Data Alignment Factor"); |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 814 | streamer.EmitSLEB128IntValue(getDataAlignmentFactor(streamer)); |
| 815 | |
| 816 | // Return Address Register |
Bill Wendling | 3c163cf | 2011-06-30 21:25:51 +0000 | [diff] [blame] | 817 | if (verboseAsm) streamer.AddComment("CIE Return Address Column"); |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 818 | streamer.EmitULEB128IntValue(asmInfo.getDwarfRARegNum(true)); |
| 819 | |
| 820 | // Augmentation Data Length (optional) |
Rafael Espindola | 1f6c875 | 2011-04-29 21:50:57 +0000 | [diff] [blame] | 821 | |
| 822 | unsigned augmentationLength = 0; |
Rafael Espindola | 40a7dbb | 2011-05-10 03:54:12 +0000 | [diff] [blame] | 823 | if (IsEH) { |
| 824 | if (personality) { |
| 825 | // Personality Encoding |
| 826 | augmentationLength += 1; |
| 827 | // Personality |
| 828 | augmentationLength += getSizeForEncoding(streamer, personalityEncoding); |
| 829 | } |
| 830 | if (lsda) |
| 831 | augmentationLength += 1; |
| 832 | // Encoding of the FDE pointers |
Rafael Espindola | 1f6c875 | 2011-04-29 21:50:57 +0000 | [diff] [blame] | 833 | augmentationLength += 1; |
Rafael Espindola | 1f6c875 | 2011-04-29 21:50:57 +0000 | [diff] [blame] | 834 | |
Bill Wendling | 3c163cf | 2011-06-30 21:25:51 +0000 | [diff] [blame] | 835 | if (verboseAsm) streamer.AddComment("Augmentation Size"); |
Rafael Espindola | 40a7dbb | 2011-05-10 03:54:12 +0000 | [diff] [blame] | 836 | streamer.EmitULEB128IntValue(augmentationLength); |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 837 | |
Rafael Espindola | 40a7dbb | 2011-05-10 03:54:12 +0000 | [diff] [blame] | 838 | // Augmentation Data (optional) |
| 839 | if (personality) { |
| 840 | // Personality Encoding |
Bill Wendling | 3c163cf | 2011-06-30 21:25:51 +0000 | [diff] [blame] | 841 | EmitEncodingByte(streamer, personalityEncoding, |
| 842 | "Personality Encoding"); |
Rafael Espindola | 40a7dbb | 2011-05-10 03:54:12 +0000 | [diff] [blame] | 843 | // Personality |
Bill Wendling | 3c163cf | 2011-06-30 21:25:51 +0000 | [diff] [blame] | 844 | if (verboseAsm) streamer.AddComment("Personality"); |
Rafael Espindola | 40a7dbb | 2011-05-10 03:54:12 +0000 | [diff] [blame] | 845 | EmitPersonality(streamer, *personality, personalityEncoding); |
| 846 | } |
Bill Wendling | 3c163cf | 2011-06-30 21:25:51 +0000 | [diff] [blame] | 847 | |
Rafael Espindola | 40a7dbb | 2011-05-10 03:54:12 +0000 | [diff] [blame] | 848 | if (lsda) |
Bill Wendling | 3c163cf | 2011-06-30 21:25:51 +0000 | [diff] [blame] | 849 | EmitEncodingByte(streamer, lsdaEncoding, "LSDA Encoding"); |
| 850 | |
Rafael Espindola | 40a7dbb | 2011-05-10 03:54:12 +0000 | [diff] [blame] | 851 | // Encoding of the FDE pointers |
Bill Wendling | 3c163cf | 2011-06-30 21:25:51 +0000 | [diff] [blame] | 852 | EmitEncodingByte(streamer, asmInfo.getFDEEncoding(UsingCFI), |
| 853 | "FDE Encoding"); |
Rafael Espindola | bdc3167 | 2010-12-27 15:56:22 +0000 | [diff] [blame] | 854 | } |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 855 | |
| 856 | // Initial Instructions |
| 857 | |
Bill Wendling | 5b46e8e | 2011-06-23 07:55:41 +0000 | [diff] [blame] | 858 | const std::vector<MachineMove> &Moves = asmInfo.getInitialFrameState(); |
Rafael Espindola | fe024d0 | 2010-12-28 18:36:23 +0000 | [diff] [blame] | 859 | std::vector<MCCFIInstruction> Instructions; |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 860 | |
Rafael Espindola | fe024d0 | 2010-12-28 18:36:23 +0000 | [diff] [blame] | 861 | for (int i = 0, n = Moves.size(); i != n; ++i) { |
Rafael Espindola | b40a71f | 2010-12-29 01:42:56 +0000 | [diff] [blame] | 862 | MCSymbol *Label = Moves[i].getLabel(); |
| 863 | const MachineLocation &Dst = |
| 864 | TranslateMachineLocation(asmInfo, Moves[i].getDestination()); |
| 865 | const MachineLocation &Src = |
| 866 | TranslateMachineLocation(asmInfo, Moves[i].getSource()); |
| 867 | MCCFIInstruction Inst(Label, Dst, Src); |
Rafael Espindola | fe024d0 | 2010-12-28 18:36:23 +0000 | [diff] [blame] | 868 | Instructions.push_back(Inst); |
| 869 | } |
| 870 | |
Rafael Espindola | b40a71f | 2010-12-29 01:42:56 +0000 | [diff] [blame] | 871 | EmitCFIInstructions(streamer, Instructions, NULL); |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 872 | |
| 873 | // Padding |
Rafael Espindola | 40a7dbb | 2011-05-10 03:54:12 +0000 | [diff] [blame] | 874 | streamer.EmitValueToAlignment(IsEH ? 4 : asmInfo.getPointerSize()); |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 875 | |
| 876 | streamer.EmitLabel(sectionEnd); |
| 877 | return *sectionStart; |
| 878 | } |
| 879 | |
Rafael Espindola | 25f492e | 2011-04-12 16:12:03 +0000 | [diff] [blame] | 880 | MCSymbol *FrameEmitterImpl::EmitFDE(MCStreamer &streamer, |
| 881 | const MCSymbol &cieStart, |
Rafael Espindola | 9f270da | 2011-05-10 03:01:39 +0000 | [diff] [blame] | 882 | const MCDwarfFrameInfo &frame) { |
Rafael Espindola | bdc3167 | 2010-12-27 15:56:22 +0000 | [diff] [blame] | 883 | MCContext &context = streamer.getContext(); |
| 884 | MCSymbol *fdeStart = context.CreateTempSymbol(); |
| 885 | MCSymbol *fdeEnd = context.CreateTempSymbol(); |
Rafael Espindola | e3a0e98 | 2011-05-10 20:59:42 +0000 | [diff] [blame] | 886 | const TargetAsmInfo &TAsmInfo = context.getTargetAsmInfo(); |
Bill Wendling | 2541c41 | 2011-06-30 22:02:20 +0000 | [diff] [blame] | 887 | bool verboseAsm = streamer.isVerboseAsm(); |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 888 | |
Rafael Espindola | e3a0e98 | 2011-05-10 20:59:42 +0000 | [diff] [blame] | 889 | if (!TAsmInfo.isFunctionEHFrameSymbolPrivate() && IsEH) { |
Bill Wendling | 2541c41 | 2011-06-30 22:02:20 +0000 | [diff] [blame] | 890 | MCSymbol *EHSym = |
| 891 | context.GetOrCreateSymbol(frame.Function->getName() + Twine(".eh")); |
Rafael Espindola | 8bca410 | 2011-04-28 12:50:37 +0000 | [diff] [blame] | 892 | streamer.EmitEHSymAttributes(frame.Function, EHSym); |
Rafael Espindola | a8cfb87 | 2011-04-28 02:46:42 +0000 | [diff] [blame] | 893 | streamer.EmitLabel(EHSym); |
| 894 | } |
| 895 | |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 896 | // Length |
| 897 | const MCExpr *Length = MakeStartMinusEndExpr(streamer, *fdeStart, *fdeEnd, 0); |
Bill Wendling | 2541c41 | 2011-06-30 22:02:20 +0000 | [diff] [blame] | 898 | if (verboseAsm) streamer.AddComment("FDE Length"); |
Rafael Espindola | 9266cc4 | 2011-04-27 01:43:49 +0000 | [diff] [blame] | 899 | streamer.EmitAbsValue(Length, 4); |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 900 | |
| 901 | streamer.EmitLabel(fdeStart); |
Rafael Espindola | e3a0e98 | 2011-05-10 20:59:42 +0000 | [diff] [blame] | 902 | |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 903 | // CIE Pointer |
Rafael Espindola | e3a0e98 | 2011-05-10 20:59:42 +0000 | [diff] [blame] | 904 | const MCAsmInfo &asmInfo = context.getAsmInfo(); |
Rafael Espindola | 0d450dc | 2011-05-10 15:20:23 +0000 | [diff] [blame] | 905 | if (IsEH) { |
| 906 | const MCExpr *offset = MakeStartMinusEndExpr(streamer, cieStart, *fdeStart, |
| 907 | 0); |
Bill Wendling | 2541c41 | 2011-06-30 22:02:20 +0000 | [diff] [blame] | 908 | if (verboseAsm) streamer.AddComment("FDE CIE Offset"); |
Rafael Espindola | 0d450dc | 2011-05-10 15:20:23 +0000 | [diff] [blame] | 909 | streamer.EmitAbsValue(offset, 4); |
Rafael Espindola | e3a0e98 | 2011-05-10 20:59:42 +0000 | [diff] [blame] | 910 | } else if (!asmInfo.doesDwarfRequireRelocationForSectionOffset()) { |
| 911 | const MCExpr *offset = MakeStartMinusEndExpr(streamer, *SectionStart, |
| 912 | cieStart, 0); |
| 913 | streamer.EmitAbsValue(offset, 4); |
Rafael Espindola | 0d450dc | 2011-05-10 15:20:23 +0000 | [diff] [blame] | 914 | } else { |
| 915 | streamer.EmitSymbolValue(&cieStart, 4); |
| 916 | } |
Bill Wendling | 2541c41 | 2011-06-30 22:02:20 +0000 | [diff] [blame] | 917 | |
Rafael Espindola | e3a0e98 | 2011-05-10 20:59:42 +0000 | [diff] [blame] | 918 | unsigned fdeEncoding = TAsmInfo.getFDEEncoding(UsingCFI); |
Rafael Espindola | abf9af6 | 2011-04-22 00:08:43 +0000 | [diff] [blame] | 919 | unsigned size = getSizeForEncoding(streamer, fdeEncoding); |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 920 | |
| 921 | // PC Begin |
Rafael Espindola | 9989ef4 | 2011-05-10 22:28:35 +0000 | [diff] [blame] | 922 | unsigned PCBeginEncoding = IsEH ? fdeEncoding : |
| 923 | (unsigned)dwarf::DW_EH_PE_absptr; |
Rafael Espindola | 40a7dbb | 2011-05-10 03:54:12 +0000 | [diff] [blame] | 924 | unsigned PCBeginSize = getSizeForEncoding(streamer, PCBeginEncoding); |
Bill Wendling | 2541c41 | 2011-06-30 22:02:20 +0000 | [diff] [blame] | 925 | EmitSymbol(streamer, *frame.Begin, PCBeginEncoding, "FDE initial location"); |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 926 | |
| 927 | // PC Range |
| 928 | const MCExpr *Range = MakeStartMinusEndExpr(streamer, *frame.Begin, |
| 929 | *frame.End, 0); |
Bill Wendling | 2541c41 | 2011-06-30 22:02:20 +0000 | [diff] [blame] | 930 | if (verboseAsm) streamer.AddComment("FDE address range"); |
Rafael Espindola | 9266cc4 | 2011-04-27 01:43:49 +0000 | [diff] [blame] | 931 | streamer.EmitAbsValue(Range, size); |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 932 | |
Rafael Espindola | 40a7dbb | 2011-05-10 03:54:12 +0000 | [diff] [blame] | 933 | if (IsEH) { |
| 934 | // Augmentation Data Length |
| 935 | unsigned augmentationLength = 0; |
Rafael Espindola | 1f6c875 | 2011-04-29 21:50:57 +0000 | [diff] [blame] | 936 | |
Rafael Espindola | 40a7dbb | 2011-05-10 03:54:12 +0000 | [diff] [blame] | 937 | if (frame.Lsda) |
| 938 | augmentationLength += getSizeForEncoding(streamer, frame.LsdaEncoding); |
Rafael Espindola | 1f6c875 | 2011-04-29 21:50:57 +0000 | [diff] [blame] | 939 | |
Bill Wendling | 2541c41 | 2011-06-30 22:02:20 +0000 | [diff] [blame] | 940 | if (verboseAsm) streamer.AddComment("Augmentation size"); |
Rafael Espindola | 40a7dbb | 2011-05-10 03:54:12 +0000 | [diff] [blame] | 941 | streamer.EmitULEB128IntValue(augmentationLength); |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 942 | |
Rafael Espindola | 40a7dbb | 2011-05-10 03:54:12 +0000 | [diff] [blame] | 943 | // Augmentation Data |
| 944 | if (frame.Lsda) |
Bill Wendling | 2541c41 | 2011-06-30 22:02:20 +0000 | [diff] [blame] | 945 | EmitSymbol(streamer, *frame.Lsda, frame.LsdaEncoding, |
| 946 | "Language Specific Data Area"); |
Rafael Espindola | 40a7dbb | 2011-05-10 03:54:12 +0000 | [diff] [blame] | 947 | } |
Rafael Espindola | 4892dff | 2011-04-29 03:06:29 +0000 | [diff] [blame] | 948 | |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 949 | // Call Frame Instructions |
| 950 | |
Rafael Espindola | b40a71f | 2010-12-29 01:42:56 +0000 | [diff] [blame] | 951 | EmitCFIInstructions(streamer, frame.Instructions, frame.Begin); |
Rafael Espindola | 5bba084 | 2010-12-28 04:15:37 +0000 | [diff] [blame] | 952 | |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 953 | // Padding |
Rafael Espindola | 40a7dbb | 2011-05-10 03:54:12 +0000 | [diff] [blame] | 954 | streamer.EmitValueToAlignment(PCBeginSize); |
Rafael Espindola | dfe125c | 2010-12-17 00:28:02 +0000 | [diff] [blame] | 955 | |
| 956 | return fdeEnd; |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 957 | } |
| 958 | |
Benjamin Kramer | 1928236 | 2010-12-30 22:34:44 +0000 | [diff] [blame] | 959 | namespace { |
| 960 | struct CIEKey { |
| 961 | static const CIEKey getEmptyKey() { return CIEKey(0, 0, -1); } |
| 962 | static const CIEKey getTombstoneKey() { return CIEKey(0, -1, 0); } |
Rafael Espindola | bdc3167 | 2010-12-27 15:56:22 +0000 | [diff] [blame] | 963 | |
Benjamin Kramer | 1928236 | 2010-12-30 22:34:44 +0000 | [diff] [blame] | 964 | CIEKey(const MCSymbol* Personality_, unsigned PersonalityEncoding_, |
| 965 | unsigned LsdaEncoding_) : Personality(Personality_), |
| 966 | PersonalityEncoding(PersonalityEncoding_), |
| 967 | LsdaEncoding(LsdaEncoding_) { |
| 968 | } |
| 969 | const MCSymbol* Personality; |
| 970 | unsigned PersonalityEncoding; |
| 971 | unsigned LsdaEncoding; |
| 972 | }; |
| 973 | } |
Rafael Espindola | bdc3167 | 2010-12-27 15:56:22 +0000 | [diff] [blame] | 974 | |
| 975 | namespace llvm { |
| 976 | template <> |
| 977 | struct DenseMapInfo<CIEKey> { |
| 978 | static CIEKey getEmptyKey() { |
Benjamin Kramer | 1928236 | 2010-12-30 22:34:44 +0000 | [diff] [blame] | 979 | return CIEKey::getEmptyKey(); |
Rafael Espindola | bdc3167 | 2010-12-27 15:56:22 +0000 | [diff] [blame] | 980 | } |
| 981 | static CIEKey getTombstoneKey() { |
Benjamin Kramer | 1928236 | 2010-12-30 22:34:44 +0000 | [diff] [blame] | 982 | return CIEKey::getTombstoneKey(); |
Rafael Espindola | bdc3167 | 2010-12-27 15:56:22 +0000 | [diff] [blame] | 983 | } |
| 984 | static unsigned getHashValue(const CIEKey &Key) { |
| 985 | FoldingSetNodeID ID; |
| 986 | ID.AddPointer(Key.Personality); |
| 987 | ID.AddInteger(Key.PersonalityEncoding); |
| 988 | ID.AddInteger(Key.LsdaEncoding); |
| 989 | return ID.ComputeHash(); |
| 990 | } |
| 991 | static bool isEqual(const CIEKey &LHS, |
| 992 | const CIEKey &RHS) { |
| 993 | return LHS.Personality == RHS.Personality && |
| 994 | LHS.PersonalityEncoding == RHS.PersonalityEncoding && |
| 995 | LHS.LsdaEncoding == RHS.LsdaEncoding; |
| 996 | } |
| 997 | }; |
| 998 | } |
| 999 | |
Bill Wendling | a8c9e6a | 2011-06-23 07:44:54 +0000 | [diff] [blame] | 1000 | void MCDwarfFrameEmitter::Emit(MCStreamer &Streamer, |
| 1001 | bool UsingCFI, |
| 1002 | bool IsEH) { |
| 1003 | MCContext &Context = Streamer.getContext(); |
| 1004 | const TargetAsmInfo &AsmInfo = Context.getTargetAsmInfo(); |
| 1005 | const MCSection &Section = IsEH ? *AsmInfo.getEHFrameSection() : |
| 1006 | *AsmInfo.getDwarfFrameSection(); |
| 1007 | Streamer.SwitchSection(&Section); |
| 1008 | MCSymbol *SectionStart = Context.CreateTempSymbol(); |
| 1009 | Streamer.EmitLabel(SectionStart); |
Rafael Espindola | 9099813 | 2011-04-29 02:42:28 +0000 | [diff] [blame] | 1010 | |
Bill Wendling | a8c9e6a | 2011-06-23 07:44:54 +0000 | [diff] [blame] | 1011 | MCSymbol *FDEEnd = NULL; |
Rafael Espindola | bdc3167 | 2010-12-27 15:56:22 +0000 | [diff] [blame] | 1012 | DenseMap<CIEKey, const MCSymbol*> CIEStarts; |
Bill Wendling | a8c9e6a | 2011-06-23 07:44:54 +0000 | [diff] [blame] | 1013 | FrameEmitterImpl Emitter(UsingCFI, IsEH, SectionStart); |
Rafael Espindola | d7c8cca | 2010-12-26 20:20:31 +0000 | [diff] [blame] | 1014 | |
Rafael Espindola | 40a7dbb | 2011-05-10 03:54:12 +0000 | [diff] [blame] | 1015 | const MCSymbol *DummyDebugKey = NULL; |
Bill Wendling | a8c9e6a | 2011-06-23 07:44:54 +0000 | [diff] [blame] | 1016 | for (unsigned i = 0, n = Streamer.getNumFrameInfos(); i < n; ++i) { |
| 1017 | const MCDwarfFrameInfo &Frame = Streamer.getFrameInfo(i); |
| 1018 | if (IsEH && AsmInfo.getCompactUnwindSection() && |
| 1019 | Emitter.EmitCompactUnwind(Streamer, Frame)) |
Bill Wendling | e3cd13f | 2011-06-23 01:06:23 +0000 | [diff] [blame] | 1020 | continue; |
| 1021 | |
Bill Wendling | a8c9e6a | 2011-06-23 07:44:54 +0000 | [diff] [blame] | 1022 | CIEKey Key(Frame.Personality, Frame.PersonalityEncoding, |
| 1023 | Frame.LsdaEncoding); |
| 1024 | const MCSymbol *&CIEStart = IsEH ? CIEStarts[Key] : DummyDebugKey; |
| 1025 | if (!CIEStart) |
| 1026 | CIEStart = &Emitter.EmitCIE(Streamer, Frame.Personality, |
| 1027 | Frame.PersonalityEncoding, Frame.Lsda, |
| 1028 | Frame.LsdaEncoding); |
Bill Wendling | e3cd13f | 2011-06-23 01:06:23 +0000 | [diff] [blame] | 1029 | |
Bill Wendling | a8c9e6a | 2011-06-23 07:44:54 +0000 | [diff] [blame] | 1030 | FDEEnd = Emitter.EmitFDE(Streamer, *CIEStart, Frame); |
Bill Wendling | e3cd13f | 2011-06-23 01:06:23 +0000 | [diff] [blame] | 1031 | |
Rafael Espindola | dfe125c | 2010-12-17 00:28:02 +0000 | [diff] [blame] | 1032 | if (i != n - 1) |
Bill Wendling | a8c9e6a | 2011-06-23 07:44:54 +0000 | [diff] [blame] | 1033 | Streamer.EmitLabel(FDEEnd); |
Rafael Espindola | dfe125c | 2010-12-17 00:28:02 +0000 | [diff] [blame] | 1034 | } |
Rafael Espindola | d7c8cca | 2010-12-26 20:20:31 +0000 | [diff] [blame] | 1035 | |
Bill Wendling | a8c9e6a | 2011-06-23 07:44:54 +0000 | [diff] [blame] | 1036 | Streamer.EmitValueToAlignment(AsmInfo.getPointerSize()); |
| 1037 | if (FDEEnd) |
| 1038 | Streamer.EmitLabel(FDEEnd); |
Rafael Espindola | 89b9372 | 2010-12-10 07:39:47 +0000 | [diff] [blame] | 1039 | } |
Rafael Espindola | 245a1e2 | 2010-12-28 05:39:27 +0000 | [diff] [blame] | 1040 | |
| 1041 | void MCDwarfFrameEmitter::EmitAdvanceLoc(MCStreamer &Streamer, |
| 1042 | uint64_t AddrDelta) { |
| 1043 | SmallString<256> Tmp; |
| 1044 | raw_svector_ostream OS(Tmp); |
Rafael Espindola | 4eafe10 | 2011-05-08 14:35:21 +0000 | [diff] [blame] | 1045 | MCDwarfFrameEmitter::EncodeAdvanceLoc(AddrDelta, OS); |
Rafael Espindola | 245a1e2 | 2010-12-28 05:39:27 +0000 | [diff] [blame] | 1046 | Streamer.EmitBytes(OS.str(), /*AddrSpace=*/0); |
| 1047 | } |
| 1048 | |
| 1049 | void MCDwarfFrameEmitter::EncodeAdvanceLoc(uint64_t AddrDelta, |
Rafael Espindola | 4eafe10 | 2011-05-08 14:35:21 +0000 | [diff] [blame] | 1050 | raw_ostream &OS) { |
Rafael Espindola | 245a1e2 | 2010-12-28 05:39:27 +0000 | [diff] [blame] | 1051 | // FIXME: Assumes the code alignment factor is 1. |
Rafael Espindola | 3b78cdc | 2010-12-28 23:38:03 +0000 | [diff] [blame] | 1052 | if (AddrDelta == 0) { |
Rafael Espindola | 4eafe10 | 2011-05-08 14:35:21 +0000 | [diff] [blame] | 1053 | } else if (isUIntN(6, AddrDelta)) { |
Rafael Espindola | 245a1e2 | 2010-12-28 05:39:27 +0000 | [diff] [blame] | 1054 | uint8_t Opcode = dwarf::DW_CFA_advance_loc | AddrDelta; |
| 1055 | OS << Opcode; |
Rafael Espindola | 4eafe10 | 2011-05-08 14:35:21 +0000 | [diff] [blame] | 1056 | } else if (isUInt<8>(AddrDelta)) { |
Rafael Espindola | 245a1e2 | 2010-12-28 05:39:27 +0000 | [diff] [blame] | 1057 | OS << uint8_t(dwarf::DW_CFA_advance_loc1); |
| 1058 | OS << uint8_t(AddrDelta); |
Rafael Espindola | 4eafe10 | 2011-05-08 14:35:21 +0000 | [diff] [blame] | 1059 | } else if (isUInt<16>(AddrDelta)) { |
Rafael Espindola | a7e4505 | 2010-12-29 02:30:49 +0000 | [diff] [blame] | 1060 | // FIXME: check what is the correct behavior on a big endian machine. |
Rafael Espindola | 245a1e2 | 2010-12-28 05:39:27 +0000 | [diff] [blame] | 1061 | OS << uint8_t(dwarf::DW_CFA_advance_loc2); |
Rafael Espindola | a7e4505 | 2010-12-29 02:30:49 +0000 | [diff] [blame] | 1062 | OS << uint8_t( AddrDelta & 0xff); |
| 1063 | OS << uint8_t((AddrDelta >> 8) & 0xff); |
Rafael Espindola | 245a1e2 | 2010-12-28 05:39:27 +0000 | [diff] [blame] | 1064 | } else { |
Rafael Espindola | a7e4505 | 2010-12-29 02:30:49 +0000 | [diff] [blame] | 1065 | // FIXME: check what is the correct behavior on a big endian machine. |
Rafael Espindola | 245a1e2 | 2010-12-28 05:39:27 +0000 | [diff] [blame] | 1066 | assert(isUInt<32>(AddrDelta)); |
| 1067 | OS << uint8_t(dwarf::DW_CFA_advance_loc4); |
Rafael Espindola | a7e4505 | 2010-12-29 02:30:49 +0000 | [diff] [blame] | 1068 | OS << uint8_t( AddrDelta & 0xff); |
| 1069 | OS << uint8_t((AddrDelta >> 8) & 0xff); |
| 1070 | OS << uint8_t((AddrDelta >> 16) & 0xff); |
| 1071 | OS << uint8_t((AddrDelta >> 24) & 0xff); |
| 1072 | |
Rafael Espindola | 245a1e2 | 2010-12-28 05:39:27 +0000 | [diff] [blame] | 1073 | } |
| 1074 | } |