MCDwarf.cpp revision 9e999adb48beb61663f6abca667b8c85068ee585
17cbf73a73f296167b6e978dbd919ed249e88eeb5Kevin Enderby//===- lib/MC/MCDwarf.cpp - MCDwarf implementation ------------------------===// 27cbf73a73f296167b6e978dbd919ed249e88eeb5Kevin Enderby// 37cbf73a73f296167b6e978dbd919ed249e88eeb5Kevin Enderby// The LLVM Compiler Infrastructure 47cbf73a73f296167b6e978dbd919ed249e88eeb5Kevin Enderby// 57cbf73a73f296167b6e978dbd919ed249e88eeb5Kevin Enderby// This file is distributed under the University of Illinois Open Source 67cbf73a73f296167b6e978dbd919ed249e88eeb5Kevin Enderby// License. See LICENSE.TXT for details. 77cbf73a73f296167b6e978dbd919ed249e88eeb5Kevin Enderby// 87cbf73a73f296167b6e978dbd919ed249e88eeb5Kevin Enderby//===----------------------------------------------------------------------===// 97cbf73a73f296167b6e978dbd919ed249e88eeb5Kevin Enderby 107cbf73a73f296167b6e978dbd919ed249e88eeb5Kevin Enderby#include "llvm/MC/MCDwarf.h" 11d04a8d4b33ff316ca4cf961e06c9e312eff8e64fChandler Carruth#include "llvm/ADT/Hashing.h" 12d04a8d4b33ff316ca4cf961e06c9e312eff8e64fChandler Carruth#include "llvm/ADT/SmallString.h" 13d04a8d4b33ff316ca4cf961e06c9e312eff8e64fChandler Carruth#include "llvm/ADT/Twine.h" 14d04a8d4b33ff316ca4cf961e06c9e312eff8e64fChandler Carruth#include "llvm/Config/config.h" 15e76a33b9567d78a5744dc52fcec3a6056d6fb576Evan Cheng#include "llvm/MC/MCAsmInfo.h" 16e76a33b9567d78a5744dc52fcec3a6056d6fb576Evan Cheng#include "llvm/MC/MCContext.h" 17d04a8d4b33ff316ca4cf961e06c9e312eff8e64fChandler Carruth#include "llvm/MC/MCExpr.h" 18e76a33b9567d78a5744dc52fcec3a6056d6fb576Evan Cheng#include "llvm/MC/MCObjectFileInfo.h" 19e76a33b9567d78a5744dc52fcec3a6056d6fb576Evan Cheng#include "llvm/MC/MCObjectWriter.h" 20e76a33b9567d78a5744dc52fcec3a6056d6fb576Evan Cheng#include "llvm/MC/MCRegisterInfo.h" 21ad8aaa069cfdb3bdc32b1becc8881f67b5272e14Rafael Espindola#include "llvm/MC/MCStreamer.h" 22c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby#include "llvm/MC/MCSymbol.h" 237cbf73a73f296167b6e978dbd919ed249e88eeb5Kevin Enderby#include "llvm/Support/Debug.h" 24fe024d0a624404ada11fb330e7360abc5f88742eRafael Espindola#include "llvm/Support/ErrorHandling.h" 252d39a0e52df9ce050bd4e2de3a2ecca8fd9a87c3Jim Grosbach#include "llvm/Support/LEB128.h" 2694c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby#include "llvm/Support/Path.h" 2794c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby#include "llvm/Support/SourceMgr.h" 28d04a8d4b33ff316ca4cf961e06c9e312eff8e64fChandler Carruth#include "llvm/Support/raw_ostream.h" 297cbf73a73f296167b6e978dbd919ed249e88eeb5Kevin Enderbyusing namespace llvm; 307cbf73a73f296167b6e978dbd919ed249e88eeb5Kevin Enderby 31c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby// Given a special op, return the address skip amount (in units of 32c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby// DWARF2_LINE_MIN_INSN_LENGTH. 33c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby#define SPECIAL_ADDR(op) (((op) - DWARF2_LINE_OPCODE_BASE)/DWARF2_LINE_RANGE) 34c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby 35c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby// The maximum address skip amount that can be encoded with a special op. 36c3882164cbf794dbe21816a2946a31bc9e02a419Bill Wendling#define MAX_SPECIAL_ADDR_DELTA SPECIAL_ADDR(255) 37c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby 38c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby// First special line opcode - leave room for the standard opcodes. 39c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby// Note: If you want to change this, you'll have to update the 402684d9e3c702b2ef9fd430155d94671d12fa994fJim Grosbach// "standard_opcode_lengths" table that is emitted in DwarfFileTable::Emit(). 41c3882164cbf794dbe21816a2946a31bc9e02a419Bill Wendling#define DWARF2_LINE_OPCODE_BASE 13 42c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby 43c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby// Minimum line offset in a special line info. opcode. This value 44c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby// was chosen to give a reasonable range of values. 45c3882164cbf794dbe21816a2946a31bc9e02a419Bill Wendling#define DWARF2_LINE_BASE -5 46c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby 47c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby// Range of line offsets in a special line info. opcode. 48c3882164cbf794dbe21816a2946a31bc9e02a419Bill Wendling#define DWARF2_LINE_RANGE 14 49c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby 50c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby// Define the architecture-dependent minimum instruction length (in bytes). 51c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby// This value should be rather too small than too big. 52c3882164cbf794dbe21816a2946a31bc9e02a419Bill Wendling#define DWARF2_LINE_MIN_INSN_LENGTH 1 53c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby 54c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby// Note: when DWARF2_LINE_MIN_INSN_LENGTH == 1 which is the current setting, 55c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby// this routine is a nop and will be optimized away. 56a8c9e6a943bc0873d1ce781d2444a6d6137f0e17Bill Wendlingstatic inline uint64_t ScaleAddrDelta(uint64_t AddrDelta) { 57c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby if (DWARF2_LINE_MIN_INSN_LENGTH == 1) 58c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby return AddrDelta; 59c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby if (AddrDelta % DWARF2_LINE_MIN_INSN_LENGTH != 0) { 60c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // TODO: report this error, but really only once. 61c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby ; 62c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby } 63c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby return AddrDelta / DWARF2_LINE_MIN_INSN_LENGTH; 64c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby} 65c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby 66c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby// 67c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby// This is called when an instruction is assembled into the specified section 68c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby// and if there is information from the last .loc directive that has yet to have 69c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby// a line entry made for it is made. 70c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby// 71195a0ce484cd12a5adae9184188f6d0fb52b84c0Rafael Espindolavoid MCLineEntry::Make(MCStreamer *MCOS, const MCSection *Section) { 72c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby if (!MCOS->getContext().getDwarfLocSeen()) 73c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby return; 74c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby 75c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // Create a symbol at in the current section for use in the line entry. 76c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby MCSymbol *LineSym = MCOS->getContext().CreateTempSymbol(); 77c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // Set the value of the symbol to use for the MCLineEntry. 78c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby MCOS->EmitLabel(LineSym); 79c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby 80c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // Get the current .loc info saved in the context. 81c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby const MCDwarfLoc &DwarfLoc = MCOS->getContext().getCurrentDwarfLoc(); 82c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby 83c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // Create a (local) line entry with the symbol and the current .loc info. 84c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby MCLineEntry LineEntry(LineSym, DwarfLoc); 85c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby 86c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // clear DwarfLocSeen saying the current .loc info is now used. 873f55c24df9527de345f6cc960944840a7a101c6aKevin Enderby MCOS->getContext().ClearDwarfLocSeen(); 88c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby 89c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // Get the MCLineSection for this section, if one does not exist for this 90c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // section create it. 9117fd7bda5ac08f873c063c64e1456f8960a0c765Rafael Espindola const DenseMap<const MCSection *, MCLineSection *> &MCLineSections = 92c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby MCOS->getContext().getMCLineSections(); 9317fd7bda5ac08f873c063c64e1456f8960a0c765Rafael Espindola MCLineSection *LineSection = MCLineSections.lookup(Section); 94c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby if (!LineSection) { 95c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // Create a new MCLineSection. This will be deleted after the dwarf line 96c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // table is created using it by iterating through the MCLineSections 97c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // DenseMap. 98c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby LineSection = new MCLineSection; 99c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // Save a pointer to the new LineSection into the MCLineSections DenseMap. 10017fd7bda5ac08f873c063c64e1456f8960a0c765Rafael Espindola MCOS->getContext().addMCLineSection(Section, LineSection); 101c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby } 102c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby 103c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // Add the line entry to this section's entries. 10443213cf1ac05b4198fcf9fa85d7da85477daafd1Manman Ren LineSection->addLineEntry(LineEntry, 10543213cf1ac05b4198fcf9fa85d7da85477daafd1Manman Ren MCOS->getContext().getDwarfCompileUnitID()); 106c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby} 107c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby 108c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby// 109c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby// This helper routine returns an expression of End - Start + IntVal . 1102684d9e3c702b2ef9fd430155d94671d12fa994fJim Grosbach// 1115fad7a99c00980fc30ce16fb51ce09dc435c40adRafael Espindolastatic inline const MCExpr *MakeStartMinusEndExpr(const MCStreamer &MCOS, 1125fad7a99c00980fc30ce16fb51ce09dc435c40adRafael Espindola const MCSymbol &Start, 1135fad7a99c00980fc30ce16fb51ce09dc435c40adRafael Espindola const MCSymbol &End, 1145fad7a99c00980fc30ce16fb51ce09dc435c40adRafael Espindola int IntVal) { 115c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby MCSymbolRefExpr::VariantKind Variant = MCSymbolRefExpr::VK_None; 116c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby const MCExpr *Res = 1175fad7a99c00980fc30ce16fb51ce09dc435c40adRafael Espindola MCSymbolRefExpr::Create(&End, Variant, MCOS.getContext()); 118c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby const MCExpr *RHS = 1195fad7a99c00980fc30ce16fb51ce09dc435c40adRafael Espindola MCSymbolRefExpr::Create(&Start, Variant, MCOS.getContext()); 120c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby const MCExpr *Res1 = 1215fad7a99c00980fc30ce16fb51ce09dc435c40adRafael Espindola MCBinaryExpr::Create(MCBinaryExpr::Sub, Res, RHS, MCOS.getContext()); 122c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby const MCExpr *Res2 = 1235fad7a99c00980fc30ce16fb51ce09dc435c40adRafael Espindola MCConstantExpr::Create(IntVal, MCOS.getContext()); 124c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby const MCExpr *Res3 = 1255fad7a99c00980fc30ce16fb51ce09dc435c40adRafael Espindola MCBinaryExpr::Create(MCBinaryExpr::Sub, Res1, Res2, MCOS.getContext()); 126c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby return Res3; 127c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby} 128c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby 129c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby// 130c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby// This emits the Dwarf line table for the specified section from the entries 131c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby// in the LineSection. 132c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby// 133195a0ce484cd12a5adae9184188f6d0fb52b84c0Rafael Espindolastatic inline void EmitDwarfLineTable(MCStreamer *MCOS, 134c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby const MCSection *Section, 13543213cf1ac05b4198fcf9fa85d7da85477daafd1Manman Ren const MCLineSection *LineSection, 13643213cf1ac05b4198fcf9fa85d7da85477daafd1Manman Ren unsigned CUID) { 13743213cf1ac05b4198fcf9fa85d7da85477daafd1Manman Ren // This LineSection does not contain any LineEntry for the given Compile Unit. 13843213cf1ac05b4198fcf9fa85d7da85477daafd1Manman Ren if (!LineSection->containEntriesForID(CUID)) 13943213cf1ac05b4198fcf9fa85d7da85477daafd1Manman Ren return; 14043213cf1ac05b4198fcf9fa85d7da85477daafd1Manman Ren 141c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby unsigned FileNum = 1; 142c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby unsigned LastLine = 1; 143c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby unsigned Column = 0; 144c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby unsigned Flags = DWARF2_LINE_DEFAULT_IS_STMT ? DWARF2_FLAG_IS_STMT : 0; 145c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby unsigned Isa = 0; 146c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby MCSymbol *LastLabel = NULL; 147c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby 148c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // Loop through each MCLineEntry and encode the dwarf line number table. 14917fd7bda5ac08f873c063c64e1456f8960a0c765Rafael Espindola for (MCLineSection::const_iterator 15043213cf1ac05b4198fcf9fa85d7da85477daafd1Manman Ren it = LineSection->getMCLineEntries(CUID).begin(), 15143213cf1ac05b4198fcf9fa85d7da85477daafd1Manman Ren ie = LineSection->getMCLineEntries(CUID).end(); it != ie; ++it) { 152c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby 153c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby if (FileNum != it->getFileNum()) { 154c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby FileNum = it->getFileNum(); 155c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby MCOS->EmitIntValue(dwarf::DW_LNS_set_file, 1); 1563ff57094a7d176a759ddb1e1668489d89064f56cRafael Espindola MCOS->EmitULEB128IntValue(FileNum); 157c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby } 158c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby if (Column != it->getColumn()) { 159c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby Column = it->getColumn(); 160c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby MCOS->EmitIntValue(dwarf::DW_LNS_set_column, 1); 1613ff57094a7d176a759ddb1e1668489d89064f56cRafael Espindola MCOS->EmitULEB128IntValue(Column); 162c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby } 163c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby if (Isa != it->getIsa()) { 164c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby Isa = it->getIsa(); 165c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby MCOS->EmitIntValue(dwarf::DW_LNS_set_isa, 1); 1663ff57094a7d176a759ddb1e1668489d89064f56cRafael Espindola MCOS->EmitULEB128IntValue(Isa); 167c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby } 168c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby if ((it->getFlags() ^ Flags) & DWARF2_FLAG_IS_STMT) { 169c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby Flags = it->getFlags(); 170c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby MCOS->EmitIntValue(dwarf::DW_LNS_negate_stmt, 1); 171c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby } 172c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby if (it->getFlags() & DWARF2_FLAG_BASIC_BLOCK) 173c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby MCOS->EmitIntValue(dwarf::DW_LNS_set_basic_block, 1); 174c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby if (it->getFlags() & DWARF2_FLAG_PROLOGUE_END) 175c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby MCOS->EmitIntValue(dwarf::DW_LNS_set_prologue_end, 1); 176c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby if (it->getFlags() & DWARF2_FLAG_EPILOGUE_BEGIN) 177c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby MCOS->EmitIntValue(dwarf::DW_LNS_set_epilogue_begin, 1); 178c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby 17964185cc6090f695c4f97c51cf2adc731f56d1a20Rafael Espindola int64_t LineDelta = static_cast<int64_t>(it->getLine()) - LastLine; 180c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby MCSymbol *Label = it->getLabel(); 181c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby 182c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // At this point we want to emit/create the sequence to encode the delta in 183c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // line numbers and the increment of the address from the previous Label 184c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // and the current Label. 1851be0e271a07925b928ba89848934f1ea6f1854e2Evan Cheng const MCAsmInfo &asmInfo = MCOS->getContext().getAsmInfo(); 186672b93a3324cc1da6d374eed4c75c050a9cad7beEvan Cheng MCOS->EmitDwarfAdvanceLineAddr(LineDelta, LastLabel, Label, 187672b93a3324cc1da6d374eed4c75c050a9cad7beEvan Cheng asmInfo.getPointerSize()); 188c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby 189c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby LastLine = it->getLine(); 190c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby LastLabel = Label; 191c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby } 192c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby 193c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // Emit a DW_LNE_end_sequence for the end of the section. 194c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // Using the pointer Section create a temporary label at the end of the 195c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // section and use that and the LastLabel to compute the address delta 196c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // and use INT64_MAX as the line delta which is the signal that this is 197c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // actually a DW_LNE_end_sequence. 198c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby 199c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // Switch to the section to be able to create a symbol at its end. 200c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby MCOS->SwitchSection(Section); 20189b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola 20289b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola MCContext &context = MCOS->getContext(); 203c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // Create a symbol at the end of the section. 20489b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola MCSymbol *SectionEnd = context.CreateTempSymbol(); 205c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // Set the value of the symbol, as we are at the end of the section. 206c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby MCOS->EmitLabel(SectionEnd); 207c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby 208c8e41c591741b3da1077f7000274ad040bef8002Sylvestre Ledru // Switch back the dwarf line section. 209e76a33b9567d78a5744dc52fcec3a6056d6fb576Evan Cheng MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfLineSection()); 210195a0ce484cd12a5adae9184188f6d0fb52b84c0Rafael Espindola 2111be0e271a07925b928ba89848934f1ea6f1854e2Evan Cheng const MCAsmInfo &asmInfo = MCOS->getContext().getAsmInfo(); 212672b93a3324cc1da6d374eed4c75c050a9cad7beEvan Cheng MCOS->EmitDwarfAdvanceLineAddr(INT64_MAX, LastLabel, SectionEnd, 213672b93a3324cc1da6d374eed4c75c050a9cad7beEvan Cheng asmInfo.getPointerSize()); 214c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby} 215c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby 216c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby// 217c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby// This emits the Dwarf file and the line tables. 218c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby// 219489d67927172941bf59b9f4829ab8910814fea24Rafael Espindolaconst MCSymbol *MCDwarfFileTable::Emit(MCStreamer *MCOS) { 22089b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola MCContext &context = MCOS->getContext(); 221c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // Switch to the section where the table will be emitted into. 222e76a33b9567d78a5744dc52fcec3a6056d6fb576Evan Cheng MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfLineSection()); 223c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby 22443213cf1ac05b4198fcf9fa85d7da85477daafd1Manman Ren const DenseMap<unsigned, MCSymbol *> &MCLineTableSymbols = 22543213cf1ac05b4198fcf9fa85d7da85477daafd1Manman Ren MCOS->getContext().getMCLineTableSymbols(); 22643213cf1ac05b4198fcf9fa85d7da85477daafd1Manman Ren // CUID and MCLineTableSymbols are set in DwarfDebug, when DwarfDebug does 22743213cf1ac05b4198fcf9fa85d7da85477daafd1Manman Ren // not exist, CUID will be 0 and MCLineTableSymbols will be empty. 22843213cf1ac05b4198fcf9fa85d7da85477daafd1Manman Ren // Handle Compile Unit 0, the line table start symbol is the section symbol. 22943213cf1ac05b4198fcf9fa85d7da85477daafd1Manman Ren const MCSymbol *LineStartSym = EmitCU(MCOS, 0); 23043213cf1ac05b4198fcf9fa85d7da85477daafd1Manman Ren // Handle the rest of the Compile Units. 23143213cf1ac05b4198fcf9fa85d7da85477daafd1Manman Ren for (unsigned Is = 1, Ie = MCLineTableSymbols.size(); Is < Ie; Is++) 23243213cf1ac05b4198fcf9fa85d7da85477daafd1Manman Ren EmitCU(MCOS, Is); 23343213cf1ac05b4198fcf9fa85d7da85477daafd1Manman Ren 23443213cf1ac05b4198fcf9fa85d7da85477daafd1Manman Ren // Now delete the MCLineSections that were created in MCLineEntry::Make() 23543213cf1ac05b4198fcf9fa85d7da85477daafd1Manman Ren // and used to emit the line table. 23643213cf1ac05b4198fcf9fa85d7da85477daafd1Manman Ren const DenseMap<const MCSection *, MCLineSection *> &MCLineSections = 23743213cf1ac05b4198fcf9fa85d7da85477daafd1Manman Ren MCOS->getContext().getMCLineSections(); 23843213cf1ac05b4198fcf9fa85d7da85477daafd1Manman Ren for (DenseMap<const MCSection *, MCLineSection *>::const_iterator it = 23943213cf1ac05b4198fcf9fa85d7da85477daafd1Manman Ren MCLineSections.begin(), ie = MCLineSections.end(); it != ie; 24043213cf1ac05b4198fcf9fa85d7da85477daafd1Manman Ren ++it) 24143213cf1ac05b4198fcf9fa85d7da85477daafd1Manman Ren delete it->second; 24243213cf1ac05b4198fcf9fa85d7da85477daafd1Manman Ren 24343213cf1ac05b4198fcf9fa85d7da85477daafd1Manman Ren return LineStartSym; 24443213cf1ac05b4198fcf9fa85d7da85477daafd1Manman Ren} 24543213cf1ac05b4198fcf9fa85d7da85477daafd1Manman Ren 24643213cf1ac05b4198fcf9fa85d7da85477daafd1Manman Renconst MCSymbol *MCDwarfFileTable::EmitCU(MCStreamer *MCOS, unsigned CUID) { 24743213cf1ac05b4198fcf9fa85d7da85477daafd1Manman Ren MCContext &context = MCOS->getContext(); 24843213cf1ac05b4198fcf9fa85d7da85477daafd1Manman Ren 24943213cf1ac05b4198fcf9fa85d7da85477daafd1Manman Ren // Create a symbol at the beginning of the line table. 25043213cf1ac05b4198fcf9fa85d7da85477daafd1Manman Ren MCSymbol *LineStartSym = MCOS->getContext().getMCLineTableSymbol(CUID); 25143213cf1ac05b4198fcf9fa85d7da85477daafd1Manman Ren if (!LineStartSym) 25243213cf1ac05b4198fcf9fa85d7da85477daafd1Manman Ren LineStartSym = context.CreateTempSymbol(); 25343213cf1ac05b4198fcf9fa85d7da85477daafd1Manman Ren // Set the value of the symbol, as we are at the start of the line table. 254c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby MCOS->EmitLabel(LineStartSym); 255c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby 256c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // Create a symbol for the end of the section (to be set when we get there). 25789b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola MCSymbol *LineEndSym = context.CreateTempSymbol(); 258c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby 259c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // The first 4 bytes is the total length of the information for this 260c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // compilation unit (not including these 4 bytes for the length). 2615fad7a99c00980fc30ce16fb51ce09dc435c40adRafael Espindola MCOS->EmitAbsValue(MakeStartMinusEndExpr(*MCOS, *LineStartSym, *LineEndSym,4), 2620bbe0b440ee2cef47dcb7b281825eb70341c16ddRafael Espindola 4); 263c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby 264c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // Next 2 bytes is the Version, which is Dwarf 2. 265c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby MCOS->EmitIntValue(2, 2); 266c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby 267c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // Create a symbol for the end of the prologue (to be set when we get there). 26889b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola MCSymbol *ProEndSym = context.CreateTempSymbol(); // Lprologue_end 269c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby 270c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // Length of the prologue, is the next 4 bytes. Which is the start of the 271c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // section to the end of the prologue. Not including the 4 bytes for the 272c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // total length, the 2 bytes for the version, and these 4 bytes for the 273c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // length of the prologue. 2745fad7a99c00980fc30ce16fb51ce09dc435c40adRafael Espindola MCOS->EmitAbsValue(MakeStartMinusEndExpr(*MCOS, *LineStartSym, *ProEndSym, 275e0501e866ca15601f4da2dc6b5572dc2de53abc8Eric Christopher (4 + 2 + 4)), 4, 0); 276c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby 277c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // Parameters of the state machine, are next. 278c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby MCOS->EmitIntValue(DWARF2_LINE_MIN_INSN_LENGTH, 1); 279c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby MCOS->EmitIntValue(DWARF2_LINE_DEFAULT_IS_STMT, 1); 280c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby MCOS->EmitIntValue(DWARF2_LINE_BASE, 1); 281c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby MCOS->EmitIntValue(DWARF2_LINE_RANGE, 1); 282c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby MCOS->EmitIntValue(DWARF2_LINE_OPCODE_BASE, 1); 283c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby 284c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // Standard opcode lengths 285c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby MCOS->EmitIntValue(0, 1); // length of DW_LNS_copy 286c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby MCOS->EmitIntValue(1, 1); // length of DW_LNS_advance_pc 287c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby MCOS->EmitIntValue(1, 1); // length of DW_LNS_advance_line 288c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby MCOS->EmitIntValue(1, 1); // length of DW_LNS_set_file 289c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby MCOS->EmitIntValue(1, 1); // length of DW_LNS_set_column 290c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby MCOS->EmitIntValue(0, 1); // length of DW_LNS_negate_stmt 291c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby MCOS->EmitIntValue(0, 1); // length of DW_LNS_set_basic_block 292c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby MCOS->EmitIntValue(0, 1); // length of DW_LNS_const_add_pc 293c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby MCOS->EmitIntValue(1, 1); // length of DW_LNS_fixed_advance_pc 294c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby MCOS->EmitIntValue(0, 1); // length of DW_LNS_set_prologue_end 295c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby MCOS->EmitIntValue(0, 1); // length of DW_LNS_set_epilogue_begin 296c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby MCOS->EmitIntValue(1, 1); // DW_LNS_set_isa 297c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby 298c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // Put out the directory and file tables. 299c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby 300c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // First the directory table. 3019e999adb48beb61663f6abca667b8c85068ee585Manman Ren const SmallVectorImpl<StringRef> &MCDwarfDirs = 3023de61b4c0144748e4b9157e2c22fe4ea685981a2Manman Ren context.getMCDwarfDirs(CUID); 303c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby for (unsigned i = 0; i < MCDwarfDirs.size(); i++) { 30468ca56285f9b6e82eb16ff8ea02a301f2c489faeEric Christopher MCOS->EmitBytes(MCDwarfDirs[i]); // the DirectoryName 30568ca56285f9b6e82eb16ff8ea02a301f2c489faeEric Christopher MCOS->EmitBytes(StringRef("\0", 1)); // the null term. of the string 306c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby } 307c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby MCOS->EmitIntValue(0, 1); // Terminate the directory list 308c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby 309c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // Second the file table. 3109e999adb48beb61663f6abca667b8c85068ee585Manman Ren const SmallVectorImpl<MCDwarfFile *> &MCDwarfFiles = 3113de61b4c0144748e4b9157e2c22fe4ea685981a2Manman Ren MCOS->getContext().getMCDwarfFiles(CUID); 312c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby for (unsigned i = 1; i < MCDwarfFiles.size(); i++) { 31368ca56285f9b6e82eb16ff8ea02a301f2c489faeEric Christopher MCOS->EmitBytes(MCDwarfFiles[i]->getName()); // FileName 31468ca56285f9b6e82eb16ff8ea02a301f2c489faeEric Christopher MCOS->EmitBytes(StringRef("\0", 1)); // the null term. of the string 3153ff57094a7d176a759ddb1e1668489d89064f56cRafael Espindola // the Directory num 3163ff57094a7d176a759ddb1e1668489d89064f56cRafael Espindola MCOS->EmitULEB128IntValue(MCDwarfFiles[i]->getDirIndex()); 317c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby MCOS->EmitIntValue(0, 1); // last modification timestamp (always 0) 318c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby MCOS->EmitIntValue(0, 1); // filesize (always 0) 319c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby } 320c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby MCOS->EmitIntValue(0, 1); // Terminate the file list 321c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby 322c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // This is the end of the prologue, so set the value of the symbol at the 323c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // end of the prologue (that was used in a previous expression). 324c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby MCOS->EmitLabel(ProEndSym); 325c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby 326c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // Put out the line tables. 32717fd7bda5ac08f873c063c64e1456f8960a0c765Rafael Espindola const DenseMap<const MCSection *, MCLineSection *> &MCLineSections = 328c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby MCOS->getContext().getMCLineSections(); 32917fd7bda5ac08f873c063c64e1456f8960a0c765Rafael Espindola const std::vector<const MCSection *> &MCLineSectionOrder = 33017fd7bda5ac08f873c063c64e1456f8960a0c765Rafael Espindola MCOS->getContext().getMCLineSectionOrder(); 33117fd7bda5ac08f873c063c64e1456f8960a0c765Rafael Espindola for (std::vector<const MCSection*>::const_iterator it = 332c3882164cbf794dbe21816a2946a31bc9e02a419Bill Wendling MCLineSectionOrder.begin(), ie = MCLineSectionOrder.end(); it != ie; 33317fd7bda5ac08f873c063c64e1456f8960a0c765Rafael Espindola ++it) { 33417fd7bda5ac08f873c063c64e1456f8960a0c765Rafael Espindola const MCSection *Sec = *it; 33517fd7bda5ac08f873c063c64e1456f8960a0c765Rafael Espindola const MCLineSection *Line = MCLineSections.lookup(Sec); 33643213cf1ac05b4198fcf9fa85d7da85477daafd1Manman Ren EmitDwarfLineTable(MCOS, Sec, Line, CUID); 337c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby } 338c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby 339767b1be3900bdc693aa0ad3e554ba034845f67f7Rafael Espindola if (MCOS->getContext().getAsmInfo().getLinkerRequiresNonEmptyDwarfLines() 340767b1be3900bdc693aa0ad3e554ba034845f67f7Rafael Espindola && MCLineSectionOrder.begin() == MCLineSectionOrder.end()) { 341a8de83c68aaa03cafa0e3618fb8bf030b48f6540Rafael Espindola // The darwin9 linker has a bug (see PR8715). For for 32-bit architectures 3422684d9e3c702b2ef9fd430155d94671d12fa994fJim Grosbach // it requires: 343a8de83c68aaa03cafa0e3618fb8bf030b48f6540Rafael Espindola // total_length >= prologue_length + 10 344a8de83c68aaa03cafa0e3618fb8bf030b48f6540Rafael Espindola // We are 4 bytes short, since we have total_length = 51 and 345a8de83c68aaa03cafa0e3618fb8bf030b48f6540Rafael Espindola // prologue_length = 45 346a8de83c68aaa03cafa0e3618fb8bf030b48f6540Rafael Espindola 347a8de83c68aaa03cafa0e3618fb8bf030b48f6540Rafael Espindola // The regular end_sequence should be sufficient. 348a8de83c68aaa03cafa0e3618fb8bf030b48f6540Rafael Espindola MCDwarfLineAddr::Emit(MCOS, INT64_MAX, 0); 3495113cdbfff7df4c7a79a92e5aa971126254202c6Devang Patel } 3505113cdbfff7df4c7a79a92e5aa971126254202c6Devang Patel 351c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // This is the end of the section, so set the value of the symbol at the end 352c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // of this section (that was used in a previous expression). 353c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby MCOS->EmitLabel(LineEndSym); 354489d67927172941bf59b9f4829ab8910814fea24Rafael Espindola 355489d67927172941bf59b9f4829ab8910814fea24Rafael Espindola return LineStartSym; 356c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby} 357c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby 358c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby/// Utility function to write the encoding to an object writer. 359c095793b4ab027181605c79c9808df12afe45d63Kevin Enderbyvoid MCDwarfLineAddr::Write(MCObjectWriter *OW, int64_t LineDelta, 360c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby uint64_t AddrDelta) { 361c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby SmallString<256> Tmp; 362c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby raw_svector_ostream OS(Tmp); 363c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby MCDwarfLineAddr::Encode(LineDelta, AddrDelta, OS); 364c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby OW->WriteBytes(OS.str()); 365c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby} 366c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby 367c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby/// Utility function to emit the encoding to a streamer. 368195a0ce484cd12a5adae9184188f6d0fb52b84c0Rafael Espindolavoid MCDwarfLineAddr::Emit(MCStreamer *MCOS, int64_t LineDelta, 369c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby uint64_t AddrDelta) { 370c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby SmallString<256> Tmp; 371c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby raw_svector_ostream OS(Tmp); 372c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby MCDwarfLineAddr::Encode(LineDelta, AddrDelta, OS); 37368ca56285f9b6e82eb16ff8ea02a301f2c489faeEric Christopher MCOS->EmitBytes(OS.str()); 374c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby} 375c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby 376c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby/// Utility function to encode a Dwarf pair of LineDelta and AddrDeltas. 377c095793b4ab027181605c79c9808df12afe45d63Kevin Enderbyvoid MCDwarfLineAddr::Encode(int64_t LineDelta, uint64_t AddrDelta, 378c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby raw_ostream &OS) { 379c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby uint64_t Temp, Opcode; 380c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby bool NeedCopy = false; 381c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby 382c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // Scale the address delta by the minimum instruction length. 383c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby AddrDelta = ScaleAddrDelta(AddrDelta); 384c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby 385c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // A LineDelta of INT64_MAX is a signal that this is actually a 3862684d9e3c702b2ef9fd430155d94671d12fa994fJim Grosbach // DW_LNE_end_sequence. We cannot use special opcodes here, since we want the 387c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // end_sequence to emit the matrix entry. 388c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby if (LineDelta == INT64_MAX) { 389c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby if (AddrDelta == MAX_SPECIAL_ADDR_DELTA) 390c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby OS << char(dwarf::DW_LNS_const_add_pc); 391c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby else { 392c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby OS << char(dwarf::DW_LNS_advance_pc); 3932d39a0e52df9ce050bd4e2de3a2ecca8fd9a87c3Jim Grosbach encodeULEB128(AddrDelta, OS); 394c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby } 395c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby OS << char(dwarf::DW_LNS_extended_op); 396c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby OS << char(1); 397c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby OS << char(dwarf::DW_LNE_end_sequence); 398c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby return; 399c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby } 400c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby 401c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // Bias the line delta by the base. 402c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby Temp = LineDelta - DWARF2_LINE_BASE; 403c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby 404c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // If the line increment is out of range of a special opcode, we must encode 405c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // it with DW_LNS_advance_line. 406c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby if (Temp >= DWARF2_LINE_RANGE) { 407c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby OS << char(dwarf::DW_LNS_advance_line); 4082d39a0e52df9ce050bd4e2de3a2ecca8fd9a87c3Jim Grosbach encodeSLEB128(LineDelta, OS); 409c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby 410c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby LineDelta = 0; 411c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby Temp = 0 - DWARF2_LINE_BASE; 412c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby NeedCopy = true; 413c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby } 414c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby 415c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // Use DW_LNS_copy instead of a "line +0, addr +0" special opcode. 416c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby if (LineDelta == 0 && AddrDelta == 0) { 417c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby OS << char(dwarf::DW_LNS_copy); 418c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby return; 419c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby } 420c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby 421c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // Bias the opcode by the special opcode base. 422c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby Temp += DWARF2_LINE_OPCODE_BASE; 423c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby 424c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // Avoid overflow when addr_delta is large. 425c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby if (AddrDelta < 256 + MAX_SPECIAL_ADDR_DELTA) { 426c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // Try using a special opcode. 427c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby Opcode = Temp + AddrDelta * DWARF2_LINE_RANGE; 428c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby if (Opcode <= 255) { 429c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby OS << char(Opcode); 430c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby return; 431c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby } 432c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby 433c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // Try using DW_LNS_const_add_pc followed by special op. 434c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby Opcode = Temp + (AddrDelta - MAX_SPECIAL_ADDR_DELTA) * DWARF2_LINE_RANGE; 435c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby if (Opcode <= 255) { 436c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby OS << char(dwarf::DW_LNS_const_add_pc); 437c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby OS << char(Opcode); 438c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby return; 439c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby } 440c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby } 441c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby 442c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby // Otherwise use DW_LNS_advance_pc. 443c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby OS << char(dwarf::DW_LNS_advance_pc); 4442d39a0e52df9ce050bd4e2de3a2ecca8fd9a87c3Jim Grosbach encodeULEB128(AddrDelta, OS); 445c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby 446c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby if (NeedCopy) 447c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby OS << char(dwarf::DW_LNS_copy); 448c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby else 449c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby OS << char(Temp); 450c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby} 451c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby 4527cbf73a73f296167b6e978dbd919ed249e88eeb5Kevin Enderbyvoid MCDwarfFile::print(raw_ostream &OS) const { 4537cbf73a73f296167b6e978dbd919ed249e88eeb5Kevin Enderby OS << '"' << getName() << '"'; 4547cbf73a73f296167b6e978dbd919ed249e88eeb5Kevin Enderby} 4557cbf73a73f296167b6e978dbd919ed249e88eeb5Kevin Enderby 456286c4dc355b8be6806081b23c3097485821c7642Manman Ren#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 4577cbf73a73f296167b6e978dbd919ed249e88eeb5Kevin Enderbyvoid MCDwarfFile::dump() const { 4587cbf73a73f296167b6e978dbd919ed249e88eeb5Kevin Enderby print(dbgs()); 4597cbf73a73f296167b6e978dbd919ed249e88eeb5Kevin Enderby} 460cc77eece74c8db09acc2af425e7e6c88a5bb30d1Manman Ren#endif 461c095793b4ab027181605c79c9808df12afe45d63Kevin Enderby 46294c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby// Utility function to write a tuple for .debug_abbrev. 46394c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderbystatic void EmitAbbrev(MCStreamer *MCOS, uint64_t Name, uint64_t Form) { 46494c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCOS->EmitULEB128IntValue(Name); 46594c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCOS->EmitULEB128IntValue(Form); 46694c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby} 46794c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 46894c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby// When generating dwarf for assembly source files this emits 46994c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby// the data for .debug_abbrev section which contains three DIEs. 47094c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderbystatic void EmitGenDwarfAbbrev(MCStreamer *MCOS) { 47194c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCContext &context = MCOS->getContext(); 47294c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfAbbrevSection()); 47394c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 47494c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // DW_TAG_compile_unit DIE abbrev (1). 47594c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCOS->EmitULEB128IntValue(1); 47694c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCOS->EmitULEB128IntValue(dwarf::DW_TAG_compile_unit); 47794c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCOS->EmitIntValue(dwarf::DW_CHILDREN_yes, 1); 47894c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby EmitAbbrev(MCOS, dwarf::DW_AT_stmt_list, dwarf::DW_FORM_data4); 47994c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby EmitAbbrev(MCOS, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr); 48094c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby EmitAbbrev(MCOS, dwarf::DW_AT_high_pc, dwarf::DW_FORM_addr); 48194c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby EmitAbbrev(MCOS, dwarf::DW_AT_name, dwarf::DW_FORM_string); 48294c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby EmitAbbrev(MCOS, dwarf::DW_AT_comp_dir, dwarf::DW_FORM_string); 48394c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby StringRef DwarfDebugFlags = context.getDwarfDebugFlags(); 48494c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby if (!DwarfDebugFlags.empty()) 48594c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby EmitAbbrev(MCOS, dwarf::DW_AT_APPLE_flags, dwarf::DW_FORM_string); 48694c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby EmitAbbrev(MCOS, dwarf::DW_AT_producer, dwarf::DW_FORM_string); 48794c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby EmitAbbrev(MCOS, dwarf::DW_AT_language, dwarf::DW_FORM_data2); 48894c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby EmitAbbrev(MCOS, 0, 0); 48994c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 49038fdb7d9fc40e9f29c3156b6625cac8d91d562e1Kevin Enderby // DW_TAG_label DIE abbrev (2). 49194c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCOS->EmitULEB128IntValue(2); 49238fdb7d9fc40e9f29c3156b6625cac8d91d562e1Kevin Enderby MCOS->EmitULEB128IntValue(dwarf::DW_TAG_label); 49394c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCOS->EmitIntValue(dwarf::DW_CHILDREN_yes, 1); 49494c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby EmitAbbrev(MCOS, dwarf::DW_AT_name, dwarf::DW_FORM_string); 49594c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby EmitAbbrev(MCOS, dwarf::DW_AT_decl_file, dwarf::DW_FORM_data4); 49694c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby EmitAbbrev(MCOS, dwarf::DW_AT_decl_line, dwarf::DW_FORM_data4); 49794c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby EmitAbbrev(MCOS, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr); 49894c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby EmitAbbrev(MCOS, dwarf::DW_AT_prototyped, dwarf::DW_FORM_flag); 49994c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby EmitAbbrev(MCOS, 0, 0); 50094c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 50194c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // DW_TAG_unspecified_parameters DIE abbrev (3). 50294c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCOS->EmitULEB128IntValue(3); 50394c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCOS->EmitULEB128IntValue(dwarf::DW_TAG_unspecified_parameters); 50494c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCOS->EmitIntValue(dwarf::DW_CHILDREN_no, 1); 50594c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby EmitAbbrev(MCOS, 0, 0); 50694c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 50794c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // Terminate the abbreviations for this compilation unit. 50894c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCOS->EmitIntValue(0, 1); 50994c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby} 51094c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 51194c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby// When generating dwarf for assembly source files this emits the data for 51294c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby// .debug_aranges section. Which contains a header and a table of pairs of 51394c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby// PointerSize'ed values for the address and size of section(s) with line table 51494c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby// entries (just the default .text in our case) and a terminating pair of zeros. 51515ab115df57949fa55d92ffdfba491f7d02ed60fAlexey Samsonovstatic void EmitGenDwarfAranges(MCStreamer *MCOS, 51615ab115df57949fa55d92ffdfba491f7d02ed60fAlexey Samsonov const MCSymbol *InfoSectionSymbol) { 51794c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCContext &context = MCOS->getContext(); 51894c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 51994c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // Create a symbol at the end of the section that we are creating the dwarf 52094c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // debugging info to use later in here as part of the expression to calculate 52194c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // the size of the section for the table. 52294c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCOS->SwitchSection(context.getGenDwarfSection()); 52394c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCSymbol *SectionEndSym = context.CreateTempSymbol(); 52494c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCOS->EmitLabel(SectionEndSym); 52594c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby context.setGenDwarfSectionEndSym(SectionEndSym); 52694c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 52794c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfARangesSection()); 52894c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 52994c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // This will be the length of the .debug_aranges section, first account for 53094c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // the size of each item in the header (see below where we emit these items). 53194c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby int Length = 4 + 2 + 4 + 1 + 1; 53294c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 53394c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // Figure the padding after the header before the table of address and size 53494c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // pairs who's values are PointerSize'ed. 53594c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby const MCAsmInfo &asmInfo = context.getAsmInfo(); 53694c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby int AddrSize = asmInfo.getPointerSize(); 53794c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby int Pad = 2 * AddrSize - (Length & (2 * AddrSize - 1)); 53894c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby if (Pad == 2 * AddrSize) 53994c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby Pad = 0; 54094c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby Length += Pad; 54194c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 54294c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // Add the size of the pair of PointerSize'ed values for the address and size 54394c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // of the one default .text section we have in the table. 54494c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby Length += 2 * AddrSize; 54594c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // And the pair of terminating zeros. 54694c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby Length += 2 * AddrSize; 54794c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 54894c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 54994c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // Emit the header for this section. 55094c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // The 4 byte length not including the 4 byte value for the length. 55194c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCOS->EmitIntValue(Length - 4, 4); 55294c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // The 2 byte version, which is 2. 55394c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCOS->EmitIntValue(2, 2); 55494c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // The 4 byte offset to the compile unit in the .debug_info from the start 55515ab115df57949fa55d92ffdfba491f7d02ed60fAlexey Samsonov // of the .debug_info. 55615ab115df57949fa55d92ffdfba491f7d02ed60fAlexey Samsonov if (InfoSectionSymbol) 55715ab115df57949fa55d92ffdfba491f7d02ed60fAlexey Samsonov MCOS->EmitSymbolValue(InfoSectionSymbol, 4); 55815ab115df57949fa55d92ffdfba491f7d02ed60fAlexey Samsonov else 55915ab115df57949fa55d92ffdfba491f7d02ed60fAlexey Samsonov MCOS->EmitIntValue(0, 4); 56094c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // The 1 byte size of an address. 56194c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCOS->EmitIntValue(AddrSize, 1); 56294c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // The 1 byte size of a segment descriptor, we use a value of zero. 56394c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCOS->EmitIntValue(0, 1); 56494c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // Align the header with the padding if needed, before we put out the table. 56594c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby for(int i = 0; i < Pad; i++) 56694c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCOS->EmitIntValue(0, 1); 56794c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 56894c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // Now emit the table of pairs of PointerSize'ed values for the section(s) 56994c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // address and size, in our case just the one default .text section. 57094c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby const MCExpr *Addr = MCSymbolRefExpr::Create( 57194c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby context.getGenDwarfSectionStartSym(), MCSymbolRefExpr::VK_None, context); 57294c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby const MCExpr *Size = MakeStartMinusEndExpr(*MCOS, 57394c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby *context.getGenDwarfSectionStartSym(), *SectionEndSym, 0); 57494c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCOS->EmitAbsValue(Addr, AddrSize); 57594c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCOS->EmitAbsValue(Size, AddrSize); 57694c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 57794c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // And finally the pair of terminating zeros. 57894c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCOS->EmitIntValue(0, AddrSize); 57994c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCOS->EmitIntValue(0, AddrSize); 58094c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby} 58194c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 58294c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby// When generating dwarf for assembly source files this emits the data for 58394c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby// .debug_info section which contains three parts. The header, the compile_unit 58438fdb7d9fc40e9f29c3156b6625cac8d91d562e1Kevin Enderby// DIE and a list of label DIEs. 585489d67927172941bf59b9f4829ab8910814fea24Rafael Espindolastatic void EmitGenDwarfInfo(MCStreamer *MCOS, 586489d67927172941bf59b9f4829ab8910814fea24Rafael Espindola const MCSymbol *AbbrevSectionSymbol, 587489d67927172941bf59b9f4829ab8910814fea24Rafael Espindola const MCSymbol *LineSectionSymbol) { 58894c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCContext &context = MCOS->getContext(); 58994c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 5902684d9e3c702b2ef9fd430155d94671d12fa994fJim Grosbach MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfInfoSection()); 59194c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 59294c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // Create a symbol at the start and end of this section used in here for the 59394c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // expression to calculate the length in the header. 59494c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCSymbol *InfoStart = context.CreateTempSymbol(); 59594c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCOS->EmitLabel(InfoStart); 59694c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCSymbol *InfoEnd = context.CreateTempSymbol(); 59794c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 59894c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // First part: the header. 59994c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 60094c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // The 4 byte total length of the information for this compilation unit, not 60194c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // including these 4 bytes. 60294c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby const MCExpr *Length = MakeStartMinusEndExpr(*MCOS, *InfoStart, *InfoEnd, 4); 60394c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCOS->EmitAbsValue(Length, 4); 60494c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 60594c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // The 2 byte DWARF version, which is 2. 60694c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCOS->EmitIntValue(2, 2); 60794c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 60894c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // The 4 byte offset to the debug abbrevs from the start of the .debug_abbrev, 60994c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // it is at the start of that section so this is zero. 610489d67927172941bf59b9f4829ab8910814fea24Rafael Espindola if (AbbrevSectionSymbol) { 611489d67927172941bf59b9f4829ab8910814fea24Rafael Espindola MCOS->EmitSymbolValue(AbbrevSectionSymbol, 4); 612489d67927172941bf59b9f4829ab8910814fea24Rafael Espindola } else { 613489d67927172941bf59b9f4829ab8910814fea24Rafael Espindola MCOS->EmitIntValue(0, 4); 614489d67927172941bf59b9f4829ab8910814fea24Rafael Espindola } 61594c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 61694c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby const MCAsmInfo &asmInfo = context.getAsmInfo(); 61794c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby int AddrSize = asmInfo.getPointerSize(); 61894c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // The 1 byte size of an address. 61994c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCOS->EmitIntValue(AddrSize, 1); 62094c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 62194c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // Second part: the compile_unit DIE. 62294c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 62394c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // The DW_TAG_compile_unit DIE abbrev (1). 62494c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCOS->EmitULEB128IntValue(1); 62594c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 62694c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // DW_AT_stmt_list, a 4 byte offset from the start of the .debug_line section, 62794c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // which is at the start of that section so this is zero. 628489d67927172941bf59b9f4829ab8910814fea24Rafael Espindola if (LineSectionSymbol) { 629489d67927172941bf59b9f4829ab8910814fea24Rafael Espindola MCOS->EmitSymbolValue(LineSectionSymbol, 4); 630489d67927172941bf59b9f4829ab8910814fea24Rafael Espindola } else { 631489d67927172941bf59b9f4829ab8910814fea24Rafael Espindola MCOS->EmitIntValue(0, 4); 632489d67927172941bf59b9f4829ab8910814fea24Rafael Espindola } 63394c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 63494c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // AT_low_pc, the first address of the default .text section. 63594c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby const MCExpr *Start = MCSymbolRefExpr::Create( 63694c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby context.getGenDwarfSectionStartSym(), MCSymbolRefExpr::VK_None, context); 63794c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCOS->EmitAbsValue(Start, AddrSize); 63894c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 63994c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // AT_high_pc, the last address of the default .text section. 64094c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby const MCExpr *End = MCSymbolRefExpr::Create( 64194c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby context.getGenDwarfSectionEndSym(), MCSymbolRefExpr::VK_None, context); 64294c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCOS->EmitAbsValue(End, AddrSize); 64394c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 64494c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // AT_name, the name of the source file. Reconstruct from the first directory 64594c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // and file table entries. 6469e999adb48beb61663f6abca667b8c85068ee585Manman Ren const SmallVectorImpl<StringRef> &MCDwarfDirs = 64794c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby context.getMCDwarfDirs(); 64894c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby if (MCDwarfDirs.size() > 0) { 64968ca56285f9b6e82eb16ff8ea02a301f2c489faeEric Christopher MCOS->EmitBytes(MCDwarfDirs[0]); 65068ca56285f9b6e82eb16ff8ea02a301f2c489faeEric Christopher MCOS->EmitBytes("/"); 65194c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby } 6529e999adb48beb61663f6abca667b8c85068ee585Manman Ren const SmallVectorImpl<MCDwarfFile *> &MCDwarfFiles = 65394c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCOS->getContext().getMCDwarfFiles(); 65468ca56285f9b6e82eb16ff8ea02a301f2c489faeEric Christopher MCOS->EmitBytes(MCDwarfFiles[1]->getName()); 65594c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCOS->EmitIntValue(0, 1); // NULL byte to terminate the string. 65694c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 65794c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // AT_comp_dir, the working directory the assembly was done in. 65868ca56285f9b6e82eb16ff8ea02a301f2c489faeEric Christopher MCOS->EmitBytes(context.getCompilationDir()); 65994c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCOS->EmitIntValue(0, 1); // NULL byte to terminate the string. 66094c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 66194c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // AT_APPLE_flags, the command line arguments of the assembler tool. 66294c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby StringRef DwarfDebugFlags = context.getDwarfDebugFlags(); 66394c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby if (!DwarfDebugFlags.empty()){ 66468ca56285f9b6e82eb16ff8ea02a301f2c489faeEric Christopher MCOS->EmitBytes(DwarfDebugFlags); 66594c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCOS->EmitIntValue(0, 1); // NULL byte to terminate the string. 66694c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby } 66794c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 66894c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // AT_producer, the version of the assembler tool. 66975c9b9384f50e9387f24dd7ce6af403cbda6d19aKevin Enderby StringRef DwarfDebugProducer = context.getDwarfDebugProducer(); 67075c9b9384f50e9387f24dd7ce6af403cbda6d19aKevin Enderby if (!DwarfDebugProducer.empty()){ 67175c9b9384f50e9387f24dd7ce6af403cbda6d19aKevin Enderby MCOS->EmitBytes(DwarfDebugProducer); 67275c9b9384f50e9387f24dd7ce6af403cbda6d19aKevin Enderby } 67375c9b9384f50e9387f24dd7ce6af403cbda6d19aKevin Enderby else { 67475c9b9384f50e9387f24dd7ce6af403cbda6d19aKevin Enderby MCOS->EmitBytes(StringRef("llvm-mc (based on LLVM ")); 67575c9b9384f50e9387f24dd7ce6af403cbda6d19aKevin Enderby MCOS->EmitBytes(StringRef(PACKAGE_VERSION)); 67675c9b9384f50e9387f24dd7ce6af403cbda6d19aKevin Enderby MCOS->EmitBytes(StringRef(")")); 67775c9b9384f50e9387f24dd7ce6af403cbda6d19aKevin Enderby } 67894c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCOS->EmitIntValue(0, 1); // NULL byte to terminate the string. 67994c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 68094c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // AT_language, a 4 byte value. We use DW_LANG_Mips_Assembler as the dwarf2 68194c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // draft has no standard code for assembler. 68294c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCOS->EmitIntValue(dwarf::DW_LANG_Mips_Assembler, 2); 68394c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 68438fdb7d9fc40e9f29c3156b6625cac8d91d562e1Kevin Enderby // Third part: the list of label DIEs. 68594c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 68611c2defa9157bd589cb322218c718c4492ed5746Kevin Enderby // Loop on saved info for dwarf labels and create the DIEs for them. 68711c2defa9157bd589cb322218c718c4492ed5746Kevin Enderby const std::vector<const MCGenDwarfLabelEntry *> &Entries = 68811c2defa9157bd589cb322218c718c4492ed5746Kevin Enderby MCOS->getContext().getMCGenDwarfLabelEntries(); 68911c2defa9157bd589cb322218c718c4492ed5746Kevin Enderby for (std::vector<const MCGenDwarfLabelEntry *>::const_iterator it = 69094c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby Entries.begin(), ie = Entries.end(); it != ie; 69194c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby ++it) { 69211c2defa9157bd589cb322218c718c4492ed5746Kevin Enderby const MCGenDwarfLabelEntry *Entry = *it; 69394c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 69438fdb7d9fc40e9f29c3156b6625cac8d91d562e1Kevin Enderby // The DW_TAG_label DIE abbrev (2). 69594c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCOS->EmitULEB128IntValue(2); 69694c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 69794c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // AT_name, of the label without any leading underbar. 69868ca56285f9b6e82eb16ff8ea02a301f2c489faeEric Christopher MCOS->EmitBytes(Entry->getName()); 69994c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCOS->EmitIntValue(0, 1); // NULL byte to terminate the string. 70094c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 70194c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // AT_decl_file, index into the file table. 70294c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCOS->EmitIntValue(Entry->getFileNumber(), 4); 70394c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 70494c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // AT_decl_line, source line number. 70594c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCOS->EmitIntValue(Entry->getLineNumber(), 4); 70694c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 70794c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // AT_low_pc, start address of the label. 70894c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby const MCExpr *AT_low_pc = MCSymbolRefExpr::Create(Entry->getLabel(), 70994c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCSymbolRefExpr::VK_None, context); 71094c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCOS->EmitAbsValue(AT_low_pc, AddrSize); 71194c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 71294c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // DW_AT_prototyped, a one byte flag value of 0 saying we have no prototype. 71394c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCOS->EmitIntValue(0, 1); 71494c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 71594c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // The DW_TAG_unspecified_parameters DIE abbrev (3). 71694c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCOS->EmitULEB128IntValue(3); 71794c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 71894c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // Add the NULL DIE terminating the DW_TAG_unspecified_parameters DIE's. 71994c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCOS->EmitIntValue(0, 1); 72094c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby } 72111c2defa9157bd589cb322218c718c4492ed5746Kevin Enderby // Deallocate the MCGenDwarfLabelEntry classes that saved away the info 72211c2defa9157bd589cb322218c718c4492ed5746Kevin Enderby // for the dwarf labels. 72311c2defa9157bd589cb322218c718c4492ed5746Kevin Enderby for (std::vector<const MCGenDwarfLabelEntry *>::const_iterator it = 72494c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby Entries.begin(), ie = Entries.end(); it != ie; 72594c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby ++it) { 72611c2defa9157bd589cb322218c718c4492ed5746Kevin Enderby const MCGenDwarfLabelEntry *Entry = *it; 72794c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby delete Entry; 72894c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby } 72994c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 73094c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // Add the NULL DIE terminating the Compile Unit DIE's. 73194c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCOS->EmitIntValue(0, 1); 73294c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 73394c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // Now set the value of the symbol at the end of the info section. 73494c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCOS->EmitLabel(InfoEnd); 73594c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby} 73694c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 73794c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby// 73894c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby// When generating dwarf for assembly source files this emits the Dwarf 73994c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby// sections. 74094c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby// 741489d67927172941bf59b9f4829ab8910814fea24Rafael Espindolavoid MCGenDwarfInfo::Emit(MCStreamer *MCOS, const MCSymbol *LineSectionSymbol) { 74294c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // Create the dwarf sections in this order (.debug_line already created). 74394c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCContext &context = MCOS->getContext(); 744489d67927172941bf59b9f4829ab8910814fea24Rafael Espindola const MCAsmInfo &AsmInfo = context.getAsmInfo(); 74515ab115df57949fa55d92ffdfba491f7d02ed60fAlexey Samsonov bool CreateDwarfSectionSymbols = 74615ab115df57949fa55d92ffdfba491f7d02ed60fAlexey Samsonov AsmInfo.doesDwarfUseRelocationsAcrossSections(); 74715ab115df57949fa55d92ffdfba491f7d02ed60fAlexey Samsonov if (!CreateDwarfSectionSymbols) 74815ab115df57949fa55d92ffdfba491f7d02ed60fAlexey Samsonov LineSectionSymbol = NULL; 74915ab115df57949fa55d92ffdfba491f7d02ed60fAlexey Samsonov MCSymbol *AbbrevSectionSymbol = NULL; 75015ab115df57949fa55d92ffdfba491f7d02ed60fAlexey Samsonov MCSymbol *InfoSectionSymbol = NULL; 75194c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfInfoSection()); 75215ab115df57949fa55d92ffdfba491f7d02ed60fAlexey Samsonov if (CreateDwarfSectionSymbols) { 75315ab115df57949fa55d92ffdfba491f7d02ed60fAlexey Samsonov InfoSectionSymbol = context.CreateTempSymbol(); 75415ab115df57949fa55d92ffdfba491f7d02ed60fAlexey Samsonov MCOS->EmitLabel(InfoSectionSymbol); 75515ab115df57949fa55d92ffdfba491f7d02ed60fAlexey Samsonov } 75694c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfAbbrevSection()); 75715ab115df57949fa55d92ffdfba491f7d02ed60fAlexey Samsonov if (CreateDwarfSectionSymbols) { 758489d67927172941bf59b9f4829ab8910814fea24Rafael Espindola AbbrevSectionSymbol = context.CreateTempSymbol(); 759489d67927172941bf59b9f4829ab8910814fea24Rafael Espindola MCOS->EmitLabel(AbbrevSectionSymbol); 760489d67927172941bf59b9f4829ab8910814fea24Rafael Espindola } 76194c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfARangesSection()); 76294c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 76394c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // If there are no line table entries then do not emit any section contents. 76494c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby if (context.getMCLineSections().empty()) 76594c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby return; 76694c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 76794c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // Output the data for .debug_aranges section. 76815ab115df57949fa55d92ffdfba491f7d02ed60fAlexey Samsonov EmitGenDwarfAranges(MCOS, InfoSectionSymbol); 76994c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 77094c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // Output the data for .debug_abbrev section. 77194c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby EmitGenDwarfAbbrev(MCOS); 77294c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 77394c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // Output the data for .debug_info section. 774489d67927172941bf59b9f4829ab8910814fea24Rafael Espindola EmitGenDwarfInfo(MCOS, AbbrevSectionSymbol, LineSectionSymbol); 77594c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby} 77694c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 77794c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby// 77894c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby// When generating dwarf for assembly source files this is called when symbol 77994c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby// for a label is created. If this symbol is not a temporary and is in the 78094c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby// section that dwarf is being generated for, save the needed info to create 78111c2defa9157bd589cb322218c718c4492ed5746Kevin Enderby// a dwarf label. 78294c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby// 78311c2defa9157bd589cb322218c718c4492ed5746Kevin Enderbyvoid MCGenDwarfLabelEntry::Make(MCSymbol *Symbol, MCStreamer *MCOS, 78494c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby SourceMgr &SrcMgr, SMLoc &Loc) { 7853c3cdcc270515de95a4982db3073b9fdf44a5c2eEric Christopher // We won't create dwarf labels for temporary symbols or symbols not in 78694c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // the default text. 78794c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby if (Symbol->isTemporary()) 78894c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby return; 78994c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCContext &context = MCOS->getContext(); 79094c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby if (context.getGenDwarfSection() != MCOS->getCurrentSection()) 79194c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby return; 79294c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 79311c2defa9157bd589cb322218c718c4492ed5746Kevin Enderby // The dwarf label's name does not have the symbol name's leading 79494c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // underbar if any. 79594c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby StringRef Name = Symbol->getName(); 79694c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby if (Name.startswith("_")) 79794c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby Name = Name.substr(1, Name.size()-1); 79894c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 79911c2defa9157bd589cb322218c718c4492ed5746Kevin Enderby // Get the dwarf file number to be used for the dwarf label. 80094c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby unsigned FileNumber = context.getGenDwarfFileNumber(); 80194c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 80294c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // Finding the line number is the expensive part which is why we just don't 80311c2defa9157bd589cb322218c718c4492ed5746Kevin Enderby // pass it in as for some symbols we won't create a dwarf label. 80494c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby int CurBuffer = SrcMgr.FindBufferContainingLoc(Loc); 80594c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby unsigned LineNumber = SrcMgr.FindLineNumber(Loc, CurBuffer); 80694c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 80794c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // We create a temporary symbol for use for the AT_high_pc and AT_low_pc 80894c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // values so that they don't have things like an ARM thumb bit from the 80994c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // original symbol. So when used they won't get a low bit set after 81094c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // relocation. 81194c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCSymbol *Label = context.CreateTempSymbol(); 81294c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby MCOS->EmitLabel(Label); 81394c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 81494c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby // Create and entry for the info and add it to the other entries. 8152684d9e3c702b2ef9fd430155d94671d12fa994fJim Grosbach MCGenDwarfLabelEntry *Entry = 81611c2defa9157bd589cb322218c718c4492ed5746Kevin Enderby new MCGenDwarfLabelEntry(Name, FileNumber, LineNumber, Label); 81711c2defa9157bd589cb322218c718c4492ed5746Kevin Enderby MCOS->getContext().addMCGenDwarfLabelEntry(Entry); 81894c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby} 81994c2e85bea1ab1b837a4c055ccc83d5cd32dd027Kevin Enderby 82089b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindolastatic int getDataAlignmentFactor(MCStreamer &streamer) { 82189b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola MCContext &context = streamer.getContext(); 8221be0e271a07925b928ba89848934f1ea6f1854e2Evan Cheng const MCAsmInfo &asmInfo = context.getAsmInfo(); 8239dd2a3b1f2c253e20262535bb89b1ab6cc680eceEli Bendersky int size = asmInfo.getCalleeSaveStackSlotSize(); 8241be0e271a07925b928ba89848934f1ea6f1854e2Evan Cheng if (asmInfo.isStackGrowthDirectionUp()) 82589b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola return size; 8261be0e271a07925b928ba89848934f1ea6f1854e2Evan Cheng else 8271be0e271a07925b928ba89848934f1ea6f1854e2Evan Cheng return -size; 82889b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola} 82989b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola 830abf9af60add19a0f037bb2a05433769bfd1e7f6fRafael Espindolastatic unsigned getSizeForEncoding(MCStreamer &streamer, 831abf9af60add19a0f037bb2a05433769bfd1e7f6fRafael Espindola unsigned symbolEncoding) { 83225f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindola MCContext &context = streamer.getContext(); 83325f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindola unsigned format = symbolEncoding & 0x0f; 83425f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindola switch (format) { 835858143816d43e58b17bfd11cb1b57afbd7f0f893Craig Topper default: llvm_unreachable("Unknown Encoding"); 83625f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindola case dwarf::DW_EH_PE_absptr: 83725f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindola case dwarf::DW_EH_PE_signed: 8381be0e271a07925b928ba89848934f1ea6f1854e2Evan Cheng return context.getAsmInfo().getPointerSize(); 83925f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindola case dwarf::DW_EH_PE_udata2: 84025f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindola case dwarf::DW_EH_PE_sdata2: 841abf9af60add19a0f037bb2a05433769bfd1e7f6fRafael Espindola return 2; 84225f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindola case dwarf::DW_EH_PE_udata4: 84325f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindola case dwarf::DW_EH_PE_sdata4: 844abf9af60add19a0f037bb2a05433769bfd1e7f6fRafael Espindola return 4; 84525f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindola case dwarf::DW_EH_PE_udata8: 84625f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindola case dwarf::DW_EH_PE_sdata8: 847abf9af60add19a0f037bb2a05433769bfd1e7f6fRafael Espindola return 8; 84825f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindola } 849abf9af60add19a0f037bb2a05433769bfd1e7f6fRafael Espindola} 850abf9af60add19a0f037bb2a05433769bfd1e7f6fRafael Espindola 851abf9af60add19a0f037bb2a05433769bfd1e7f6fRafael Espindolastatic void EmitSymbol(MCStreamer &streamer, const MCSymbol &symbol, 8522541c41f3e2af94585e14353a91f02facd65e415Bill Wendling unsigned symbolEncoding, const char *comment = 0) { 853a0057ca13f06b8de08483c3e3a143a7236c67097Rafael Espindola MCContext &context = streamer.getContext(); 854a0057ca13f06b8de08483c3e3a143a7236c67097Rafael Espindola const MCAsmInfo &asmInfo = context.getAsmInfo(); 855a0057ca13f06b8de08483c3e3a143a7236c67097Rafael Espindola const MCExpr *v = asmInfo.getExprForFDESymbol(&symbol, 856debd7e4e8bc5cfe61bfb71835ce2b1a3fbccc2beRafael Espindola symbolEncoding, 857a0057ca13f06b8de08483c3e3a143a7236c67097Rafael Espindola streamer); 858abf9af60add19a0f037bb2a05433769bfd1e7f6fRafael Espindola unsigned size = getSizeForEncoding(streamer, symbolEncoding); 8592541c41f3e2af94585e14353a91f02facd65e415Bill Wendling if (streamer.isVerboseAsm() && comment) streamer.AddComment(comment); 860debd7e4e8bc5cfe61bfb71835ce2b1a3fbccc2beRafael Espindola streamer.EmitAbsValue(v, size); 86125f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindola} 86225f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindola 863bfa27cc5d72e061a96efbb461864d40bc8089ec2Rafael Espindolastatic void EmitPersonality(MCStreamer &streamer, const MCSymbol &symbol, 864bfa27cc5d72e061a96efbb461864d40bc8089ec2Rafael Espindola unsigned symbolEncoding) { 865bfa27cc5d72e061a96efbb461864d40bc8089ec2Rafael Espindola MCContext &context = streamer.getContext(); 866bfa27cc5d72e061a96efbb461864d40bc8089ec2Rafael Espindola const MCAsmInfo &asmInfo = context.getAsmInfo(); 867debd7e4e8bc5cfe61bfb71835ce2b1a3fbccc2beRafael Espindola const MCExpr *v = asmInfo.getExprForPersonalitySymbol(&symbol, 868debd7e4e8bc5cfe61bfb71835ce2b1a3fbccc2beRafael Espindola symbolEncoding, 869debd7e4e8bc5cfe61bfb71835ce2b1a3fbccc2beRafael Espindola streamer); 870bfa27cc5d72e061a96efbb461864d40bc8089ec2Rafael Espindola unsigned size = getSizeForEncoding(streamer, symbolEncoding); 871debd7e4e8bc5cfe61bfb71835ce2b1a3fbccc2beRafael Espindola streamer.EmitValue(v, size); 872bfa27cc5d72e061a96efbb461864d40bc8089ec2Rafael Espindola} 873bfa27cc5d72e061a96efbb461864d40bc8089ec2Rafael Espindola 87425f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindolastatic const MachineLocation TranslateMachineLocation( 8750e6a052331f674dd70e28af41f654a7874405eabEvan Cheng const MCRegisterInfo &MRI, 87625f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindola const MachineLocation &Loc) { 87725f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindola unsigned Reg = Loc.getReg() == MachineLocation::VirtualFP ? 87825f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindola MachineLocation::VirtualFP : 8790e6a052331f674dd70e28af41f654a7874405eabEvan Cheng unsigned(MRI.getDwarfRegNum(Loc.getReg(), true)); 88025f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindola const MachineLocation &NewLoc = Loc.isReg() ? 88125f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindola MachineLocation(Reg) : MachineLocation(Reg, Loc.getOffset()); 88225f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindola return NewLoc; 88325f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindola} 88425f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindola 88525f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindolanamespace { 88625f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindola class FrameEmitterImpl { 88725f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindola int CFAOffset; 888514cecc72b23bb75108844285ab8f3616a08bac5Rafael Espindola int CIENum; 8895426a9ee37667660935d80841c5392d78e254318Rafael Espindola bool UsingCFI; 89040a7dbbeff44c4cbd8c7e4f07f28dd614f8a5d08Rafael Espindola bool IsEH; 891e3a0e987f3d4f07512cdb64b9034369f966cb448Rafael Espindola const MCSymbol *SectionStart; 89225f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindola public: 8931424c3c3e696868775ac5bfc57d27a0ac3bc6c63Bill Wendling FrameEmitterImpl(bool usingCFI, bool isEH) 8941424c3c3e696868775ac5bfc57d27a0ac3bc6c63Bill Wendling : CFAOffset(0), CIENum(0), UsingCFI(usingCFI), IsEH(isEH), 8951424c3c3e696868775ac5bfc57d27a0ac3bc6c63Bill Wendling SectionStart(0) {} 8961424c3c3e696868775ac5bfc57d27a0ac3bc6c63Bill Wendling 8971424c3c3e696868775ac5bfc57d27a0ac3bc6c63Bill Wendling void setSectionStart(const MCSymbol *Label) { SectionStart = Label; } 89825f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindola 899e3cd13f0e2d4e2ef30f8a57c0a82d328102eeb26Bill Wendling /// EmitCompactUnwind - Emit the unwind information in a compact way. If 900e3cd13f0e2d4e2ef30f8a57c0a82d328102eeb26Bill Wendling /// we're successful, return 'true'. Otherwise, return 'false' and it will 901e3cd13f0e2d4e2ef30f8a57c0a82d328102eeb26Bill Wendling /// emit the normal CIE and FDE. 902e3cd13f0e2d4e2ef30f8a57c0a82d328102eeb26Bill Wendling bool EmitCompactUnwind(MCStreamer &streamer, 903e3cd13f0e2d4e2ef30f8a57c0a82d328102eeb26Bill Wendling const MCDwarfFrameInfo &frame); 904e3cd13f0e2d4e2ef30f8a57c0a82d328102eeb26Bill Wendling 90525f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindola const MCSymbol &EmitCIE(MCStreamer &streamer, 90625f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindola const MCSymbol *personality, 90725f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindola unsigned personalityEncoding, 90825f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindola const MCSymbol *lsda, 90916d7d437e03ce87fdaef7971919302920d54a966Rafael Espindola bool IsSignalFrame, 91025f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindola unsigned lsdaEncoding); 91125f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindola MCSymbol *EmitFDE(MCStreamer &streamer, 91225f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindola const MCSymbol &cieStart, 9139f270dadd429771dded5a8572da8c74513771c15Rafael Espindola const MCDwarfFrameInfo &frame); 91425f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindola void EmitCFIInstructions(MCStreamer &streamer, 91525f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindola const std::vector<MCCFIInstruction> &Instrs, 91625f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindola MCSymbol *BaseLabel); 91725f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindola void EmitCFIInstruction(MCStreamer &Streamer, 91825f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindola const MCCFIInstruction &Instr); 91925f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindola }; 9203c163cfa60f9f196cd6a5a04e07baec3947fee0bBill Wendling 9213c163cfa60f9f196cd6a5a04e07baec3947fee0bBill Wendling} // end anonymous namespace 9223c163cfa60f9f196cd6a5a04e07baec3947fee0bBill Wendling 9233c163cfa60f9f196cd6a5a04e07baec3947fee0bBill Wendlingstatic void EmitEncodingByte(MCStreamer &Streamer, unsigned Encoding, 9243c163cfa60f9f196cd6a5a04e07baec3947fee0bBill Wendling StringRef Prefix) { 9253c163cfa60f9f196cd6a5a04e07baec3947fee0bBill Wendling if (Streamer.isVerboseAsm()) { 926eb9fa666f9ea27334aa728d7b6b435b5c20a2c4cBenjamin Kramer const char *EncStr; 9273c163cfa60f9f196cd6a5a04e07baec3947fee0bBill Wendling switch (Encoding) { 928eb9fa666f9ea27334aa728d7b6b435b5c20a2c4cBenjamin Kramer default: EncStr = "<unknown encoding>"; break; 929eb9fa666f9ea27334aa728d7b6b435b5c20a2c4cBenjamin Kramer case dwarf::DW_EH_PE_absptr: EncStr = "absptr"; break; 930eb9fa666f9ea27334aa728d7b6b435b5c20a2c4cBenjamin Kramer case dwarf::DW_EH_PE_omit: EncStr = "omit"; break; 931eb9fa666f9ea27334aa728d7b6b435b5c20a2c4cBenjamin Kramer case dwarf::DW_EH_PE_pcrel: EncStr = "pcrel"; break; 932eb9fa666f9ea27334aa728d7b6b435b5c20a2c4cBenjamin Kramer case dwarf::DW_EH_PE_udata4: EncStr = "udata4"; break; 933eb9fa666f9ea27334aa728d7b6b435b5c20a2c4cBenjamin Kramer case dwarf::DW_EH_PE_udata8: EncStr = "udata8"; break; 934eb9fa666f9ea27334aa728d7b6b435b5c20a2c4cBenjamin Kramer case dwarf::DW_EH_PE_sdata4: EncStr = "sdata4"; break; 935eb9fa666f9ea27334aa728d7b6b435b5c20a2c4cBenjamin Kramer case dwarf::DW_EH_PE_sdata8: EncStr = "sdata8"; break; 936eb9fa666f9ea27334aa728d7b6b435b5c20a2c4cBenjamin Kramer case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata4: 937eb9fa666f9ea27334aa728d7b6b435b5c20a2c4cBenjamin Kramer EncStr = "pcrel udata4"; 938eb9fa666f9ea27334aa728d7b6b435b5c20a2c4cBenjamin Kramer break; 939eb9fa666f9ea27334aa728d7b6b435b5c20a2c4cBenjamin Kramer case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4: 940eb9fa666f9ea27334aa728d7b6b435b5c20a2c4cBenjamin Kramer EncStr = "pcrel sdata4"; 941eb9fa666f9ea27334aa728d7b6b435b5c20a2c4cBenjamin Kramer break; 942eb9fa666f9ea27334aa728d7b6b435b5c20a2c4cBenjamin Kramer case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8: 943eb9fa666f9ea27334aa728d7b6b435b5c20a2c4cBenjamin Kramer EncStr = "pcrel udata8"; 944eb9fa666f9ea27334aa728d7b6b435b5c20a2c4cBenjamin Kramer break; 945eb9fa666f9ea27334aa728d7b6b435b5c20a2c4cBenjamin Kramer case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8: 946eb9fa666f9ea27334aa728d7b6b435b5c20a2c4cBenjamin Kramer EncStr = "screl sdata8"; 947eb9fa666f9ea27334aa728d7b6b435b5c20a2c4cBenjamin Kramer break; 9483c163cfa60f9f196cd6a5a04e07baec3947fee0bBill Wendling case dwarf::DW_EH_PE_indirect |dwarf::DW_EH_PE_pcrel|dwarf::DW_EH_PE_udata4: 9493c163cfa60f9f196cd6a5a04e07baec3947fee0bBill Wendling EncStr = "indirect pcrel udata4"; 950eb9fa666f9ea27334aa728d7b6b435b5c20a2c4cBenjamin Kramer break; 9513c163cfa60f9f196cd6a5a04e07baec3947fee0bBill Wendling case dwarf::DW_EH_PE_indirect |dwarf::DW_EH_PE_pcrel|dwarf::DW_EH_PE_sdata4: 9523c163cfa60f9f196cd6a5a04e07baec3947fee0bBill Wendling EncStr = "indirect pcrel sdata4"; 953eb9fa666f9ea27334aa728d7b6b435b5c20a2c4cBenjamin Kramer break; 9543c163cfa60f9f196cd6a5a04e07baec3947fee0bBill Wendling case dwarf::DW_EH_PE_indirect |dwarf::DW_EH_PE_pcrel|dwarf::DW_EH_PE_udata8: 9553c163cfa60f9f196cd6a5a04e07baec3947fee0bBill Wendling EncStr = "indirect pcrel udata8"; 956eb9fa666f9ea27334aa728d7b6b435b5c20a2c4cBenjamin Kramer break; 9573c163cfa60f9f196cd6a5a04e07baec3947fee0bBill Wendling case dwarf::DW_EH_PE_indirect |dwarf::DW_EH_PE_pcrel|dwarf::DW_EH_PE_sdata8: 9583c163cfa60f9f196cd6a5a04e07baec3947fee0bBill Wendling EncStr = "indirect pcrel sdata8"; 959eb9fa666f9ea27334aa728d7b6b435b5c20a2c4cBenjamin Kramer break; 9603c163cfa60f9f196cd6a5a04e07baec3947fee0bBill Wendling } 9613c163cfa60f9f196cd6a5a04e07baec3947fee0bBill Wendling 9623c163cfa60f9f196cd6a5a04e07baec3947fee0bBill Wendling Streamer.AddComment(Twine(Prefix) + " = " + EncStr); 9633c163cfa60f9f196cd6a5a04e07baec3947fee0bBill Wendling } 9643c163cfa60f9f196cd6a5a04e07baec3947fee0bBill Wendling 9653c163cfa60f9f196cd6a5a04e07baec3947fee0bBill Wendling Streamer.EmitIntValue(Encoding, 1); 96625f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindola} 96725f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindola 96825f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindolavoid FrameEmitterImpl::EmitCFIInstruction(MCStreamer &Streamer, 96925f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindola const MCCFIInstruction &Instr) { 970fe024d0a624404ada11fb330e7360abc5f88742eRafael Espindola int dataAlignmentFactor = getDataAlignmentFactor(Streamer); 971efd24ddbffc1e69fa88089de036d1873c950dfb5Bill Wendling bool VerboseAsm = Streamer.isVerboseAsm(); 97289b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola 973fe024d0a624404ada11fb330e7360abc5f88742eRafael Espindola switch (Instr.getOperation()) { 974f4f14f68f6078ea6681ee27b5bf42719d7db3441Rafael Espindola case MCCFIInstruction::OpRegister: { 975f4f14f68f6078ea6681ee27b5bf42719d7db3441Rafael Espindola unsigned Reg1 = Instr.getRegister(); 976f4f14f68f6078ea6681ee27b5bf42719d7db3441Rafael Espindola unsigned Reg2 = Instr.getRegister2(); 977f4f14f68f6078ea6681ee27b5bf42719d7db3441Rafael Espindola if (VerboseAsm) { 978f4f14f68f6078ea6681ee27b5bf42719d7db3441Rafael Espindola Streamer.AddComment("DW_CFA_register"); 979f4f14f68f6078ea6681ee27b5bf42719d7db3441Rafael Espindola Streamer.AddComment(Twine("Reg1 ") + Twine(Reg1)); 980f4f14f68f6078ea6681ee27b5bf42719d7db3441Rafael Espindola Streamer.AddComment(Twine("Reg2 ") + Twine(Reg2)); 981f4f14f68f6078ea6681ee27b5bf42719d7db3441Rafael Espindola } 982f4f14f68f6078ea6681ee27b5bf42719d7db3441Rafael Espindola Streamer.EmitIntValue(dwarf::DW_CFA_register, 1); 983f4f14f68f6078ea6681ee27b5bf42719d7db3441Rafael Espindola Streamer.EmitULEB128IntValue(Reg1); 984f4f14f68f6078ea6681ee27b5bf42719d7db3441Rafael Espindola Streamer.EmitULEB128IntValue(Reg2); 985f4f14f68f6078ea6681ee27b5bf42719d7db3441Rafael Espindola return; 986f4f14f68f6078ea6681ee27b5bf42719d7db3441Rafael Espindola } 9877f74d2c2c197eec76ae2b41fed9c227c0dcc04cbRafael Espindola case MCCFIInstruction::OpUndefined: { 988ff233c9e5c3e439fd1eed84b9a9e88a5370572dbRafael Espindola unsigned Reg = Instr.getRegister(); 989c8fec7e21f5c24303eab8a8592f3b8faff347d86Rafael Espindola if (VerboseAsm) { 990c8fec7e21f5c24303eab8a8592f3b8faff347d86Rafael Espindola Streamer.AddComment("DW_CFA_undefined"); 991c8fec7e21f5c24303eab8a8592f3b8faff347d86Rafael Espindola Streamer.AddComment(Twine("Reg ") + Twine(Reg)); 992c8fec7e21f5c24303eab8a8592f3b8faff347d86Rafael Espindola } 993c8fec7e21f5c24303eab8a8592f3b8faff347d86Rafael Espindola Streamer.EmitIntValue(dwarf::DW_CFA_undefined, 1); 994c8fec7e21f5c24303eab8a8592f3b8faff347d86Rafael Espindola Streamer.EmitULEB128IntValue(Reg); 995c8fec7e21f5c24303eab8a8592f3b8faff347d86Rafael Espindola return; 996c8fec7e21f5c24303eab8a8592f3b8faff347d86Rafael Espindola } 9977f74d2c2c197eec76ae2b41fed9c227c0dcc04cbRafael Espindola case MCCFIInstruction::OpAdjustCfaOffset: 9987f74d2c2c197eec76ae2b41fed9c227c0dcc04cbRafael Espindola case MCCFIInstruction::OpDefCfaOffset: { 9997f74d2c2c197eec76ae2b41fed9c227c0dcc04cbRafael Espindola const bool IsRelative = 10007f74d2c2c197eec76ae2b41fed9c227c0dcc04cbRafael Espindola Instr.getOperation() == MCCFIInstruction::OpAdjustCfaOffset; 100189b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola 10027f74d2c2c197eec76ae2b41fed9c227c0dcc04cbRafael Espindola if (VerboseAsm) 10037f74d2c2c197eec76ae2b41fed9c227c0dcc04cbRafael Espindola Streamer.AddComment("DW_CFA_def_cfa_offset"); 10047f74d2c2c197eec76ae2b41fed9c227c0dcc04cbRafael Espindola Streamer.EmitIntValue(dwarf::DW_CFA_def_cfa_offset, 1); 10055d7dcd3335234d2a2bc16dc69f86fbb5dcaa8962Rafael Espindola 10067f74d2c2c197eec76ae2b41fed9c227c0dcc04cbRafael Espindola if (IsRelative) 1007ff233c9e5c3e439fd1eed84b9a9e88a5370572dbRafael Espindola CFAOffset += Instr.getOffset(); 10087f74d2c2c197eec76ae2b41fed9c227c0dcc04cbRafael Espindola else 1009ff233c9e5c3e439fd1eed84b9a9e88a5370572dbRafael Espindola CFAOffset = -Instr.getOffset(); 101089b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola 10117f74d2c2c197eec76ae2b41fed9c227c0dcc04cbRafael Espindola if (VerboseAsm) 10127f74d2c2c197eec76ae2b41fed9c227c0dcc04cbRafael Espindola Streamer.AddComment(Twine("Offset " + Twine(CFAOffset))); 10137f74d2c2c197eec76ae2b41fed9c227c0dcc04cbRafael Espindola Streamer.EmitULEB128IntValue(CFAOffset); 10147f74d2c2c197eec76ae2b41fed9c227c0dcc04cbRafael Espindola 10157f74d2c2c197eec76ae2b41fed9c227c0dcc04cbRafael Espindola return; 10167f74d2c2c197eec76ae2b41fed9c227c0dcc04cbRafael Espindola } 10177f74d2c2c197eec76ae2b41fed9c227c0dcc04cbRafael Espindola case MCCFIInstruction::OpDefCfa: { 10187f74d2c2c197eec76ae2b41fed9c227c0dcc04cbRafael Espindola if (VerboseAsm) 10197f74d2c2c197eec76ae2b41fed9c227c0dcc04cbRafael Espindola Streamer.AddComment("DW_CFA_def_cfa"); 10207f74d2c2c197eec76ae2b41fed9c227c0dcc04cbRafael Espindola Streamer.EmitIntValue(dwarf::DW_CFA_def_cfa, 1); 10217f74d2c2c197eec76ae2b41fed9c227c0dcc04cbRafael Espindola 10227f74d2c2c197eec76ae2b41fed9c227c0dcc04cbRafael Espindola if (VerboseAsm) 1023ff233c9e5c3e439fd1eed84b9a9e88a5370572dbRafael Espindola Streamer.AddComment(Twine("Reg ") + Twine(Instr.getRegister())); 1024ff233c9e5c3e439fd1eed84b9a9e88a5370572dbRafael Espindola Streamer.EmitULEB128IntValue(Instr.getRegister()); 10257f74d2c2c197eec76ae2b41fed9c227c0dcc04cbRafael Espindola 1026ff233c9e5c3e439fd1eed84b9a9e88a5370572dbRafael Espindola CFAOffset = -Instr.getOffset(); 10277f74d2c2c197eec76ae2b41fed9c227c0dcc04cbRafael Espindola 10287f74d2c2c197eec76ae2b41fed9c227c0dcc04cbRafael Espindola if (VerboseAsm) 10297f74d2c2c197eec76ae2b41fed9c227c0dcc04cbRafael Espindola Streamer.AddComment(Twine("Offset " + Twine(CFAOffset))); 10307f74d2c2c197eec76ae2b41fed9c227c0dcc04cbRafael Espindola Streamer.EmitULEB128IntValue(CFAOffset); 10317f74d2c2c197eec76ae2b41fed9c227c0dcc04cbRafael Espindola 10327f74d2c2c197eec76ae2b41fed9c227c0dcc04cbRafael Espindola return; 10337f74d2c2c197eec76ae2b41fed9c227c0dcc04cbRafael Espindola } 10347f74d2c2c197eec76ae2b41fed9c227c0dcc04cbRafael Espindola 10357f74d2c2c197eec76ae2b41fed9c227c0dcc04cbRafael Espindola case MCCFIInstruction::OpDefCfaRegister: { 10367f74d2c2c197eec76ae2b41fed9c227c0dcc04cbRafael Espindola if (VerboseAsm) 10377f74d2c2c197eec76ae2b41fed9c227c0dcc04cbRafael Espindola Streamer.AddComment("DW_CFA_def_cfa_register"); 10387f74d2c2c197eec76ae2b41fed9c227c0dcc04cbRafael Espindola Streamer.EmitIntValue(dwarf::DW_CFA_def_cfa_register, 1); 10397f74d2c2c197eec76ae2b41fed9c227c0dcc04cbRafael Espindola 10407f74d2c2c197eec76ae2b41fed9c227c0dcc04cbRafael Espindola if (VerboseAsm) 1041ff233c9e5c3e439fd1eed84b9a9e88a5370572dbRafael Espindola Streamer.AddComment(Twine("Reg ") + Twine(Instr.getRegister())); 1042ff233c9e5c3e439fd1eed84b9a9e88a5370572dbRafael Espindola Streamer.EmitULEB128IntValue(Instr.getRegister()); 10437f74d2c2c197eec76ae2b41fed9c227c0dcc04cbRafael Espindola 10447f74d2c2c197eec76ae2b41fed9c227c0dcc04cbRafael Espindola return; 10457f74d2c2c197eec76ae2b41fed9c227c0dcc04cbRafael Espindola } 10467f74d2c2c197eec76ae2b41fed9c227c0dcc04cbRafael Espindola 10477f74d2c2c197eec76ae2b41fed9c227c0dcc04cbRafael Espindola case MCCFIInstruction::OpOffset: 10487f74d2c2c197eec76ae2b41fed9c227c0dcc04cbRafael Espindola case MCCFIInstruction::OpRelOffset: { 10497f74d2c2c197eec76ae2b41fed9c227c0dcc04cbRafael Espindola const bool IsRelative = 10507f74d2c2c197eec76ae2b41fed9c227c0dcc04cbRafael Espindola Instr.getOperation() == MCCFIInstruction::OpRelOffset; 105189b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola 1052ff233c9e5c3e439fd1eed84b9a9e88a5370572dbRafael Espindola unsigned Reg = Instr.getRegister(); 1053ff233c9e5c3e439fd1eed84b9a9e88a5370572dbRafael Espindola int Offset = Instr.getOffset(); 105425f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindola if (IsRelative) 105525f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindola Offset -= CFAOffset; 105625f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindola Offset = Offset / dataAlignmentFactor; 105789b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola 105889b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola if (Offset < 0) { 1059efd24ddbffc1e69fa88089de036d1873c950dfb5Bill Wendling if (VerboseAsm) Streamer.AddComment("DW_CFA_offset_extended_sf"); 1060fe024d0a624404ada11fb330e7360abc5f88742eRafael Espindola Streamer.EmitIntValue(dwarf::DW_CFA_offset_extended_sf, 1); 1061efd24ddbffc1e69fa88089de036d1873c950dfb5Bill Wendling if (VerboseAsm) Streamer.AddComment(Twine("Reg ") + Twine(Reg)); 1062fe024d0a624404ada11fb330e7360abc5f88742eRafael Espindola Streamer.EmitULEB128IntValue(Reg); 1063efd24ddbffc1e69fa88089de036d1873c950dfb5Bill Wendling if (VerboseAsm) Streamer.AddComment(Twine("Offset ") + Twine(Offset)); 1064fe024d0a624404ada11fb330e7360abc5f88742eRafael Espindola Streamer.EmitSLEB128IntValue(Offset); 106589b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola } else if (Reg < 64) { 1066e08d4335ad29d74008222b4d7ac91c153ed66becBill Wendling if (VerboseAsm) Streamer.AddComment(Twine("DW_CFA_offset + Reg(") + 1067e08d4335ad29d74008222b4d7ac91c153ed66becBill Wendling Twine(Reg) + ")"); 1068fe024d0a624404ada11fb330e7360abc5f88742eRafael Espindola Streamer.EmitIntValue(dwarf::DW_CFA_offset + Reg, 1); 1069efd24ddbffc1e69fa88089de036d1873c950dfb5Bill Wendling if (VerboseAsm) Streamer.AddComment(Twine("Offset ") + Twine(Offset)); 1070eccbad78e0854743e358841b64f9e0f5eba82861Rafael Espindola Streamer.EmitULEB128IntValue(Offset); 107189b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola } else { 1072efd24ddbffc1e69fa88089de036d1873c950dfb5Bill Wendling if (VerboseAsm) Streamer.AddComment("DW_CFA_offset_extended"); 1073fe024d0a624404ada11fb330e7360abc5f88742eRafael Espindola Streamer.EmitIntValue(dwarf::DW_CFA_offset_extended, 1); 1074efd24ddbffc1e69fa88089de036d1873c950dfb5Bill Wendling if (VerboseAsm) Streamer.AddComment(Twine("Reg ") + Twine(Reg)); 1075eccbad78e0854743e358841b64f9e0f5eba82861Rafael Espindola Streamer.EmitULEB128IntValue(Reg); 1076efd24ddbffc1e69fa88089de036d1873c950dfb5Bill Wendling if (VerboseAsm) Streamer.AddComment(Twine("Offset ") + Twine(Offset)); 1077eccbad78e0854743e358841b64f9e0f5eba82861Rafael Espindola Streamer.EmitULEB128IntValue(Offset); 1078fe024d0a624404ada11fb330e7360abc5f88742eRafael Espindola } 1079fe024d0a624404ada11fb330e7360abc5f88742eRafael Espindola return; 1080fe024d0a624404ada11fb330e7360abc5f88742eRafael Espindola } 10817f74d2c2c197eec76ae2b41fed9c227c0dcc04cbRafael Espindola case MCCFIInstruction::OpRememberState: 1082efd24ddbffc1e69fa88089de036d1873c950dfb5Bill Wendling if (VerboseAsm) Streamer.AddComment("DW_CFA_remember_state"); 1083fe024d0a624404ada11fb330e7360abc5f88742eRafael Espindola Streamer.EmitIntValue(dwarf::DW_CFA_remember_state, 1); 1084fe024d0a624404ada11fb330e7360abc5f88742eRafael Espindola return; 10857f74d2c2c197eec76ae2b41fed9c227c0dcc04cbRafael Espindola case MCCFIInstruction::OpRestoreState: 1086efd24ddbffc1e69fa88089de036d1873c950dfb5Bill Wendling if (VerboseAsm) Streamer.AddComment("DW_CFA_restore_state"); 1087fe024d0a624404ada11fb330e7360abc5f88742eRafael Espindola Streamer.EmitIntValue(dwarf::DW_CFA_restore_state, 1); 1088fe024d0a624404ada11fb330e7360abc5f88742eRafael Espindola return; 10897f74d2c2c197eec76ae2b41fed9c227c0dcc04cbRafael Espindola case MCCFIInstruction::OpSameValue: { 1090ff233c9e5c3e439fd1eed84b9a9e88a5370572dbRafael Espindola unsigned Reg = Instr.getRegister(); 1091efd24ddbffc1e69fa88089de036d1873c950dfb5Bill Wendling if (VerboseAsm) Streamer.AddComment("DW_CFA_same_value"); 1092c57543964d1382d3d3a5005f415b6c0f49671b3aRafael Espindola Streamer.EmitIntValue(dwarf::DW_CFA_same_value, 1); 1093efd24ddbffc1e69fa88089de036d1873c950dfb5Bill Wendling if (VerboseAsm) Streamer.AddComment(Twine("Reg ") + Twine(Reg)); 1094e8cfbd843d737e1f95c3032c7670c2be3838a6f6Rafael Espindola Streamer.EmitULEB128IntValue(Reg); 1095c57543964d1382d3d3a5005f415b6c0f49671b3aRafael Espindola return; 1096c57543964d1382d3d3a5005f415b6c0f49671b3aRafael Espindola } 10977f74d2c2c197eec76ae2b41fed9c227c0dcc04cbRafael Espindola case MCCFIInstruction::OpRestore: { 1098ff233c9e5c3e439fd1eed84b9a9e88a5370572dbRafael Espindola unsigned Reg = Instr.getRegister(); 1099ed23bdb65fe86cdb7a38c8c1998ec965e6973966Rafael Espindola if (VerboseAsm) { 1100ed23bdb65fe86cdb7a38c8c1998ec965e6973966Rafael Espindola Streamer.AddComment("DW_CFA_restore"); 1101ed23bdb65fe86cdb7a38c8c1998ec965e6973966Rafael Espindola Streamer.AddComment(Twine("Reg ") + Twine(Reg)); 1102ed23bdb65fe86cdb7a38c8c1998ec965e6973966Rafael Espindola } 1103ed23bdb65fe86cdb7a38c8c1998ec965e6973966Rafael Espindola Streamer.EmitIntValue(dwarf::DW_CFA_restore | Reg, 1); 1104ed23bdb65fe86cdb7a38c8c1998ec965e6973966Rafael Espindola return; 1105ed23bdb65fe86cdb7a38c8c1998ec965e6973966Rafael Espindola } 11067f74d2c2c197eec76ae2b41fed9c227c0dcc04cbRafael Espindola case MCCFIInstruction::OpEscape: 11076f0b181bc70318f8d5d4b9bdead7fc748677fe2aRafael Espindola if (VerboseAsm) Streamer.AddComment("Escape bytes"); 110868ca56285f9b6e82eb16ff8ea02a301f2c489faeEric Christopher Streamer.EmitBytes(Instr.getValues()); 11096f0b181bc70318f8d5d4b9bdead7fc748677fe2aRafael Espindola return; 1110fe024d0a624404ada11fb330e7360abc5f88742eRafael Espindola } 1111fe024d0a624404ada11fb330e7360abc5f88742eRafael Espindola llvm_unreachable("Unhandled case in switch"); 1112fe024d0a624404ada11fb330e7360abc5f88742eRafael Espindola} 1113fe024d0a624404ada11fb330e7360abc5f88742eRafael Espindola 1114fe024d0a624404ada11fb330e7360abc5f88742eRafael Espindola/// EmitFrameMoves - Emit frame instructions to describe the layout of the 1115fe024d0a624404ada11fb330e7360abc5f88742eRafael Espindola/// frame. 111625f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindolavoid FrameEmitterImpl::EmitCFIInstructions(MCStreamer &streamer, 111725f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindola const std::vector<MCCFIInstruction> &Instrs, 111825f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindola MCSymbol *BaseLabel) { 1119fe024d0a624404ada11fb330e7360abc5f88742eRafael Espindola for (unsigned i = 0, N = Instrs.size(); i < N; ++i) { 1120fe024d0a624404ada11fb330e7360abc5f88742eRafael Espindola const MCCFIInstruction &Instr = Instrs[i]; 1121fe024d0a624404ada11fb330e7360abc5f88742eRafael Espindola MCSymbol *Label = Instr.getLabel(); 1122fe024d0a624404ada11fb330e7360abc5f88742eRafael Espindola // Throw out move if the label is invalid. 1123fe024d0a624404ada11fb330e7360abc5f88742eRafael Espindola if (Label && !Label->isDefined()) continue; // Not emitted, in dead code. 1124fe024d0a624404ada11fb330e7360abc5f88742eRafael Espindola 1125fe024d0a624404ada11fb330e7360abc5f88742eRafael Espindola // Advance row if new location. 1126fe024d0a624404ada11fb330e7360abc5f88742eRafael Espindola if (BaseLabel && Label) { 1127fe024d0a624404ada11fb330e7360abc5f88742eRafael Espindola MCSymbol *ThisSym = Label; 1128fe024d0a624404ada11fb330e7360abc5f88742eRafael Espindola if (ThisSym != BaseLabel) { 1129d221cd676b44d8118b1db152ecc2168538479626Bill Wendling if (streamer.isVerboseAsm()) streamer.AddComment("DW_CFA_advance_loc4"); 1130fe024d0a624404ada11fb330e7360abc5f88742eRafael Espindola streamer.EmitDwarfAdvanceFrameAddr(BaseLabel, ThisSym); 1131fe024d0a624404ada11fb330e7360abc5f88742eRafael Espindola BaseLabel = ThisSym; 1132fe024d0a624404ada11fb330e7360abc5f88742eRafael Espindola } 113389b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola } 1134fe024d0a624404ada11fb330e7360abc5f88742eRafael Espindola 1135b40a71fda188f8ca564e606ac2cb051a44ada311Rafael Espindola EmitCFIInstruction(streamer, Instr); 113689b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola } 113789b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola} 113889b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola 1139e3cd13f0e2d4e2ef30f8a57c0a82d328102eeb26Bill Wendling/// EmitCompactUnwind - Emit the unwind information in a compact way. If we're 1140e3cd13f0e2d4e2ef30f8a57c0a82d328102eeb26Bill Wendling/// successful, return 'true'. Otherwise, return 'false' and it will emit the 1141e3cd13f0e2d4e2ef30f8a57c0a82d328102eeb26Bill Wendling/// normal CIE and FDE. 1142e3cd13f0e2d4e2ef30f8a57c0a82d328102eeb26Bill Wendlingbool FrameEmitterImpl::EmitCompactUnwind(MCStreamer &Streamer, 1143e3cd13f0e2d4e2ef30f8a57c0a82d328102eeb26Bill Wendling const MCDwarfFrameInfo &Frame) { 1144e3cd13f0e2d4e2ef30f8a57c0a82d328102eeb26Bill Wendling MCContext &Context = Streamer.getContext(); 1145e76a33b9567d78a5744dc52fcec3a6056d6fb576Evan Cheng const MCObjectFileInfo *MOFI = Context.getObjectFileInfo(); 11463c163cfa60f9f196cd6a5a04e07baec3947fee0bBill Wendling bool VerboseAsm = Streamer.isVerboseAsm(); 1147e3cd13f0e2d4e2ef30f8a57c0a82d328102eeb26Bill Wendling 1148e3cd13f0e2d4e2ef30f8a57c0a82d328102eeb26Bill Wendling // range-start range-length compact-unwind-enc personality-func lsda 1149e3cd13f0e2d4e2ef30f8a57c0a82d328102eeb26Bill Wendling // _foo LfooEnd-_foo 0x00000023 0 0 1150e3cd13f0e2d4e2ef30f8a57c0a82d328102eeb26Bill Wendling // _bar LbarEnd-_bar 0x00000025 __gxx_personality except_tab1 1151e3cd13f0e2d4e2ef30f8a57c0a82d328102eeb26Bill Wendling // 1152e3cd13f0e2d4e2ef30f8a57c0a82d328102eeb26Bill Wendling // .section __LD,__compact_unwind,regular,debug 1153e3cd13f0e2d4e2ef30f8a57c0a82d328102eeb26Bill Wendling // 1154e3cd13f0e2d4e2ef30f8a57c0a82d328102eeb26Bill Wendling // # compact unwind for _foo 1155e3cd13f0e2d4e2ef30f8a57c0a82d328102eeb26Bill Wendling // .quad _foo 1156e3cd13f0e2d4e2ef30f8a57c0a82d328102eeb26Bill Wendling // .set L1,LfooEnd-_foo 1157e3cd13f0e2d4e2ef30f8a57c0a82d328102eeb26Bill Wendling // .long L1 1158e3cd13f0e2d4e2ef30f8a57c0a82d328102eeb26Bill Wendling // .long 0x01010001 1159e3cd13f0e2d4e2ef30f8a57c0a82d328102eeb26Bill Wendling // .quad 0 1160e3cd13f0e2d4e2ef30f8a57c0a82d328102eeb26Bill Wendling // .quad 0 1161e3cd13f0e2d4e2ef30f8a57c0a82d328102eeb26Bill Wendling // 1162e3cd13f0e2d4e2ef30f8a57c0a82d328102eeb26Bill Wendling // # compact unwind for _bar 1163e3cd13f0e2d4e2ef30f8a57c0a82d328102eeb26Bill Wendling // .quad _bar 1164e3cd13f0e2d4e2ef30f8a57c0a82d328102eeb26Bill Wendling // .set L2,LbarEnd-_bar 1165e3cd13f0e2d4e2ef30f8a57c0a82d328102eeb26Bill Wendling // .long L2 1166e3cd13f0e2d4e2ef30f8a57c0a82d328102eeb26Bill Wendling // .long 0x01020011 1167e3cd13f0e2d4e2ef30f8a57c0a82d328102eeb26Bill Wendling // .quad __gxx_personality 1168e3cd13f0e2d4e2ef30f8a57c0a82d328102eeb26Bill Wendling // .quad except_tab1 1169e3cd13f0e2d4e2ef30f8a57c0a82d328102eeb26Bill Wendling 1170e52e3f2c020354c8e0e966b719152b08349d0334Bill Wendling uint32_t Encoding = Frame.CompactUnwindEncoding; 11716a6b8c3e96b9e1ca7092eafd0cfb219cbbfbdfc4Bill Wendling if (!Encoding) return false; 11726a6b8c3e96b9e1ca7092eafd0cfb219cbbfbdfc4Bill Wendling 11734bb5b037126ea35f35d5a490b03ccffa8677fa5eBill Wendling // The encoding needs to know we have an LSDA. 11744bb5b037126ea35f35d5a490b03ccffa8677fa5eBill Wendling if (Frame.Lsda) 11754bb5b037126ea35f35d5a490b03ccffa8677fa5eBill Wendling Encoding |= 0x40000000; 11764bb5b037126ea35f35d5a490b03ccffa8677fa5eBill Wendling 1177e76a33b9567d78a5744dc52fcec3a6056d6fb576Evan Cheng Streamer.SwitchSection(MOFI->getCompactUnwindSection()); 11783c163cfa60f9f196cd6a5a04e07baec3947fee0bBill Wendling 1179e3cd13f0e2d4e2ef30f8a57c0a82d328102eeb26Bill Wendling // Range Start 1180203576aa0cb9d8bf2d2e4d910ebab4b7a63262aeEvan Cheng unsigned FDEEncoding = MOFI->getFDEEncoding(UsingCFI); 11819056e9032001a2d47057cecec5e39895cbc31799Bill Wendling unsigned Size = getSizeForEncoding(Streamer, FDEEncoding); 11823c163cfa60f9f196cd6a5a04e07baec3947fee0bBill Wendling if (VerboseAsm) Streamer.AddComment("Range Start"); 11839056e9032001a2d47057cecec5e39895cbc31799Bill Wendling Streamer.EmitSymbolValue(Frame.Function, Size); 1184e3cd13f0e2d4e2ef30f8a57c0a82d328102eeb26Bill Wendling 1185e3cd13f0e2d4e2ef30f8a57c0a82d328102eeb26Bill Wendling // Range Length 1186e3cd13f0e2d4e2ef30f8a57c0a82d328102eeb26Bill Wendling const MCExpr *Range = MakeStartMinusEndExpr(Streamer, *Frame.Begin, 1187e3cd13f0e2d4e2ef30f8a57c0a82d328102eeb26Bill Wendling *Frame.End, 0); 11883c163cfa60f9f196cd6a5a04e07baec3947fee0bBill Wendling if (VerboseAsm) Streamer.AddComment("Range Length"); 11899287a6eef336585628a55e1f33e1e3ea9d7f81cfBill Wendling Streamer.EmitAbsValue(Range, 4); 11909287a6eef336585628a55e1f33e1e3ea9d7f81cfBill Wendling 11919287a6eef336585628a55e1f33e1e3ea9d7f81cfBill Wendling // Compact Encoding 11929287a6eef336585628a55e1f33e1e3ea9d7f81cfBill Wendling Size = getSizeForEncoding(Streamer, dwarf::DW_EH_PE_udata4); 119370be28a5adba5bcae0c6dcd63f17592864c351fcBenjamin Kramer if (VerboseAsm) Streamer.AddComment("Compact Unwind Encoding: 0x" + 119470be28a5adba5bcae0c6dcd63f17592864c351fcBenjamin Kramer Twine::utohexstr(Encoding)); 11959287a6eef336585628a55e1f33e1e3ea9d7f81cfBill Wendling Streamer.EmitIntValue(Encoding, Size); 11969287a6eef336585628a55e1f33e1e3ea9d7f81cfBill Wendling 1197e52e3f2c020354c8e0e966b719152b08349d0334Bill Wendling 11989056e9032001a2d47057cecec5e39895cbc31799Bill Wendling // Personality Function 11994bb5b037126ea35f35d5a490b03ccffa8677fa5eBill Wendling Size = getSizeForEncoding(Streamer, dwarf::DW_EH_PE_absptr); 12003c163cfa60f9f196cd6a5a04e07baec3947fee0bBill Wendling if (VerboseAsm) Streamer.AddComment("Personality Function"); 12014498d39680abe3970dc84dca973aff46d0f9039bBill Wendling if (Frame.Personality) 12029056e9032001a2d47057cecec5e39895cbc31799Bill Wendling Streamer.EmitSymbolValue(Frame.Personality, Size); 12034498d39680abe3970dc84dca973aff46d0f9039bBill Wendling else 12044498d39680abe3970dc84dca973aff46d0f9039bBill Wendling Streamer.EmitIntValue(0, Size); // No personality fn 12059056e9032001a2d47057cecec5e39895cbc31799Bill Wendling 12069056e9032001a2d47057cecec5e39895cbc31799Bill Wendling // LSDA 12074498d39680abe3970dc84dca973aff46d0f9039bBill Wendling Size = getSizeForEncoding(Streamer, Frame.LsdaEncoding); 12083c163cfa60f9f196cd6a5a04e07baec3947fee0bBill Wendling if (VerboseAsm) Streamer.AddComment("LSDA"); 12094498d39680abe3970dc84dca973aff46d0f9039bBill Wendling if (Frame.Lsda) 12109056e9032001a2d47057cecec5e39895cbc31799Bill Wendling Streamer.EmitSymbolValue(Frame.Lsda, Size); 12114498d39680abe3970dc84dca973aff46d0f9039bBill Wendling else 12124498d39680abe3970dc84dca973aff46d0f9039bBill Wendling Streamer.EmitIntValue(0, Size); // No LSDA 12139056e9032001a2d47057cecec5e39895cbc31799Bill Wendling 1214e3cd13f0e2d4e2ef30f8a57c0a82d328102eeb26Bill Wendling return true; 1215e3cd13f0e2d4e2ef30f8a57c0a82d328102eeb26Bill Wendling} 1216e3cd13f0e2d4e2ef30f8a57c0a82d328102eeb26Bill Wendling 121725f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindolaconst MCSymbol &FrameEmitterImpl::EmitCIE(MCStreamer &streamer, 121825f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindola const MCSymbol *personality, 121925f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindola unsigned personalityEncoding, 122025f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindola const MCSymbol *lsda, 122116d7d437e03ce87fdaef7971919302920d54a966Rafael Espindola bool IsSignalFrame, 122225f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindola unsigned lsdaEncoding) { 122389b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola MCContext &context = streamer.getContext(); 12240e6a052331f674dd70e28af41f654a7874405eabEvan Cheng const MCRegisterInfo &MRI = context.getRegisterInfo(); 1225e76a33b9567d78a5744dc52fcec3a6056d6fb576Evan Cheng const MCObjectFileInfo *MOFI = context.getObjectFileInfo(); 12263c163cfa60f9f196cd6a5a04e07baec3947fee0bBill Wendling bool verboseAsm = streamer.isVerboseAsm(); 1227514cecc72b23bb75108844285ab8f3616a08bac5Rafael Espindola 1228514cecc72b23bb75108844285ab8f3616a08bac5Rafael Espindola MCSymbol *sectionStart; 1229e76a33b9567d78a5744dc52fcec3a6056d6fb576Evan Cheng if (MOFI->isFunctionEHFrameSymbolPrivate() || !IsEH) 1230514cecc72b23bb75108844285ab8f3616a08bac5Rafael Espindola sectionStart = context.CreateTempSymbol(); 1231514cecc72b23bb75108844285ab8f3616a08bac5Rafael Espindola else 1232514cecc72b23bb75108844285ab8f3616a08bac5Rafael Espindola sectionStart = context.GetOrCreateSymbol(Twine("EH_frame") + Twine(CIENum)); 1233514cecc72b23bb75108844285ab8f3616a08bac5Rafael Espindola 12343c163cfa60f9f196cd6a5a04e07baec3947fee0bBill Wendling streamer.EmitLabel(sectionStart); 1235514cecc72b23bb75108844285ab8f3616a08bac5Rafael Espindola CIENum++; 1236514cecc72b23bb75108844285ab8f3616a08bac5Rafael Espindola 12376a6b8c3e96b9e1ca7092eafd0cfb219cbbfbdfc4Bill Wendling MCSymbol *sectionEnd = context.CreateTempSymbol(); 123889b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola 123989b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola // Length 124089b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola const MCExpr *Length = MakeStartMinusEndExpr(streamer, *sectionStart, 124189b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola *sectionEnd, 4); 12423c163cfa60f9f196cd6a5a04e07baec3947fee0bBill Wendling if (verboseAsm) streamer.AddComment("CIE Length"); 12439266cc400ee2fc86abb24ab0819d9da280fb61c4Rafael Espindola streamer.EmitAbsValue(Length, 4); 124489b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola 124589b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola // CIE ID 124640a7dbbeff44c4cbd8c7e4f07f28dd614f8a5d08Rafael Espindola unsigned CIE_ID = IsEH ? 0 : -1; 12473c163cfa60f9f196cd6a5a04e07baec3947fee0bBill Wendling if (verboseAsm) streamer.AddComment("CIE ID Tag"); 124840a7dbbeff44c4cbd8c7e4f07f28dd614f8a5d08Rafael Espindola streamer.EmitIntValue(CIE_ID, 4); 124989b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola 125089b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola // Version 12513c163cfa60f9f196cd6a5a04e07baec3947fee0bBill Wendling if (verboseAsm) streamer.AddComment("DW_CIE_VERSION"); 125289b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola streamer.EmitIntValue(dwarf::DW_CIE_VERSION, 1); 125389b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola 125489b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola // Augmentation String 125589b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola SmallString<8> Augmentation; 125640a7dbbeff44c4cbd8c7e4f07f28dd614f8a5d08Rafael Espindola if (IsEH) { 12573c163cfa60f9f196cd6a5a04e07baec3947fee0bBill Wendling if (verboseAsm) streamer.AddComment("CIE Augmentation"); 125840a7dbbeff44c4cbd8c7e4f07f28dd614f8a5d08Rafael Espindola Augmentation += "z"; 125940a7dbbeff44c4cbd8c7e4f07f28dd614f8a5d08Rafael Espindola if (personality) 126040a7dbbeff44c4cbd8c7e4f07f28dd614f8a5d08Rafael Espindola Augmentation += "P"; 126140a7dbbeff44c4cbd8c7e4f07f28dd614f8a5d08Rafael Espindola if (lsda) 126240a7dbbeff44c4cbd8c7e4f07f28dd614f8a5d08Rafael Espindola Augmentation += "L"; 126340a7dbbeff44c4cbd8c7e4f07f28dd614f8a5d08Rafael Espindola Augmentation += "R"; 126416d7d437e03ce87fdaef7971919302920d54a966Rafael Espindola if (IsSignalFrame) 126516d7d437e03ce87fdaef7971919302920d54a966Rafael Espindola Augmentation += "S"; 126668ca56285f9b6e82eb16ff8ea02a301f2c489faeEric Christopher streamer.EmitBytes(Augmentation.str()); 126740a7dbbeff44c4cbd8c7e4f07f28dd614f8a5d08Rafael Espindola } 126889b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola streamer.EmitIntValue(0, 1); 126989b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola 127089b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola // Code Alignment Factor 12713c163cfa60f9f196cd6a5a04e07baec3947fee0bBill Wendling if (verboseAsm) streamer.AddComment("CIE Code Alignment Factor"); 127289b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola streamer.EmitULEB128IntValue(1); 127389b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola 127489b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola // Data Alignment Factor 12753c163cfa60f9f196cd6a5a04e07baec3947fee0bBill Wendling if (verboseAsm) streamer.AddComment("CIE Data Alignment Factor"); 127689b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola streamer.EmitSLEB128IntValue(getDataAlignmentFactor(streamer)); 127789b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola 127889b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola // Return Address Register 12793c163cfa60f9f196cd6a5a04e07baec3947fee0bBill Wendling if (verboseAsm) streamer.AddComment("CIE Return Address Column"); 12800e6a052331f674dd70e28af41f654a7874405eabEvan Cheng streamer.EmitULEB128IntValue(MRI.getDwarfRegNum(MRI.getRARegister(), true)); 128189b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola 128289b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola // Augmentation Data Length (optional) 12831f6c87554a0d78103b95816fd2c1ce392b366bcfRafael Espindola 12841f6c87554a0d78103b95816fd2c1ce392b366bcfRafael Espindola unsigned augmentationLength = 0; 128540a7dbbeff44c4cbd8c7e4f07f28dd614f8a5d08Rafael Espindola if (IsEH) { 128640a7dbbeff44c4cbd8c7e4f07f28dd614f8a5d08Rafael Espindola if (personality) { 128740a7dbbeff44c4cbd8c7e4f07f28dd614f8a5d08Rafael Espindola // Personality Encoding 128840a7dbbeff44c4cbd8c7e4f07f28dd614f8a5d08Rafael Espindola augmentationLength += 1; 128940a7dbbeff44c4cbd8c7e4f07f28dd614f8a5d08Rafael Espindola // Personality 129040a7dbbeff44c4cbd8c7e4f07f28dd614f8a5d08Rafael Espindola augmentationLength += getSizeForEncoding(streamer, personalityEncoding); 129140a7dbbeff44c4cbd8c7e4f07f28dd614f8a5d08Rafael Espindola } 129240a7dbbeff44c4cbd8c7e4f07f28dd614f8a5d08Rafael Espindola if (lsda) 129340a7dbbeff44c4cbd8c7e4f07f28dd614f8a5d08Rafael Espindola augmentationLength += 1; 129440a7dbbeff44c4cbd8c7e4f07f28dd614f8a5d08Rafael Espindola // Encoding of the FDE pointers 12951f6c87554a0d78103b95816fd2c1ce392b366bcfRafael Espindola augmentationLength += 1; 12961f6c87554a0d78103b95816fd2c1ce392b366bcfRafael Espindola 12973c163cfa60f9f196cd6a5a04e07baec3947fee0bBill Wendling if (verboseAsm) streamer.AddComment("Augmentation Size"); 129840a7dbbeff44c4cbd8c7e4f07f28dd614f8a5d08Rafael Espindola streamer.EmitULEB128IntValue(augmentationLength); 129989b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola 130040a7dbbeff44c4cbd8c7e4f07f28dd614f8a5d08Rafael Espindola // Augmentation Data (optional) 130140a7dbbeff44c4cbd8c7e4f07f28dd614f8a5d08Rafael Espindola if (personality) { 130240a7dbbeff44c4cbd8c7e4f07f28dd614f8a5d08Rafael Espindola // Personality Encoding 13033c163cfa60f9f196cd6a5a04e07baec3947fee0bBill Wendling EmitEncodingByte(streamer, personalityEncoding, 13043c163cfa60f9f196cd6a5a04e07baec3947fee0bBill Wendling "Personality Encoding"); 130540a7dbbeff44c4cbd8c7e4f07f28dd614f8a5d08Rafael Espindola // Personality 13063c163cfa60f9f196cd6a5a04e07baec3947fee0bBill Wendling if (verboseAsm) streamer.AddComment("Personality"); 130740a7dbbeff44c4cbd8c7e4f07f28dd614f8a5d08Rafael Espindola EmitPersonality(streamer, *personality, personalityEncoding); 130840a7dbbeff44c4cbd8c7e4f07f28dd614f8a5d08Rafael Espindola } 13093c163cfa60f9f196cd6a5a04e07baec3947fee0bBill Wendling 131040a7dbbeff44c4cbd8c7e4f07f28dd614f8a5d08Rafael Espindola if (lsda) 13113c163cfa60f9f196cd6a5a04e07baec3947fee0bBill Wendling EmitEncodingByte(streamer, lsdaEncoding, "LSDA Encoding"); 13123c163cfa60f9f196cd6a5a04e07baec3947fee0bBill Wendling 131340a7dbbeff44c4cbd8c7e4f07f28dd614f8a5d08Rafael Espindola // Encoding of the FDE pointers 1314203576aa0cb9d8bf2d2e4d910ebab4b7a63262aeEvan Cheng EmitEncodingByte(streamer, MOFI->getFDEEncoding(UsingCFI), 13153c163cfa60f9f196cd6a5a04e07baec3947fee0bBill Wendling "FDE Encoding"); 1316bdc3167c086dd4358e24692075db5e7784140843Rafael Espindola } 131789b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola 131889b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola // Initial Instructions 131989b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola 13202d28617de2b0b731c08d1af9e830f31e14ac75b4Evan Cheng const MCAsmInfo &MAI = context.getAsmInfo(); 13212d28617de2b0b731c08d1af9e830f31e14ac75b4Evan Cheng const std::vector<MachineMove> &Moves = MAI.getInitialFrameState(); 1322fe024d0a624404ada11fb330e7360abc5f88742eRafael Espindola std::vector<MCCFIInstruction> Instructions; 1323fe024d0a624404ada11fb330e7360abc5f88742eRafael Espindola 1324fe024d0a624404ada11fb330e7360abc5f88742eRafael Espindola for (int i = 0, n = Moves.size(); i != n; ++i) { 1325b40a71fda188f8ca564e606ac2cb051a44ada311Rafael Espindola MCSymbol *Label = Moves[i].getLabel(); 1326b40a71fda188f8ca564e606ac2cb051a44ada311Rafael Espindola const MachineLocation &Dst = 13270e6a052331f674dd70e28af41f654a7874405eabEvan Cheng TranslateMachineLocation(MRI, Moves[i].getDestination()); 1328b40a71fda188f8ca564e606ac2cb051a44ada311Rafael Espindola const MachineLocation &Src = 13290e6a052331f674dd70e28af41f654a7874405eabEvan Cheng TranslateMachineLocation(MRI, Moves[i].getSource()); 133028c9ea3c13dfb8f6bb3226ba511d189135fcb140Rafael Espindola 133128c9ea3c13dfb8f6bb3226ba511d189135fcb140Rafael Espindola if (Dst.isReg()) { 133228c9ea3c13dfb8f6bb3226ba511d189135fcb140Rafael Espindola assert(Dst.getReg() == MachineLocation::VirtualFP); 133328c9ea3c13dfb8f6bb3226ba511d189135fcb140Rafael Espindola assert(!Src.isReg()); 133428c9ea3c13dfb8f6bb3226ba511d189135fcb140Rafael Espindola MCCFIInstruction Inst = 133528c9ea3c13dfb8f6bb3226ba511d189135fcb140Rafael Espindola MCCFIInstruction::createDefCfa(Label, Src.getReg(), -Src.getOffset()); 133628c9ea3c13dfb8f6bb3226ba511d189135fcb140Rafael Espindola Instructions.push_back(Inst); 133728c9ea3c13dfb8f6bb3226ba511d189135fcb140Rafael Espindola } else { 133828c9ea3c13dfb8f6bb3226ba511d189135fcb140Rafael Espindola assert(Src.isReg()); 133928c9ea3c13dfb8f6bb3226ba511d189135fcb140Rafael Espindola unsigned Reg = Src.getReg(); 134028c9ea3c13dfb8f6bb3226ba511d189135fcb140Rafael Espindola int Offset = Dst.getOffset(); 134128c9ea3c13dfb8f6bb3226ba511d189135fcb140Rafael Espindola MCCFIInstruction Inst = 13427f74d2c2c197eec76ae2b41fed9c227c0dcc04cbRafael Espindola MCCFIInstruction::createOffset(Label, Reg, Offset); 134328c9ea3c13dfb8f6bb3226ba511d189135fcb140Rafael Espindola Instructions.push_back(Inst); 134428c9ea3c13dfb8f6bb3226ba511d189135fcb140Rafael Espindola } 1345fe024d0a624404ada11fb330e7360abc5f88742eRafael Espindola } 134689b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola 1347b40a71fda188f8ca564e606ac2cb051a44ada311Rafael Espindola EmitCFIInstructions(streamer, Instructions, NULL); 134889b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola 134989b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola // Padding 13501be0e271a07925b928ba89848934f1ea6f1854e2Evan Cheng streamer.EmitValueToAlignment(IsEH 13511be0e271a07925b928ba89848934f1ea6f1854e2Evan Cheng ? 4 : context.getAsmInfo().getPointerSize()); 135289b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola 135389b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola streamer.EmitLabel(sectionEnd); 135489b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola return *sectionStart; 135589b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola} 135689b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola 135725f492e77858dc5a95fcd7180e73aff47925b668Rafael EspindolaMCSymbol *FrameEmitterImpl::EmitFDE(MCStreamer &streamer, 135825f492e77858dc5a95fcd7180e73aff47925b668Rafael Espindola const MCSymbol &cieStart, 13599f270dadd429771dded5a8572da8c74513771c15Rafael Espindola const MCDwarfFrameInfo &frame) { 1360bdc3167c086dd4358e24692075db5e7784140843Rafael Espindola MCContext &context = streamer.getContext(); 1361bdc3167c086dd4358e24692075db5e7784140843Rafael Espindola MCSymbol *fdeStart = context.CreateTempSymbol(); 1362bdc3167c086dd4358e24692075db5e7784140843Rafael Espindola MCSymbol *fdeEnd = context.CreateTempSymbol(); 1363e76a33b9567d78a5744dc52fcec3a6056d6fb576Evan Cheng const MCObjectFileInfo *MOFI = context.getObjectFileInfo(); 13642541c41f3e2af94585e14353a91f02facd65e415Bill Wendling bool verboseAsm = streamer.isVerboseAsm(); 136589b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola 13665fbe5e783ee0c5ae27c17490a752d7e603e84ed2Evan Cheng if (IsEH && frame.Function && !MOFI->isFunctionEHFrameSymbolPrivate()) { 13672541c41f3e2af94585e14353a91f02facd65e415Bill Wendling MCSymbol *EHSym = 13682541c41f3e2af94585e14353a91f02facd65e415Bill Wendling context.GetOrCreateSymbol(frame.Function->getName() + Twine(".eh")); 13698bca4106dfc2945723251db10e340183f3e372ddRafael Espindola streamer.EmitEHSymAttributes(frame.Function, EHSym); 1370a8cfb87fa2176fae2d62785a0dd606e4143cefaeRafael Espindola streamer.EmitLabel(EHSym); 1371a8cfb87fa2176fae2d62785a0dd606e4143cefaeRafael Espindola } 1372a8cfb87fa2176fae2d62785a0dd606e4143cefaeRafael Espindola 137389b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola // Length 137489b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola const MCExpr *Length = MakeStartMinusEndExpr(streamer, *fdeStart, *fdeEnd, 0); 13752541c41f3e2af94585e14353a91f02facd65e415Bill Wendling if (verboseAsm) streamer.AddComment("FDE Length"); 13769266cc400ee2fc86abb24ab0819d9da280fb61c4Rafael Espindola streamer.EmitAbsValue(Length, 4); 137789b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola 137889b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola streamer.EmitLabel(fdeStart); 1379e3a0e987f3d4f07512cdb64b9034369f966cb448Rafael Espindola 138089b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola // CIE Pointer 1381e3a0e987f3d4f07512cdb64b9034369f966cb448Rafael Espindola const MCAsmInfo &asmInfo = context.getAsmInfo(); 13820d450dc65906a30beb56aeb1ee22b45b1cd4596cRafael Espindola if (IsEH) { 13830d450dc65906a30beb56aeb1ee22b45b1cd4596cRafael Espindola const MCExpr *offset = MakeStartMinusEndExpr(streamer, cieStart, *fdeStart, 13840d450dc65906a30beb56aeb1ee22b45b1cd4596cRafael Espindola 0); 13852541c41f3e2af94585e14353a91f02facd65e415Bill Wendling if (verboseAsm) streamer.AddComment("FDE CIE Offset"); 13860d450dc65906a30beb56aeb1ee22b45b1cd4596cRafael Espindola streamer.EmitAbsValue(offset, 4); 13872241e51406f7bae369d6103cf3464e70f74c4af9Rafael Espindola } else if (!asmInfo.doesDwarfUseRelocationsAcrossSections()) { 1388e3a0e987f3d4f07512cdb64b9034369f966cb448Rafael Espindola const MCExpr *offset = MakeStartMinusEndExpr(streamer, *SectionStart, 1389e3a0e987f3d4f07512cdb64b9034369f966cb448Rafael Espindola cieStart, 0); 1390e3a0e987f3d4f07512cdb64b9034369f966cb448Rafael Espindola streamer.EmitAbsValue(offset, 4); 13910d450dc65906a30beb56aeb1ee22b45b1cd4596cRafael Espindola } else { 13920d450dc65906a30beb56aeb1ee22b45b1cd4596cRafael Espindola streamer.EmitSymbolValue(&cieStart, 4); 13930d450dc65906a30beb56aeb1ee22b45b1cd4596cRafael Espindola } 13942541c41f3e2af94585e14353a91f02facd65e415Bill Wendling 139589b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola // PC Begin 13960c5602de8c0dfa716f54306a1c540b98ab803584Nick Lewycky unsigned PCEncoding = IsEH ? MOFI->getFDEEncoding(UsingCFI) 13970c5602de8c0dfa716f54306a1c540b98ab803584Nick Lewycky : (unsigned)dwarf::DW_EH_PE_absptr; 13980c5602de8c0dfa716f54306a1c540b98ab803584Nick Lewycky unsigned PCSize = getSizeForEncoding(streamer, PCEncoding); 13990c5602de8c0dfa716f54306a1c540b98ab803584Nick Lewycky EmitSymbol(streamer, *frame.Begin, PCEncoding, "FDE initial location"); 140089b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola 140189b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola // PC Range 140289b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola const MCExpr *Range = MakeStartMinusEndExpr(streamer, *frame.Begin, 140389b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola *frame.End, 0); 14042541c41f3e2af94585e14353a91f02facd65e415Bill Wendling if (verboseAsm) streamer.AddComment("FDE address range"); 14050c5602de8c0dfa716f54306a1c540b98ab803584Nick Lewycky streamer.EmitAbsValue(Range, PCSize); 140689b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola 140740a7dbbeff44c4cbd8c7e4f07f28dd614f8a5d08Rafael Espindola if (IsEH) { 140840a7dbbeff44c4cbd8c7e4f07f28dd614f8a5d08Rafael Espindola // Augmentation Data Length 140940a7dbbeff44c4cbd8c7e4f07f28dd614f8a5d08Rafael Espindola unsigned augmentationLength = 0; 14101f6c87554a0d78103b95816fd2c1ce392b366bcfRafael Espindola 141140a7dbbeff44c4cbd8c7e4f07f28dd614f8a5d08Rafael Espindola if (frame.Lsda) 141240a7dbbeff44c4cbd8c7e4f07f28dd614f8a5d08Rafael Espindola augmentationLength += getSizeForEncoding(streamer, frame.LsdaEncoding); 14131f6c87554a0d78103b95816fd2c1ce392b366bcfRafael Espindola 14142541c41f3e2af94585e14353a91f02facd65e415Bill Wendling if (verboseAsm) streamer.AddComment("Augmentation size"); 141540a7dbbeff44c4cbd8c7e4f07f28dd614f8a5d08Rafael Espindola streamer.EmitULEB128IntValue(augmentationLength); 141689b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola 141740a7dbbeff44c4cbd8c7e4f07f28dd614f8a5d08Rafael Espindola // Augmentation Data 141840a7dbbeff44c4cbd8c7e4f07f28dd614f8a5d08Rafael Espindola if (frame.Lsda) 14192541c41f3e2af94585e14353a91f02facd65e415Bill Wendling EmitSymbol(streamer, *frame.Lsda, frame.LsdaEncoding, 14202541c41f3e2af94585e14353a91f02facd65e415Bill Wendling "Language Specific Data Area"); 142140a7dbbeff44c4cbd8c7e4f07f28dd614f8a5d08Rafael Espindola } 14224892dff07e7d99eb37aee868c4f2c91e9c7eba14Rafael Espindola 142389b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola // Call Frame Instructions 142489b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola 1425b40a71fda188f8ca564e606ac2cb051a44ada311Rafael Espindola EmitCFIInstructions(streamer, frame.Instructions, frame.Begin); 14265bba08425374ca36fe5fbc7423ce1a09858e4097Rafael Espindola 142789b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola // Padding 14280c5602de8c0dfa716f54306a1c540b98ab803584Nick Lewycky streamer.EmitValueToAlignment(PCSize); 1429dfe125cc9cfd524575973daa297c9aad10470390Rafael Espindola 1430dfe125cc9cfd524575973daa297c9aad10470390Rafael Espindola return fdeEnd; 143189b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola} 143289b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola 143319282365147f498a60463d250dbed2f8e1b81861Benjamin Kramernamespace { 143419282365147f498a60463d250dbed2f8e1b81861Benjamin Kramer struct CIEKey { 143516d7d437e03ce87fdaef7971919302920d54a966Rafael Espindola static const CIEKey getEmptyKey() { return CIEKey(0, 0, -1, false); } 143616d7d437e03ce87fdaef7971919302920d54a966Rafael Espindola static const CIEKey getTombstoneKey() { return CIEKey(0, -1, 0, false); } 143719282365147f498a60463d250dbed2f8e1b81861Benjamin Kramer 143819282365147f498a60463d250dbed2f8e1b81861Benjamin Kramer CIEKey(const MCSymbol* Personality_, unsigned PersonalityEncoding_, 143916d7d437e03ce87fdaef7971919302920d54a966Rafael Espindola unsigned LsdaEncoding_, bool IsSignalFrame_) : 144016d7d437e03ce87fdaef7971919302920d54a966Rafael Espindola Personality(Personality_), PersonalityEncoding(PersonalityEncoding_), 144116d7d437e03ce87fdaef7971919302920d54a966Rafael Espindola LsdaEncoding(LsdaEncoding_), IsSignalFrame(IsSignalFrame_) { 144219282365147f498a60463d250dbed2f8e1b81861Benjamin Kramer } 144319282365147f498a60463d250dbed2f8e1b81861Benjamin Kramer const MCSymbol* Personality; 144419282365147f498a60463d250dbed2f8e1b81861Benjamin Kramer unsigned PersonalityEncoding; 144519282365147f498a60463d250dbed2f8e1b81861Benjamin Kramer unsigned LsdaEncoding; 144616d7d437e03ce87fdaef7971919302920d54a966Rafael Espindola bool IsSignalFrame; 144719282365147f498a60463d250dbed2f8e1b81861Benjamin Kramer }; 144819282365147f498a60463d250dbed2f8e1b81861Benjamin Kramer} 1449bdc3167c086dd4358e24692075db5e7784140843Rafael Espindola 1450bdc3167c086dd4358e24692075db5e7784140843Rafael Espindolanamespace llvm { 1451bdc3167c086dd4358e24692075db5e7784140843Rafael Espindola template <> 1452bdc3167c086dd4358e24692075db5e7784140843Rafael Espindola struct DenseMapInfo<CIEKey> { 1453bdc3167c086dd4358e24692075db5e7784140843Rafael Espindola static CIEKey getEmptyKey() { 145419282365147f498a60463d250dbed2f8e1b81861Benjamin Kramer return CIEKey::getEmptyKey(); 1455bdc3167c086dd4358e24692075db5e7784140843Rafael Espindola } 1456bdc3167c086dd4358e24692075db5e7784140843Rafael Espindola static CIEKey getTombstoneKey() { 145719282365147f498a60463d250dbed2f8e1b81861Benjamin Kramer return CIEKey::getTombstoneKey(); 1458bdc3167c086dd4358e24692075db5e7784140843Rafael Espindola } 1459bdc3167c086dd4358e24692075db5e7784140843Rafael Espindola static unsigned getHashValue(const CIEKey &Key) { 14607484920cf5d95b21fa750229f8ce0d1624c918ecBenjamin Kramer return static_cast<unsigned>(hash_combine(Key.Personality, 14617484920cf5d95b21fa750229f8ce0d1624c918ecBenjamin Kramer Key.PersonalityEncoding, 14627484920cf5d95b21fa750229f8ce0d1624c918ecBenjamin Kramer Key.LsdaEncoding, 14637484920cf5d95b21fa750229f8ce0d1624c918ecBenjamin Kramer Key.IsSignalFrame)); 1464bdc3167c086dd4358e24692075db5e7784140843Rafael Espindola } 1465bdc3167c086dd4358e24692075db5e7784140843Rafael Espindola static bool isEqual(const CIEKey &LHS, 1466bdc3167c086dd4358e24692075db5e7784140843Rafael Espindola const CIEKey &RHS) { 1467bdc3167c086dd4358e24692075db5e7784140843Rafael Espindola return LHS.Personality == RHS.Personality && 1468bdc3167c086dd4358e24692075db5e7784140843Rafael Espindola LHS.PersonalityEncoding == RHS.PersonalityEncoding && 146916d7d437e03ce87fdaef7971919302920d54a966Rafael Espindola LHS.LsdaEncoding == RHS.LsdaEncoding && 147016d7d437e03ce87fdaef7971919302920d54a966Rafael Espindola LHS.IsSignalFrame == RHS.IsSignalFrame; 1471bdc3167c086dd4358e24692075db5e7784140843Rafael Espindola } 1472bdc3167c086dd4358e24692075db5e7784140843Rafael Espindola }; 1473bdc3167c086dd4358e24692075db5e7784140843Rafael Espindola} 1474bdc3167c086dd4358e24692075db5e7784140843Rafael Espindola 1475a8c9e6a943bc0873d1ce781d2444a6d6137f0e17Bill Wendlingvoid MCDwarfFrameEmitter::Emit(MCStreamer &Streamer, 1476a8c9e6a943bc0873d1ce781d2444a6d6137f0e17Bill Wendling bool UsingCFI, 1477a8c9e6a943bc0873d1ce781d2444a6d6137f0e17Bill Wendling bool IsEH) { 1478a8c9e6a943bc0873d1ce781d2444a6d6137f0e17Bill Wendling MCContext &Context = Streamer.getContext(); 1479e76a33b9567d78a5744dc52fcec3a6056d6fb576Evan Cheng MCObjectFileInfo *MOFI = 1480e76a33b9567d78a5744dc52fcec3a6056d6fb576Evan Cheng const_cast<MCObjectFileInfo*>(Context.getObjectFileInfo()); 14811424c3c3e696868775ac5bfc57d27a0ac3bc6c63Bill Wendling FrameEmitterImpl Emitter(UsingCFI, IsEH); 1482d8ab8e9707e6170218ce82516d15b36f54b4bc1cBill Wendling ArrayRef<MCDwarfFrameInfo> FrameArray = Streamer.getFrameInfos(); 14831424c3c3e696868775ac5bfc57d27a0ac3bc6c63Bill Wendling 1484d8ab8e9707e6170218ce82516d15b36f54b4bc1cBill Wendling // Emit the compact unwind info if available. 14857a13b72bbbadaa9274f6a58774970b9b95706330Bill Wendling if (IsEH && MOFI->getCompactUnwindSection()) 14861424c3c3e696868775ac5bfc57d27a0ac3bc6c63Bill Wendling for (unsigned i = 0, n = Streamer.getNumFrameInfos(); i < n; ++i) { 14871424c3c3e696868775ac5bfc57d27a0ac3bc6c63Bill Wendling const MCDwarfFrameInfo &Frame = Streamer.getFrameInfo(i); 1488a2ff3e2c3c0d8be862525c91f7b0e153480f4f5eBill Wendling if (Frame.CompactUnwindEncoding) 1489d8ab8e9707e6170218ce82516d15b36f54b4bc1cBill Wendling Emitter.EmitCompactUnwind(Streamer, Frame); 14901424c3c3e696868775ac5bfc57d27a0ac3bc6c63Bill Wendling } 14911424c3c3e696868775ac5bfc57d27a0ac3bc6c63Bill Wendling 1492e76a33b9567d78a5744dc52fcec3a6056d6fb576Evan Cheng const MCSection &Section = IsEH ? *MOFI->getEHFrameSection() : 1493e76a33b9567d78a5744dc52fcec3a6056d6fb576Evan Cheng *MOFI->getDwarfFrameSection(); 1494a8c9e6a943bc0873d1ce781d2444a6d6137f0e17Bill Wendling Streamer.SwitchSection(&Section); 1495a8c9e6a943bc0873d1ce781d2444a6d6137f0e17Bill Wendling MCSymbol *SectionStart = Context.CreateTempSymbol(); 1496a8c9e6a943bc0873d1ce781d2444a6d6137f0e17Bill Wendling Streamer.EmitLabel(SectionStart); 14971424c3c3e696868775ac5bfc57d27a0ac3bc6c63Bill Wendling Emitter.setSectionStart(SectionStart); 1498a8c9e6a943bc0873d1ce781d2444a6d6137f0e17Bill Wendling 1499a8c9e6a943bc0873d1ce781d2444a6d6137f0e17Bill Wendling MCSymbol *FDEEnd = NULL; 1500bdc3167c086dd4358e24692075db5e7784140843Rafael Espindola DenseMap<CIEKey, const MCSymbol*> CIEStarts; 1501d7c8ccae8e48dce3ab7c3e9b4d8a309998c47961Rafael Espindola 150240a7dbbeff44c4cbd8c7e4f07f28dd614f8a5d08Rafael Espindola const MCSymbol *DummyDebugKey = NULL; 15031424c3c3e696868775ac5bfc57d27a0ac3bc6c63Bill Wendling for (unsigned i = 0, n = FrameArray.size(); i < n; ++i) { 15041424c3c3e696868775ac5bfc57d27a0ac3bc6c63Bill Wendling const MCDwarfFrameInfo &Frame = FrameArray[i]; 1505a8c9e6a943bc0873d1ce781d2444a6d6137f0e17Bill Wendling CIEKey Key(Frame.Personality, Frame.PersonalityEncoding, 150616d7d437e03ce87fdaef7971919302920d54a966Rafael Espindola Frame.LsdaEncoding, Frame.IsSignalFrame); 1507a8c9e6a943bc0873d1ce781d2444a6d6137f0e17Bill Wendling const MCSymbol *&CIEStart = IsEH ? CIEStarts[Key] : DummyDebugKey; 1508a8c9e6a943bc0873d1ce781d2444a6d6137f0e17Bill Wendling if (!CIEStart) 1509a8c9e6a943bc0873d1ce781d2444a6d6137f0e17Bill Wendling CIEStart = &Emitter.EmitCIE(Streamer, Frame.Personality, 1510a8c9e6a943bc0873d1ce781d2444a6d6137f0e17Bill Wendling Frame.PersonalityEncoding, Frame.Lsda, 151116d7d437e03ce87fdaef7971919302920d54a966Rafael Espindola Frame.IsSignalFrame, 1512a8c9e6a943bc0873d1ce781d2444a6d6137f0e17Bill Wendling Frame.LsdaEncoding); 1513e3cd13f0e2d4e2ef30f8a57c0a82d328102eeb26Bill Wendling 1514a8c9e6a943bc0873d1ce781d2444a6d6137f0e17Bill Wendling FDEEnd = Emitter.EmitFDE(Streamer, *CIEStart, Frame); 1515e3cd13f0e2d4e2ef30f8a57c0a82d328102eeb26Bill Wendling 1516dfe125cc9cfd524575973daa297c9aad10470390Rafael Espindola if (i != n - 1) 1517a8c9e6a943bc0873d1ce781d2444a6d6137f0e17Bill Wendling Streamer.EmitLabel(FDEEnd); 1518dfe125cc9cfd524575973daa297c9aad10470390Rafael Espindola } 1519d7c8ccae8e48dce3ab7c3e9b4d8a309998c47961Rafael Espindola 15201be0e271a07925b928ba89848934f1ea6f1854e2Evan Cheng Streamer.EmitValueToAlignment(Context.getAsmInfo().getPointerSize()); 1521a8c9e6a943bc0873d1ce781d2444a6d6137f0e17Bill Wendling if (FDEEnd) 1522a8c9e6a943bc0873d1ce781d2444a6d6137f0e17Bill Wendling Streamer.EmitLabel(FDEEnd); 152389b9372605db2ce3b0085c84089e389f7bc1fbddRafael Espindola} 1524245a1e20419aa5a3c833d7a8e89168e19d5f4d2cRafael Espindola 1525245a1e20419aa5a3c833d7a8e89168e19d5f4d2cRafael Espindolavoid MCDwarfFrameEmitter::EmitAdvanceLoc(MCStreamer &Streamer, 1526245a1e20419aa5a3c833d7a8e89168e19d5f4d2cRafael Espindola uint64_t AddrDelta) { 1527245a1e20419aa5a3c833d7a8e89168e19d5f4d2cRafael Espindola SmallString<256> Tmp; 1528245a1e20419aa5a3c833d7a8e89168e19d5f4d2cRafael Espindola raw_svector_ostream OS(Tmp); 15294eafe109459eb115f13f1d19c5ff3cb3678e8c7aRafael Espindola MCDwarfFrameEmitter::EncodeAdvanceLoc(AddrDelta, OS); 153068ca56285f9b6e82eb16ff8ea02a301f2c489faeEric Christopher Streamer.EmitBytes(OS.str()); 1531245a1e20419aa5a3c833d7a8e89168e19d5f4d2cRafael Espindola} 1532245a1e20419aa5a3c833d7a8e89168e19d5f4d2cRafael Espindola 1533245a1e20419aa5a3c833d7a8e89168e19d5f4d2cRafael Espindolavoid MCDwarfFrameEmitter::EncodeAdvanceLoc(uint64_t AddrDelta, 15344eafe109459eb115f13f1d19c5ff3cb3678e8c7aRafael Espindola raw_ostream &OS) { 1535245a1e20419aa5a3c833d7a8e89168e19d5f4d2cRafael Espindola // FIXME: Assumes the code alignment factor is 1. 15363b78cdc57ae25ff021fd67171a7c82d533477a19Rafael Espindola if (AddrDelta == 0) { 15374eafe109459eb115f13f1d19c5ff3cb3678e8c7aRafael Espindola } else if (isUIntN(6, AddrDelta)) { 1538245a1e20419aa5a3c833d7a8e89168e19d5f4d2cRafael Espindola uint8_t Opcode = dwarf::DW_CFA_advance_loc | AddrDelta; 1539245a1e20419aa5a3c833d7a8e89168e19d5f4d2cRafael Espindola OS << Opcode; 15404eafe109459eb115f13f1d19c5ff3cb3678e8c7aRafael Espindola } else if (isUInt<8>(AddrDelta)) { 1541245a1e20419aa5a3c833d7a8e89168e19d5f4d2cRafael Espindola OS << uint8_t(dwarf::DW_CFA_advance_loc1); 1542245a1e20419aa5a3c833d7a8e89168e19d5f4d2cRafael Espindola OS << uint8_t(AddrDelta); 15434eafe109459eb115f13f1d19c5ff3cb3678e8c7aRafael Espindola } else if (isUInt<16>(AddrDelta)) { 1544a7e450574c45209ca0b05ff715f9e7dddcbd936cRafael Espindola // FIXME: check what is the correct behavior on a big endian machine. 1545245a1e20419aa5a3c833d7a8e89168e19d5f4d2cRafael Espindola OS << uint8_t(dwarf::DW_CFA_advance_loc2); 1546a7e450574c45209ca0b05ff715f9e7dddcbd936cRafael Espindola OS << uint8_t( AddrDelta & 0xff); 1547a7e450574c45209ca0b05ff715f9e7dddcbd936cRafael Espindola OS << uint8_t((AddrDelta >> 8) & 0xff); 1548245a1e20419aa5a3c833d7a8e89168e19d5f4d2cRafael Espindola } else { 1549a7e450574c45209ca0b05ff715f9e7dddcbd936cRafael Espindola // FIXME: check what is the correct behavior on a big endian machine. 1550245a1e20419aa5a3c833d7a8e89168e19d5f4d2cRafael Espindola assert(isUInt<32>(AddrDelta)); 1551245a1e20419aa5a3c833d7a8e89168e19d5f4d2cRafael Espindola OS << uint8_t(dwarf::DW_CFA_advance_loc4); 1552a7e450574c45209ca0b05ff715f9e7dddcbd936cRafael Espindola OS << uint8_t( AddrDelta & 0xff); 1553a7e450574c45209ca0b05ff715f9e7dddcbd936cRafael Espindola OS << uint8_t((AddrDelta >> 8) & 0xff); 1554a7e450574c45209ca0b05ff715f9e7dddcbd936cRafael Espindola OS << uint8_t((AddrDelta >> 16) & 0xff); 1555a7e450574c45209ca0b05ff715f9e7dddcbd936cRafael Espindola OS << uint8_t((AddrDelta >> 24) & 0xff); 1556a7e450574c45209ca0b05ff715f9e7dddcbd936cRafael Espindola 1557245a1e20419aa5a3c833d7a8e89168e19d5f4d2cRafael Espindola } 1558245a1e20419aa5a3c833d7a8e89168e19d5f4d2cRafael Espindola} 1559