2155 lines · cpp
1//===-- llvm/CodeGen/DwarfUnit.cpp - Dwarf Type and Compile Units ---------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8//9// This file contains support for constructing a dwarf compile unit.10//11//===----------------------------------------------------------------------===//12 13#include "DwarfUnit.h"14#include "AddressPool.h"15#include "DwarfCompileUnit.h"16#include "DwarfExpression.h"17#include "llvm/ADT/APFloat.h"18#include "llvm/ADT/APInt.h"19#include "llvm/CodeGen/TargetRegisterInfo.h"20#include "llvm/IR/Constants.h"21#include "llvm/IR/DataLayout.h"22#include "llvm/IR/GlobalValue.h"23#include "llvm/IR/Metadata.h"24#include "llvm/MC/MCAsmInfo.h"25#include "llvm/MC/MCContext.h"26#include "llvm/MC/MCDwarf.h"27#include "llvm/MC/MCSection.h"28#include "llvm/MC/MCStreamer.h"29#include "llvm/Support/Casting.h"30#include "llvm/Target/TargetLoweringObjectFile.h"31#include <cassert>32#include <cstdint>33#include <limits>34#include <string>35 36using namespace llvm;37 38#define DEBUG_TYPE "dwarfdebug"39 40DIEDwarfExpression::DIEDwarfExpression(const AsmPrinter &AP,41 DwarfCompileUnit &CU, DIELoc &DIE)42 : DwarfExpression(AP.getDwarfVersion(), CU), AP(AP), OutDIE(DIE) {}43 44void DIEDwarfExpression::emitOp(uint8_t Op, const char* Comment) {45 CU.addUInt(getActiveDIE(), dwarf::DW_FORM_data1, Op);46}47 48void DIEDwarfExpression::emitSigned(int64_t Value) {49 CU.addSInt(getActiveDIE(), dwarf::DW_FORM_sdata, Value);50}51 52void DIEDwarfExpression::emitUnsigned(uint64_t Value) {53 CU.addUInt(getActiveDIE(), dwarf::DW_FORM_udata, Value);54}55 56void DIEDwarfExpression::emitData1(uint8_t Value) {57 CU.addUInt(getActiveDIE(), dwarf::DW_FORM_data1, Value);58}59 60void DIEDwarfExpression::emitBaseTypeRef(uint64_t Idx) {61 CU.addBaseTypeRef(getActiveDIE(), Idx);62}63 64void DIEDwarfExpression::enableTemporaryBuffer() {65 assert(!IsBuffering && "Already buffering?");66 IsBuffering = true;67}68 69void DIEDwarfExpression::disableTemporaryBuffer() { IsBuffering = false; }70 71unsigned DIEDwarfExpression::getTemporaryBufferSize() {72 return TmpDIE.computeSize(AP.getDwarfFormParams());73}74 75void DIEDwarfExpression::commitTemporaryBuffer() { OutDIE.takeValues(TmpDIE); }76 77bool DIEDwarfExpression::isFrameRegister(const TargetRegisterInfo &TRI,78 llvm::Register MachineReg) {79 return MachineReg == TRI.getFrameRegister(*AP.MF);80}81 82DwarfUnit::DwarfUnit(dwarf::Tag UnitTag, const DICompileUnit *Node,83 AsmPrinter *A, DwarfDebug *DW, DwarfFile *DWU,84 unsigned UniqueID)85 : DIEUnit(UnitTag), UniqueID(UniqueID), CUNode(Node), Asm(A), DD(DW),86 DU(DWU) {}87 88DwarfTypeUnit::DwarfTypeUnit(DwarfCompileUnit &CU, AsmPrinter *A,89 DwarfDebug *DW, DwarfFile *DWU, unsigned UniqueID,90 MCDwarfDwoLineTable *SplitLineTable)91 : DwarfUnit(dwarf::DW_TAG_type_unit, CU.getCUNode(), A, DW, DWU, UniqueID),92 CU(CU), SplitLineTable(SplitLineTable) {}93 94DwarfUnit::~DwarfUnit() {95 for (DIEBlock *B : DIEBlocks)96 B->~DIEBlock();97 for (DIELoc *L : DIELocs)98 L->~DIELoc();99}100 101int64_t DwarfUnit::getDefaultLowerBound() const {102 switch (getSourceLanguage()) {103 default:104 break;105 106 // The languages below have valid values in all DWARF versions.107 case dwarf::DW_LANG_C:108 case dwarf::DW_LANG_C89:109 case dwarf::DW_LANG_C_plus_plus:110 return 0;111 112 case dwarf::DW_LANG_Fortran77:113 case dwarf::DW_LANG_Fortran90:114 return 1;115 116 // The languages below have valid values only if the DWARF version >= 3.117 case dwarf::DW_LANG_C99:118 case dwarf::DW_LANG_ObjC:119 case dwarf::DW_LANG_ObjC_plus_plus:120 if (DD->getDwarfVersion() >= 3)121 return 0;122 break;123 124 case dwarf::DW_LANG_Fortran95:125 if (DD->getDwarfVersion() >= 3)126 return 1;127 break;128 129 // Starting with DWARF v4, all defined languages have valid values.130 case dwarf::DW_LANG_D:131 case dwarf::DW_LANG_Java:132 case dwarf::DW_LANG_Python:133 case dwarf::DW_LANG_UPC:134 if (DD->getDwarfVersion() >= 4)135 return 0;136 break;137 138 case dwarf::DW_LANG_Ada83:139 case dwarf::DW_LANG_Ada95:140 case dwarf::DW_LANG_Cobol74:141 case dwarf::DW_LANG_Cobol85:142 case dwarf::DW_LANG_Modula2:143 case dwarf::DW_LANG_Pascal83:144 case dwarf::DW_LANG_PLI:145 if (DD->getDwarfVersion() >= 4)146 return 1;147 break;148 149 // The languages below are new in DWARF v5.150 case dwarf::DW_LANG_BLISS:151 case dwarf::DW_LANG_C11:152 case dwarf::DW_LANG_C_plus_plus_03:153 case dwarf::DW_LANG_C_plus_plus_11:154 case dwarf::DW_LANG_C_plus_plus_14:155 case dwarf::DW_LANG_Dylan:156 case dwarf::DW_LANG_Go:157 case dwarf::DW_LANG_Haskell:158 case dwarf::DW_LANG_OCaml:159 case dwarf::DW_LANG_OpenCL:160 case dwarf::DW_LANG_RenderScript:161 case dwarf::DW_LANG_Rust:162 case dwarf::DW_LANG_Swift:163 if (DD->getDwarfVersion() >= 5)164 return 0;165 break;166 167 case dwarf::DW_LANG_Fortran03:168 case dwarf::DW_LANG_Fortran08:169 case dwarf::DW_LANG_Julia:170 case dwarf::DW_LANG_Modula3:171 if (DD->getDwarfVersion() >= 5)172 return 1;173 break;174 }175 176 return -1;177}178 179/// Check whether the DIE for this MDNode can be shared across CUs.180bool DwarfUnit::isShareableAcrossCUs(const DINode *D) const {181 // When the MDNode can be part of the type system, the DIE can be shared182 // across CUs.183 // Combining type units and cross-CU DIE sharing is lower value (since184 // cross-CU DIE sharing is used in LTO and removes type redundancy at that185 // level already) but may be implementable for some value in projects186 // building multiple independent libraries with LTO and then linking those187 // together.188 if (isDwoUnit() && !DD->shareAcrossDWOCUs())189 return false;190 return (isa<DIType>(D) ||191 (isa<DISubprogram>(D) && !cast<DISubprogram>(D)->isDefinition())) &&192 !DD->generateTypeUnits();193}194 195DIE *DwarfUnit::getDIE(const DINode *D) const {196 if (isShareableAcrossCUs(D))197 return DU->getDIE(D);198 return MDNodeToDieMap.lookup(D);199}200 201void DwarfUnit::insertDIE(const DINode *Desc, DIE *D) {202 if (isShareableAcrossCUs(Desc)) {203 DU->insertDIE(Desc, D);204 return;205 }206 MDNodeToDieMap.insert(std::make_pair(Desc, D));207}208 209void DwarfUnit::insertDIE(DIE *D) {210 MDNodeToDieMap.insert(std::make_pair(nullptr, D));211}212 213void DwarfUnit::addFlag(DIE &Die, dwarf::Attribute Attribute) {214 if (DD->getDwarfVersion() >= 4)215 addAttribute(Die, Attribute, dwarf::DW_FORM_flag_present, DIEInteger(1));216 else217 addAttribute(Die, Attribute, dwarf::DW_FORM_flag, DIEInteger(1));218}219 220void DwarfUnit::addUInt(DIEValueList &Die, dwarf::Attribute Attribute,221 std::optional<dwarf::Form> Form, uint64_t Integer) {222 if (!Form)223 Form = DIEInteger::BestForm(false, Integer);224 assert(Form != dwarf::DW_FORM_implicit_const &&225 "DW_FORM_implicit_const is used only for signed integers");226 addAttribute(Die, Attribute, *Form, DIEInteger(Integer));227}228 229void DwarfUnit::addUInt(DIEValueList &Block, dwarf::Form Form,230 uint64_t Integer) {231 addUInt(Block, (dwarf::Attribute)0, Form, Integer);232}233 234void DwarfUnit::addIntAsBlock(DIE &Die, dwarf::Attribute Attribute, const APInt &Val) {235 DIEBlock *Block = new (DIEValueAllocator) DIEBlock;236 237 // Get the raw data form of the large APInt.238 const uint64_t *Ptr64 = Val.getRawData();239 240 int NumBytes = Val.getBitWidth() / 8; // 8 bits per byte.241 bool LittleEndian = Asm->getDataLayout().isLittleEndian();242 243 // Output the constant to DWARF one byte at a time.244 for (int i = 0; i < NumBytes; i++) {245 uint8_t c;246 if (LittleEndian)247 c = Ptr64[i / 8] >> (8 * (i & 7));248 else249 c = Ptr64[(NumBytes - 1 - i) / 8] >> (8 * ((NumBytes - 1 - i) & 7));250 addUInt(*Block, dwarf::DW_FORM_data1, c);251 }252 253 addBlock(Die, Attribute, Block);254}255 256void DwarfUnit::addInt(DIE &Die, dwarf::Attribute Attribute,257 const APInt &Val, bool Unsigned) {258 unsigned CIBitWidth = Val.getBitWidth();259 if (CIBitWidth <= 64) {260 if (Unsigned)261 addUInt(Die, Attribute, std::nullopt, Val.getZExtValue());262 else263 addSInt(Die, Attribute, std::nullopt, Val.getSExtValue());264 return;265 }266 267 addIntAsBlock(Die, Attribute, Val);268}269 270void DwarfUnit::addSInt(DIEValueList &Die, dwarf::Attribute Attribute,271 std::optional<dwarf::Form> Form, int64_t Integer) {272 if (!Form)273 Form = DIEInteger::BestForm(true, Integer);274 addAttribute(Die, Attribute, *Form, DIEInteger(Integer));275}276 277void DwarfUnit::addSInt(DIEValueList &Die, std::optional<dwarf::Form> Form,278 int64_t Integer) {279 addSInt(Die, (dwarf::Attribute)0, Form, Integer);280}281 282void DwarfUnit::addString(DIE &Die, dwarf::Attribute Attribute,283 StringRef String) {284 if (CUNode->isDebugDirectivesOnly())285 return;286 287 if (DD->useInlineStrings()) {288 addAttribute(Die, Attribute, dwarf::DW_FORM_string,289 new (DIEValueAllocator)290 DIEInlineString(String, DIEValueAllocator));291 return;292 }293 dwarf::Form IxForm =294 isDwoUnit() ? dwarf::DW_FORM_GNU_str_index : dwarf::DW_FORM_strp;295 296 auto StringPoolEntry =297 useSegmentedStringOffsetsTable() || IxForm == dwarf::DW_FORM_GNU_str_index298 ? DU->getStringPool().getIndexedEntry(*Asm, String)299 : DU->getStringPool().getEntry(*Asm, String);300 301 // For DWARF v5 and beyond, use the smallest strx? form possible.302 if (useSegmentedStringOffsetsTable()) {303 IxForm = dwarf::DW_FORM_strx1;304 unsigned Index = StringPoolEntry.getIndex();305 if (Index > 0xffffff)306 IxForm = dwarf::DW_FORM_strx4;307 else if (Index > 0xffff)308 IxForm = dwarf::DW_FORM_strx3;309 else if (Index > 0xff)310 IxForm = dwarf::DW_FORM_strx2;311 }312 addAttribute(Die, Attribute, IxForm, DIEString(StringPoolEntry));313}314 315void DwarfUnit::addLabel(DIEValueList &Die, dwarf::Attribute Attribute,316 dwarf::Form Form, const MCSymbol *Label) {317 addAttribute(Die, Attribute, Form, DIELabel(Label));318}319 320void DwarfUnit::addLabel(DIELoc &Die, dwarf::Form Form, const MCSymbol *Label) {321 addLabel(Die, (dwarf::Attribute)0, Form, Label);322}323 324void DwarfUnit::addSectionOffset(DIE &Die, dwarf::Attribute Attribute,325 uint64_t Integer) {326 addUInt(Die, Attribute, DD->getDwarfSectionOffsetForm(), Integer);327}328 329unsigned DwarfTypeUnit::getOrCreateSourceID(const DIFile *File) {330 if (!SplitLineTable)331 return getCU().getOrCreateSourceID(File);332 if (!UsedLineTable) {333 UsedLineTable = true;334 // This is a split type unit that needs a line table.335 addSectionOffset(getUnitDie(), dwarf::DW_AT_stmt_list, 0);336 }337 return SplitLineTable->getFile(338 File->getDirectory(), File->getFilename(), DD->getMD5AsBytes(File),339 Asm->OutContext.getDwarfVersion(), File->getSource());340}341 342void DwarfUnit::addPoolOpAddress(DIEValueList &Die, const MCSymbol *Label) {343 bool UseAddrOffsetFormOrExpressions =344 DD->useAddrOffsetForm() || DD->useAddrOffsetExpressions();345 346 const MCSymbol *Base = nullptr;347 if (Label->isInSection() && UseAddrOffsetFormOrExpressions)348 Base = DD->getSectionLabel(&Label->getSection());349 350 uint32_t Index = DD->getAddressPool().getIndex(Base ? Base : Label);351 352 if (DD->getDwarfVersion() >= 5) {353 addUInt(Die, dwarf::DW_FORM_data1, dwarf::DW_OP_addrx);354 addUInt(Die, dwarf::DW_FORM_addrx, Index);355 } else {356 addUInt(Die, dwarf::DW_FORM_data1, dwarf::DW_OP_GNU_addr_index);357 addUInt(Die, dwarf::DW_FORM_GNU_addr_index, Index);358 }359 360 if (Base && Base != Label) {361 addUInt(Die, dwarf::DW_FORM_data1, dwarf::DW_OP_const4u);362 addLabelDelta(Die, (dwarf::Attribute)0, Label, Base);363 addUInt(Die, dwarf::DW_FORM_data1, dwarf::DW_OP_plus);364 }365}366 367void DwarfUnit::addOpAddress(DIELoc &Die, const MCSymbol *Sym) {368 if (DD->getDwarfVersion() >= 5) {369 addPoolOpAddress(Die, Sym);370 return;371 }372 373 if (DD->useSplitDwarf()) {374 addPoolOpAddress(Die, Sym);375 return;376 }377 378 addUInt(Die, dwarf::DW_FORM_data1, dwarf::DW_OP_addr);379 addLabel(Die, dwarf::DW_FORM_addr, Sym);380}381 382void DwarfUnit::addLabelDelta(DIEValueList &Die, dwarf::Attribute Attribute,383 const MCSymbol *Hi, const MCSymbol *Lo) {384 addAttribute(Die, Attribute, dwarf::DW_FORM_data4,385 new (DIEValueAllocator) DIEDelta(Hi, Lo));386}387 388void DwarfUnit::addDIEEntry(DIE &Die, dwarf::Attribute Attribute, DIE &Entry) {389 addDIEEntry(Die, Attribute, DIEEntry(Entry));390}391 392void DwarfUnit::addDIETypeSignature(DIE &Die, uint64_t Signature) {393 // Flag the type unit reference as a declaration so that if it contains394 // members (implicit special members, static data member definitions, member395 // declarations for definitions in this CU, etc) consumers don't get confused396 // and think this is a full definition.397 addFlag(Die, dwarf::DW_AT_declaration);398 399 addAttribute(Die, dwarf::DW_AT_signature, dwarf::DW_FORM_ref_sig8,400 DIEInteger(Signature));401}402 403void DwarfUnit::addDIEEntry(DIE &Die, dwarf::Attribute Attribute,404 DIEEntry Entry) {405 const DIEUnit *CU = Die.getUnit();406 const DIEUnit *EntryCU = Entry.getEntry().getUnit();407 if (!CU)408 // We assume that Die belongs to this CU, if it is not linked to any CU yet.409 CU = getUnitDie().getUnit();410 if (!EntryCU)411 EntryCU = getUnitDie().getUnit();412 assert(EntryCU == CU || !DD->useSplitDwarf() || DD->shareAcrossDWOCUs() ||413 !static_cast<const DwarfUnit*>(CU)->isDwoUnit());414 addAttribute(Die, Attribute,415 EntryCU == CU ? dwarf::DW_FORM_ref4 : dwarf::DW_FORM_ref_addr,416 Entry);417}418 419DIE &DwarfUnit::createAndAddDIE(dwarf::Tag Tag, DIE &Parent, const DINode *N) {420 DIE &Die = Parent.addChild(DIE::get(DIEValueAllocator, Tag));421 if (N)422 insertDIE(N, &Die);423 return Die;424}425 426void DwarfUnit::addBlock(DIE &Die, dwarf::Attribute Attribute, DIELoc *Loc) {427 Loc->computeSize(Asm->getDwarfFormParams());428 DIELocs.push_back(Loc); // Memoize so we can call the destructor later on.429 addAttribute(Die, Attribute, Loc->BestForm(DD->getDwarfVersion()), Loc);430}431 432void DwarfUnit::addBlock(DIE &Die, dwarf::Attribute Attribute, dwarf::Form Form,433 DIEBlock *Block) {434 Block->computeSize(Asm->getDwarfFormParams());435 DIEBlocks.push_back(Block); // Memoize so we can call the destructor later on.436 addAttribute(Die, Attribute, Form, Block);437}438 439void DwarfUnit::addBlock(DIE &Die, dwarf::Attribute Attribute,440 DIEBlock *Block) {441 addBlock(Die, Attribute, Block->BestForm(), Block);442}443 444void DwarfUnit::addBlock(DIE &Die, dwarf::Attribute Attribute,445 const DIExpression *Expr) {446 DIELoc *Loc = new (DIEValueAllocator) DIELoc;447 DIEDwarfExpression DwarfExpr(*Asm, getCU(), *Loc);448 DwarfExpr.setMemoryLocationKind();449 DwarfExpr.addExpression(Expr);450 addBlock(Die, Attribute, DwarfExpr.finalize());451}452 453void DwarfUnit::addSourceLine(DIE &Die, unsigned Line, unsigned Column,454 const DIFile *File) {455 if (Line == 0)456 return;457 458 unsigned FileID = getOrCreateSourceID(File);459 addUInt(Die, dwarf::DW_AT_decl_file, std::nullopt, FileID);460 addUInt(Die, dwarf::DW_AT_decl_line, std::nullopt, Line);461 462 if (Column != 0)463 addUInt(Die, dwarf::DW_AT_decl_column, std::nullopt, Column);464}465 466void DwarfUnit::addSourceLine(DIE &Die, const DILocalVariable *V) {467 assert(V);468 469 addSourceLine(Die, V->getLine(), /*Column*/ 0, V->getFile());470}471 472void DwarfUnit::addSourceLine(DIE &Die, const DIGlobalVariable *G) {473 assert(G);474 475 addSourceLine(Die, G->getLine(), /*Column*/ 0, G->getFile());476}477 478void DwarfUnit::addSourceLine(DIE &Die, const DISubprogram *SP) {479 assert(SP);480 481 addSourceLine(Die, SP->getLine(), /*Column*/ 0, SP->getFile());482}483 484void DwarfUnit::addSourceLine(DIE &Die, const DILabel *L) {485 assert(L);486 487 addSourceLine(Die, L->getLine(), L->getColumn(), L->getFile());488}489 490void DwarfUnit::addSourceLine(DIE &Die, const DIType *Ty) {491 assert(Ty);492 493 addSourceLine(Die, Ty->getLine(), /*Column*/ 0, Ty->getFile());494}495 496void DwarfUnit::addSourceLine(DIE &Die, const DIObjCProperty *Ty) {497 assert(Ty);498 499 addSourceLine(Die, Ty->getLine(), /*Column*/ 0, Ty->getFile());500}501 502void DwarfUnit::addConstantFPValue(DIE &Die, const ConstantFP *CFP) {503 // Pass this down to addConstantValue as an unsigned bag of bits.504 addConstantValue(Die, CFP->getValueAPF().bitcastToAPInt(), true);505}506 507void DwarfUnit::addConstantValue(DIE &Die, const ConstantInt *CI,508 const DIType *Ty) {509 addConstantValue(Die, CI->getValue(), Ty);510}511 512void DwarfUnit::addConstantValue(DIE &Die, uint64_t Val, const DIType *Ty) {513 addConstantValue(Die, DD->isUnsignedDIType(Ty), Val);514}515 516void DwarfUnit::addConstantValue(DIE &Die, bool Unsigned, uint64_t Val) {517 // FIXME: This is a bit conservative/simple - it emits negative values always518 // sign extended to 64 bits rather than minimizing the number of bytes.519 addUInt(Die, dwarf::DW_AT_const_value,520 Unsigned ? dwarf::DW_FORM_udata : dwarf::DW_FORM_sdata, Val);521}522 523void DwarfUnit::addConstantValue(DIE &Die, const APInt &Val, const DIType *Ty) {524 addConstantValue(Die, Val, DD->isUnsignedDIType(Ty));525}526 527void DwarfUnit::addConstantValue(DIE &Die, const APInt &Val, bool Unsigned) {528 unsigned CIBitWidth = Val.getBitWidth();529 if (CIBitWidth <= 64) {530 addConstantValue(Die, Unsigned,531 Unsigned ? Val.getZExtValue() : Val.getSExtValue());532 return;533 }534 535 addIntAsBlock(Die, dwarf::DW_AT_const_value, Val);536}537 538void DwarfUnit::addLinkageName(DIE &Die, StringRef LinkageName) {539 if (!LinkageName.empty())540 addString(Die,541 DD->getDwarfVersion() >= 4 ? dwarf::DW_AT_linkage_name542 : dwarf::DW_AT_MIPS_linkage_name,543 GlobalValue::dropLLVMManglingEscape(LinkageName));544}545 546void DwarfUnit::addTemplateParams(DIE &Buffer, DINodeArray TParams) {547 // Add template parameters.548 for (const auto *Element : TParams) {549 if (auto *TTP = dyn_cast<DITemplateTypeParameter>(Element))550 constructTemplateTypeParameterDIE(Buffer, TTP);551 else if (auto *TVP = dyn_cast<DITemplateValueParameter>(Element))552 constructTemplateValueParameterDIE(Buffer, TVP);553 }554}555 556/// Add thrown types.557void DwarfUnit::addThrownTypes(DIE &Die, DINodeArray ThrownTypes) {558 for (const auto *Ty : ThrownTypes) {559 DIE &TT = createAndAddDIE(dwarf::DW_TAG_thrown_type, Die);560 addType(TT, cast<DIType>(Ty));561 }562}563 564void DwarfUnit::addAccess(DIE &Die, DINode::DIFlags Flags) {565 if ((Flags & DINode::FlagAccessibility) == DINode::FlagProtected)566 addUInt(Die, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,567 dwarf::DW_ACCESS_protected);568 else if ((Flags & DINode::FlagAccessibility) == DINode::FlagPrivate)569 addUInt(Die, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,570 dwarf::DW_ACCESS_private);571 else if ((Flags & DINode::FlagAccessibility) == DINode::FlagPublic)572 addUInt(Die, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,573 dwarf::DW_ACCESS_public);574}575 576DIE *DwarfUnit::getOrCreateContextDIE(const DIScope *Context) {577 if (!Context || isa<DIFile>(Context) || isa<DICompileUnit>(Context))578 return &getUnitDie();579 if (auto *T = dyn_cast<DIType>(Context))580 return getOrCreateTypeDIE(T);581 if (auto *NS = dyn_cast<DINamespace>(Context))582 return getOrCreateNameSpace(NS);583 if (auto *SP = dyn_cast<DISubprogram>(Context))584 return getOrCreateSubprogramDIE(SP, nullptr);585 if (auto *M = dyn_cast<DIModule>(Context))586 return getOrCreateModule(M);587 return getDIE(Context);588}589 590DIE *DwarfUnit::createTypeDIE(const DICompositeType *Ty) {591 auto *Context = Ty->getScope();592 DIE *ContextDIE = getOrCreateContextDIE(Context);593 594 if (DIE *TyDIE = getDIE(Ty))595 return TyDIE;596 597 // Create new type.598 DIE &TyDIE = createAndAddDIE(Ty->getTag(), *ContextDIE, Ty);599 600 constructTypeDIE(TyDIE, cast<DICompositeType>(Ty));601 602 updateAcceleratorTables(Context, Ty, TyDIE);603 return &TyDIE;604}605 606DIE *DwarfUnit::createTypeDIE(const DIScope *Context, DIE &ContextDIE,607 const DIType *Ty) {608 // Create new type.609 DIE &TyDIE = createAndAddDIE(Ty->getTag(), ContextDIE, Ty);610 611 auto construct = [&](const auto *Ty) {612 updateAcceleratorTables(Context, Ty, TyDIE);613 constructTypeDIE(TyDIE, Ty);614 };615 616 if (auto *CTy = dyn_cast<DICompositeType>(Ty)) {617 if (DD->generateTypeUnits() && !Ty->isForwardDecl() &&618 (Ty->getRawName() || CTy->getRawIdentifier())) {619 // Skip updating the accelerator tables since this is not the full type.620 if (MDString *TypeId = CTy->getRawIdentifier()) {621 addGlobalType(Ty, TyDIE, Context);622 DD->addDwarfTypeUnitType(getCU(), TypeId->getString(), TyDIE, CTy);623 } else {624 updateAcceleratorTables(Context, Ty, TyDIE);625 finishNonUnitTypeDIE(TyDIE, CTy);626 }627 return &TyDIE;628 }629 construct(CTy);630 } else if (auto *FPT = dyn_cast<DIFixedPointType>(Ty))631 construct(FPT);632 else if (auto *BT = dyn_cast<DIBasicType>(Ty))633 construct(BT);634 else if (auto *ST = dyn_cast<DIStringType>(Ty))635 construct(ST);636 else if (auto *STy = dyn_cast<DISubroutineType>(Ty))637 construct(STy);638 else if (auto *SRTy = dyn_cast<DISubrangeType>(Ty))639 constructSubrangeDIE(TyDIE, SRTy);640 else641 construct(cast<DIDerivedType>(Ty));642 643 return &TyDIE;644}645 646DIE *DwarfUnit::getOrCreateTypeDIE(const MDNode *TyNode) {647 if (!TyNode)648 return nullptr;649 650 auto *Ty = cast<DIType>(TyNode);651 652 // DW_TAG_restrict_type is not supported in DWARF2653 if (Ty->getTag() == dwarf::DW_TAG_restrict_type && DD->getDwarfVersion() <= 2)654 return getOrCreateTypeDIE(cast<DIDerivedType>(Ty)->getBaseType());655 656 // DW_TAG_atomic_type is not supported in DWARF < 5657 if (Ty->getTag() == dwarf::DW_TAG_atomic_type && DD->getDwarfVersion() < 5)658 return getOrCreateTypeDIE(cast<DIDerivedType>(Ty)->getBaseType());659 660 // Construct the context before querying for the existence of the DIE in case661 // such construction creates the DIE.662 auto *Context = Ty->getScope();663 DIE *ContextDIE = getOrCreateContextDIE(Context);664 assert(ContextDIE);665 666 if (DIE *TyDIE = getDIE(Ty))667 return TyDIE;668 669 return static_cast<DwarfUnit *>(ContextDIE->getUnit())670 ->createTypeDIE(Context, *ContextDIE, Ty);671}672 673void DwarfUnit::updateAcceleratorTables(const DIScope *Context,674 const DIType *Ty, const DIE &TyDIE) {675 if (Ty->getName().empty())676 return;677 if (Ty->isForwardDecl())678 return;679 680 // add temporary record for this type to be added later681 682 unsigned Flags = 0;683 if (auto *CT = dyn_cast<DICompositeType>(Ty)) {684 // A runtime language of 0 actually means C/C++ and that any685 // non-negative value is some version of Objective-C/C++.686 if (CT->getRuntimeLang() == 0 || CT->isObjcClassComplete())687 Flags = dwarf::DW_FLAG_type_implementation;688 }689 690 DD->addAccelType(*this, CUNode->getNameTableKind(), Ty->getName(), TyDIE,691 Flags);692 693 if (auto *CT = dyn_cast<DICompositeType>(Ty))694 if (Ty->getName() != CT->getIdentifier() &&695 CT->getRuntimeLang() == dwarf::DW_LANG_Swift)696 DD->addAccelType(*this, CUNode->getNameTableKind(), CT->getIdentifier(),697 TyDIE, Flags);698 699 addGlobalType(Ty, TyDIE, Context);700}701 702void DwarfUnit::addGlobalType(const DIType *Ty, const DIE &TyDIE,703 const DIScope *Context) {704 if (!Context || isa<DICompileUnit>(Context) || isa<DIFile>(Context) ||705 isa<DINamespace>(Context) || isa<DICommonBlock>(Context))706 addGlobalTypeImpl(Ty, TyDIE, Context);707}708 709void DwarfUnit::addType(DIE &Entity, const DIType *Ty,710 dwarf::Attribute Attribute) {711 assert(Ty && "Trying to add a type that doesn't exist?");712 addDIEEntry(Entity, Attribute, DIEEntry(*getOrCreateTypeDIE(Ty)));713}714 715// FIXME: change callsites to use the new DW_LNAME_ language codes.716llvm::dwarf::SourceLanguage DwarfUnit::getSourceLanguage() const {717 const auto &Lang = getLanguage();718 719 if (!Lang.hasVersionedName())720 return static_cast<llvm::dwarf::SourceLanguage>(Lang.getName());721 722 return llvm::dwarf::toDW_LANG(723 static_cast<llvm::dwarf::SourceLanguageName>(Lang.getName()),724 Lang.getVersion())725 .value_or(llvm::dwarf::DW_LANG_hi_user);726}727 728std::string DwarfUnit::getParentContextString(const DIScope *Context) const {729 if (!Context)730 return "";731 732 // FIXME: Decide whether to implement this for non-C++ languages.733 if (!dwarf::isCPlusPlus(getSourceLanguage()))734 return "";735 736 std::string CS;737 SmallVector<const DIScope *, 1> Parents;738 while (!isa<DICompileUnit>(Context)) {739 Parents.push_back(Context);740 if (const DIScope *S = Context->getScope())741 Context = S;742 else743 // Structure, etc types will have a NULL context if they're at the top744 // level.745 break;746 }747 748 // Reverse iterate over our list to go from the outermost construct to the749 // innermost.750 for (const DIScope *Ctx : llvm::reverse(Parents)) {751 StringRef Name = Ctx->getName();752 if (Name.empty() && isa<DINamespace>(Ctx))753 Name = "(anonymous namespace)";754 if (!Name.empty()) {755 CS += Name;756 CS += "::";757 }758 }759 return CS;760}761 762void DwarfUnit::constructTypeDIE(DIE &Buffer, const DIBasicType *BTy) {763 // Get core information.764 StringRef Name = BTy->getName();765 // Add name if not anonymous or intermediate type.766 if (!Name.empty())767 addString(Buffer, dwarf::DW_AT_name, Name);768 769 // An unspecified type only has a name attribute.770 if (BTy->getTag() == dwarf::DW_TAG_unspecified_type)771 return;772 773 if (BTy->getTag() != dwarf::DW_TAG_string_type)774 addUInt(Buffer, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1,775 BTy->getEncoding());776 777 uint64_t SizeInBytes = divideCeil(BTy->getSizeInBits(), 8);778 addUInt(Buffer, dwarf::DW_AT_byte_size, std::nullopt, SizeInBytes);779 if (BTy->getTag() == dwarf::Tag::DW_TAG_base_type) {780 // DW_TAG_base_type:781 // If the value of an object of the given type does not fully occupy the782 // storage described by a byte size attribute, the base type entry may also783 // have a DW_AT_bit_size [...] attribute.784 // TODO: Do big endian targets need DW_AT_data_bit_offset? See discussion in785 // pull request #164372.786 if (uint64_t DataSizeInBits = BTy->getDataSizeInBits();787 DataSizeInBits && DataSizeInBits != SizeInBytes * 8)788 addUInt(Buffer, dwarf::DW_AT_bit_size, std::nullopt, DataSizeInBits);789 }790 791 if (BTy->isBigEndian())792 addUInt(Buffer, dwarf::DW_AT_endianity, std::nullopt, dwarf::DW_END_big);793 else if (BTy->isLittleEndian())794 addUInt(Buffer, dwarf::DW_AT_endianity, std::nullopt, dwarf::DW_END_little);795 796 if (uint32_t NumExtraInhabitants = BTy->getNumExtraInhabitants())797 addUInt(Buffer, dwarf::DW_AT_LLVM_num_extra_inhabitants, std::nullopt,798 NumExtraInhabitants);799}800 801void DwarfUnit::constructTypeDIE(DIE &Buffer, const DIFixedPointType *BTy) {802 // Base type handling.803 constructTypeDIE(Buffer, static_cast<const DIBasicType *>(BTy));804 805 if (BTy->isBinary())806 addSInt(Buffer, dwarf::DW_AT_binary_scale, dwarf::DW_FORM_sdata,807 BTy->getFactor());808 else if (BTy->isDecimal())809 addSInt(Buffer, dwarf::DW_AT_decimal_scale, dwarf::DW_FORM_sdata,810 BTy->getFactor());811 else {812 assert(BTy->isRational());813 DIE *ContextDIE = getOrCreateContextDIE(BTy->getScope());814 DIE &Constant = createAndAddDIE(dwarf::DW_TAG_constant, *ContextDIE);815 816 addInt(Constant, dwarf::DW_AT_GNU_numerator, BTy->getNumerator(),817 !BTy->isSigned());818 addInt(Constant, dwarf::DW_AT_GNU_denominator, BTy->getDenominator(),819 !BTy->isSigned());820 821 addDIEEntry(Buffer, dwarf::DW_AT_small, Constant);822 }823}824 825void DwarfUnit::constructTypeDIE(DIE &Buffer, const DIStringType *STy) {826 // Get core information.827 StringRef Name = STy->getName();828 // Add name if not anonymous or intermediate type.829 if (!Name.empty())830 addString(Buffer, dwarf::DW_AT_name, Name);831 832 if (DIVariable *Var = STy->getStringLength()) {833 if (auto *VarDIE = getDIE(Var))834 addDIEEntry(Buffer, dwarf::DW_AT_string_length, *VarDIE);835 } else if (DIExpression *Expr = STy->getStringLengthExp()) {836 addBlock(Buffer, dwarf::DW_AT_string_length, Expr);837 } else {838 uint64_t Size = STy->getSizeInBits() >> 3;839 addUInt(Buffer, dwarf::DW_AT_byte_size, std::nullopt, Size);840 }841 842 if (DIExpression *Expr = STy->getStringLocationExp()) {843 addBlock(Buffer, dwarf::DW_AT_data_location, Expr);844 }845 846 if (STy->getEncoding()) {847 // For eventual Unicode support.848 addUInt(Buffer, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1,849 STy->getEncoding());850 }851}852 853void DwarfUnit::constructTypeDIE(DIE &Buffer, const DIDerivedType *DTy) {854 // Get core information.855 StringRef Name = DTy->getName();856 uint64_t Size = DTy->getSizeInBits() >> 3;857 uint16_t Tag = Buffer.getTag();858 859 // Map to main type, void will not have a type.860 const DIType *FromTy = DTy->getBaseType();861 if (FromTy)862 addType(Buffer, FromTy);863 864 // Add name if not anonymous or intermediate type.865 if (!Name.empty())866 addString(Buffer, dwarf::DW_AT_name, Name);867 868 addAnnotation(Buffer, DTy->getAnnotations());869 870 // If alignment is specified for a typedef , create and insert DW_AT_alignment871 // attribute in DW_TAG_typedef DIE.872 if (Tag == dwarf::DW_TAG_typedef && DD->getDwarfVersion() >= 5) {873 uint32_t AlignInBytes = DTy->getAlignInBytes();874 if (AlignInBytes > 0)875 addUInt(Buffer, dwarf::DW_AT_alignment, dwarf::DW_FORM_udata,876 AlignInBytes);877 }878 879 // Add size if non-zero (derived types might be zero-sized.)880 if (Size && Tag != dwarf::DW_TAG_pointer_type881 && Tag != dwarf::DW_TAG_ptr_to_member_type882 && Tag != dwarf::DW_TAG_reference_type883 && Tag != dwarf::DW_TAG_rvalue_reference_type)884 addUInt(Buffer, dwarf::DW_AT_byte_size, std::nullopt, Size);885 886 if (Tag == dwarf::DW_TAG_ptr_to_member_type)887 addDIEEntry(Buffer, dwarf::DW_AT_containing_type,888 *getOrCreateTypeDIE(cast<DIDerivedType>(DTy)->getClassType()));889 890 addAccess(Buffer, DTy->getFlags());891 892 // Add source line info if available and TyDesc is not a forward declaration.893 if (!DTy->isForwardDecl())894 addSourceLine(Buffer, DTy);895 896 // If DWARF address space value is other than None, add it. The IR897 // verifier checks that DWARF address space only exists for pointer898 // or reference types.899 if (DTy->getDWARFAddressSpace())900 addUInt(Buffer, dwarf::DW_AT_address_class, dwarf::DW_FORM_data4,901 *DTy->getDWARFAddressSpace());902 903 // Add template alias template parameters.904 if (Tag == dwarf::DW_TAG_template_alias)905 addTemplateParams(Buffer, DTy->getTemplateParams());906 907 if (auto PtrAuthData = DTy->getPtrAuthData()) {908 addUInt(Buffer, dwarf::DW_AT_LLVM_ptrauth_key, dwarf::DW_FORM_data1,909 PtrAuthData->key());910 if (PtrAuthData->isAddressDiscriminated())911 addFlag(Buffer, dwarf::DW_AT_LLVM_ptrauth_address_discriminated);912 addUInt(Buffer, dwarf::DW_AT_LLVM_ptrauth_extra_discriminator,913 dwarf::DW_FORM_data2, PtrAuthData->extraDiscriminator());914 if (PtrAuthData->isaPointer())915 addFlag(Buffer, dwarf::DW_AT_LLVM_ptrauth_isa_pointer);916 if (PtrAuthData->authenticatesNullValues())917 addFlag(Buffer, dwarf::DW_AT_LLVM_ptrauth_authenticates_null_values);918 }919}920 921std::optional<unsigned>922DwarfUnit::constructSubprogramArguments(DIE &Buffer, DITypeRefArray Args) {923 // Args[0] is the return type.924 std::optional<unsigned> ObjectPointerIndex;925 for (unsigned i = 1, N = Args.size(); i < N; ++i) {926 const DIType *Ty = Args[i];927 if (!Ty) {928 assert(i == N-1 && "Unspecified parameter must be the last argument");929 createAndAddDIE(dwarf::DW_TAG_unspecified_parameters, Buffer);930 } else {931 DIE &Arg = createAndAddDIE(dwarf::DW_TAG_formal_parameter, Buffer);932 addType(Arg, Ty);933 if (Ty->isArtificial())934 addFlag(Arg, dwarf::DW_AT_artificial);935 936 if (Ty->isObjectPointer()) {937 assert(!ObjectPointerIndex &&938 "Can't have more than one object pointer");939 ObjectPointerIndex = i;940 }941 }942 }943 944 return ObjectPointerIndex;945}946 947void DwarfUnit::constructTypeDIE(DIE &Buffer, const DISubroutineType *CTy) {948 // Add return type. A void return won't have a type.949 auto Elements = cast<DISubroutineType>(CTy)->getTypeArray();950 if (Elements.size())951 if (auto RTy = Elements[0])952 addType(Buffer, RTy);953 954 bool isPrototyped = true;955 if (Elements.size() == 2 && !Elements[1])956 isPrototyped = false;957 958 constructSubprogramArguments(Buffer, Elements);959 960 // Add prototype flag if we're dealing with a C language and the function has961 // been prototyped.962 if (isPrototyped && dwarf::isC(getSourceLanguage()))963 addFlag(Buffer, dwarf::DW_AT_prototyped);964 965 // Add a DW_AT_calling_convention if this has an explicit convention.966 if (CTy->getCC() && CTy->getCC() != dwarf::DW_CC_normal)967 addUInt(Buffer, dwarf::DW_AT_calling_convention, dwarf::DW_FORM_data1,968 CTy->getCC());969 970 if (CTy->isLValueReference())971 addFlag(Buffer, dwarf::DW_AT_reference);972 973 if (CTy->isRValueReference())974 addFlag(Buffer, dwarf::DW_AT_rvalue_reference);975}976 977void DwarfUnit::addAnnotation(DIE &Buffer, DINodeArray Annotations) {978 if (!Annotations)979 return;980 981 for (const Metadata *Annotation : Annotations->operands()) {982 const MDNode *MD = cast<MDNode>(Annotation);983 const MDString *Name = cast<MDString>(MD->getOperand(0));984 const auto &Value = MD->getOperand(1);985 986 DIE &AnnotationDie = createAndAddDIE(dwarf::DW_TAG_LLVM_annotation, Buffer);987 addString(AnnotationDie, dwarf::DW_AT_name, Name->getString());988 if (const auto *Data = dyn_cast<MDString>(Value))989 addString(AnnotationDie, dwarf::DW_AT_const_value, Data->getString());990 else if (const auto *Data = dyn_cast<ConstantAsMetadata>(Value))991 addConstantValue(AnnotationDie, Data->getValue()->getUniqueInteger(),992 /*Unsigned=*/true);993 else994 assert(false && "Unsupported annotation value type");995 }996}997 998void DwarfUnit::addDiscriminant(DIE &Variant, Constant *Discriminant,999 bool IsUnsigned) {1000 if (const auto *CI = dyn_cast_or_null<ConstantInt>(Discriminant)) {1001 addInt(Variant, dwarf::DW_AT_discr_value, CI->getValue(), IsUnsigned);1002 } else if (const auto *CA =1003 dyn_cast_or_null<ConstantDataArray>(Discriminant)) {1004 // Must have an even number of operands.1005 unsigned NElems = CA->getNumElements();1006 if (NElems % 2 != 0) {1007 return;1008 }1009 1010 DIEBlock *Block = new (DIEValueAllocator) DIEBlock;1011 1012 auto AddInt = [&](const APInt &Val) {1013 if (IsUnsigned)1014 addUInt(*Block, dwarf::DW_FORM_udata, Val.getZExtValue());1015 else1016 addSInt(*Block, dwarf::DW_FORM_sdata, Val.getSExtValue());1017 };1018 1019 for (unsigned I = 0; I < NElems; I += 2) {1020 APInt LV = CA->getElementAsAPInt(I);1021 APInt HV = CA->getElementAsAPInt(I + 1);1022 if (LV == HV) {1023 addUInt(*Block, dwarf::DW_FORM_data1, dwarf::DW_DSC_label);1024 AddInt(LV);1025 } else {1026 addUInt(*Block, dwarf::DW_FORM_data1, dwarf::DW_DSC_range);1027 AddInt(LV);1028 AddInt(HV);1029 }1030 }1031 addBlock(Variant, dwarf::DW_AT_discr_list, Block);1032 }1033}1034 1035void DwarfUnit::constructTypeDIE(DIE &Buffer, const DICompositeType *CTy) {1036 // Add name if not anonymous or intermediate type.1037 StringRef Name = CTy->getName();1038 1039 uint16_t Tag = Buffer.getTag();1040 1041 switch (Tag) {1042 case dwarf::DW_TAG_array_type:1043 constructArrayTypeDIE(Buffer, CTy);1044 break;1045 case dwarf::DW_TAG_enumeration_type:1046 constructEnumTypeDIE(Buffer, CTy);1047 break;1048 case dwarf::DW_TAG_variant_part:1049 case dwarf::DW_TAG_variant:1050 case dwarf::DW_TAG_structure_type:1051 case dwarf::DW_TAG_union_type:1052 case dwarf::DW_TAG_class_type:1053 case dwarf::DW_TAG_namelist: {1054 // Emit the discriminator for a variant part.1055 DIDerivedType *Discriminator = nullptr;1056 if (Tag == dwarf::DW_TAG_variant_part) {1057 Discriminator = CTy->getDiscriminator();1058 if (Discriminator) {1059 // DWARF says:1060 // If the variant part has a discriminant, the discriminant is1061 // represented by a separate debugging information entry which is1062 // a child of the variant part entry.1063 // However, for a language like Ada, this yields a weird1064 // result: a discriminant field would have to be emitted1065 // multiple times, once per variant part. Instead, this DWARF1066 // restriction was lifted for DWARF 6 (see1067 // https://dwarfstd.org/issues/180123.1.html) and so we allow1068 // this here.1069 DIE *DiscDIE = getDIE(Discriminator);1070 if (DiscDIE == nullptr) {1071 DiscDIE = &constructMemberDIE(Buffer, Discriminator);1072 }1073 addDIEEntry(Buffer, dwarf::DW_AT_discr, *DiscDIE);1074 }1075 }1076 1077 // Add template parameters to a class, structure or union types.1078 if (Tag == dwarf::DW_TAG_class_type ||1079 Tag == dwarf::DW_TAG_structure_type || Tag == dwarf::DW_TAG_union_type)1080 addTemplateParams(Buffer, CTy->getTemplateParams());1081 1082 // Add elements to structure type.1083 DINodeArray Elements = CTy->getElements();1084 for (const auto *Element : Elements) {1085 if (!Element)1086 continue;1087 if (auto *SP = dyn_cast<DISubprogram>(Element))1088 getOrCreateSubprogramDIE(SP, nullptr);1089 else if (auto *DDTy = dyn_cast<DIDerivedType>(Element)) {1090 if (DDTy->getTag() == dwarf::DW_TAG_friend) {1091 DIE &ElemDie = createAndAddDIE(dwarf::DW_TAG_friend, Buffer);1092 addType(ElemDie, DDTy->getBaseType(), dwarf::DW_AT_friend);1093 } else if (DDTy->isStaticMember()) {1094 getOrCreateStaticMemberDIE(DDTy);1095 } else if (Tag == dwarf::DW_TAG_variant_part) {1096 // When emitting a variant part, wrap each member in1097 // DW_TAG_variant.1098 DIE &Variant = createAndAddDIE(dwarf::DW_TAG_variant, Buffer);1099 if (Constant *CI = DDTy->getDiscriminantValue()) {1100 addDiscriminant(Variant, CI,1101 DD->isUnsignedDIType(Discriminator->getBaseType()));1102 }1103 // If the variant holds a composite type with tag1104 // DW_TAG_variant, inline those members into the variant1105 // DIE.1106 if (auto *Composite =1107 dyn_cast_or_null<DICompositeType>(DDTy->getBaseType());1108 Composite != nullptr &&1109 Composite->getTag() == dwarf::DW_TAG_variant) {1110 constructTypeDIE(Variant, Composite);1111 } else {1112 constructMemberDIE(Variant, DDTy);1113 }1114 } else {1115 constructMemberDIE(Buffer, DDTy);1116 }1117 } else if (auto *Property = dyn_cast<DIObjCProperty>(Element)) {1118 DIE &ElemDie = createAndAddDIE(Property->getTag(), Buffer, Property);1119 StringRef PropertyName = Property->getName();1120 addString(ElemDie, dwarf::DW_AT_APPLE_property_name, PropertyName);1121 if (Property->getType())1122 addType(ElemDie, Property->getType());1123 addSourceLine(ElemDie, Property);1124 StringRef GetterName = Property->getGetterName();1125 if (!GetterName.empty())1126 addString(ElemDie, dwarf::DW_AT_APPLE_property_getter, GetterName);1127 StringRef SetterName = Property->getSetterName();1128 if (!SetterName.empty())1129 addString(ElemDie, dwarf::DW_AT_APPLE_property_setter, SetterName);1130 if (unsigned PropertyAttributes = Property->getAttributes())1131 addUInt(ElemDie, dwarf::DW_AT_APPLE_property_attribute, std::nullopt,1132 PropertyAttributes);1133 } else if (auto *Composite = dyn_cast<DICompositeType>(Element)) {1134 if (Composite->getTag() == dwarf::DW_TAG_variant_part) {1135 DIE &VariantPart = createAndAddDIE(Composite->getTag(), Buffer);1136 constructTypeDIE(VariantPart, Composite);1137 }1138 } else if (Tag == dwarf::DW_TAG_namelist) {1139 auto *Var = dyn_cast<DINode>(Element);1140 auto *VarDIE = getDIE(Var);1141 if (VarDIE) {1142 DIE &ItemDie = createAndAddDIE(dwarf::DW_TAG_namelist_item, Buffer);1143 addDIEEntry(ItemDie, dwarf::DW_AT_namelist_item, *VarDIE);1144 }1145 }1146 }1147 1148 if (CTy->isAppleBlockExtension())1149 addFlag(Buffer, dwarf::DW_AT_APPLE_block);1150 1151 if (CTy->getExportSymbols())1152 addFlag(Buffer, dwarf::DW_AT_export_symbols);1153 1154 // This is outside the DWARF spec, but GDB expects a DW_AT_containing_type1155 // inside C++ composite types to point to the base class with the vtable.1156 // Rust uses DW_AT_containing_type to link a vtable to the type1157 // for which it was created.1158 if (auto *ContainingType = CTy->getVTableHolder())1159 addDIEEntry(Buffer, dwarf::DW_AT_containing_type,1160 *getOrCreateTypeDIE(ContainingType));1161 1162 if (CTy->isObjcClassComplete())1163 addFlag(Buffer, dwarf::DW_AT_APPLE_objc_complete_type);1164 1165 // Add the type's non-standard calling convention.1166 // DW_CC_pass_by_value/DW_CC_pass_by_reference are introduced in DWARF 5.1167 if (!Asm->TM.Options.DebugStrictDwarf || DD->getDwarfVersion() >= 5) {1168 uint8_t CC = 0;1169 if (CTy->isTypePassByValue())1170 CC = dwarf::DW_CC_pass_by_value;1171 else if (CTy->isTypePassByReference())1172 CC = dwarf::DW_CC_pass_by_reference;1173 if (CC)1174 addUInt(Buffer, dwarf::DW_AT_calling_convention, dwarf::DW_FORM_data1,1175 CC);1176 }1177 1178 if (auto *SpecifiedFrom = CTy->getSpecification())1179 addDIEEntry(Buffer, dwarf::DW_AT_specification,1180 *getOrCreateContextDIE(SpecifiedFrom));1181 1182 break;1183 }1184 default:1185 break;1186 }1187 1188 // Add name if not anonymous or intermediate type.1189 if (!Name.empty())1190 addString(Buffer, dwarf::DW_AT_name, Name);1191 1192 // For Swift, mangled names are put into DW_AT_linkage_name.1193 if (CTy->getRuntimeLang() == dwarf::DW_LANG_Swift && CTy->getRawIdentifier())1194 addString(Buffer, dwarf::DW_AT_linkage_name, CTy->getIdentifier());1195 1196 addAnnotation(Buffer, CTy->getAnnotations());1197 1198 if (Tag == dwarf::DW_TAG_enumeration_type ||1199 Tag == dwarf::DW_TAG_class_type || Tag == dwarf::DW_TAG_structure_type ||1200 Tag == dwarf::DW_TAG_union_type) {1201 if (auto *Var = dyn_cast_or_null<DIVariable>(CTy->getRawSizeInBits())) {1202 if (auto *VarDIE = getDIE(Var))1203 addDIEEntry(Buffer, dwarf::DW_AT_bit_size, *VarDIE);1204 } else if (auto *Exp =1205 dyn_cast_or_null<DIExpression>(CTy->getRawSizeInBits())) {1206 addBlock(Buffer, dwarf::DW_AT_bit_size, Exp);1207 } else {1208 uint64_t Size = CTy->getSizeInBits() >> 3;1209 // Add size if non-zero (derived types might be zero-sized.)1210 // Ignore the size if it's a non-enum forward decl.1211 // TODO: Do we care about size for enum forward declarations?1212 if (Size &&1213 (!CTy->isForwardDecl() || Tag == dwarf::DW_TAG_enumeration_type))1214 addUInt(Buffer, dwarf::DW_AT_byte_size, std::nullopt, Size);1215 else if (!CTy->isForwardDecl())1216 // Add zero size if it is not a forward declaration.1217 addUInt(Buffer, dwarf::DW_AT_byte_size, std::nullopt, 0);1218 }1219 1220 // If we're a forward decl, say so.1221 if (CTy->isForwardDecl())1222 addFlag(Buffer, dwarf::DW_AT_declaration);1223 1224 // Add accessibility info if available.1225 addAccess(Buffer, CTy->getFlags());1226 1227 // Add source line info if available.1228 if (!CTy->isForwardDecl())1229 addSourceLine(Buffer, CTy);1230 1231 // No harm in adding the runtime language to the declaration.1232 unsigned RLang = CTy->getRuntimeLang();1233 if (RLang)1234 addUInt(Buffer, dwarf::DW_AT_APPLE_runtime_class, dwarf::DW_FORM_data1,1235 RLang);1236 1237 // Add align info if available.1238 if (uint32_t AlignInBytes = CTy->getAlignInBytes())1239 addUInt(Buffer, dwarf::DW_AT_alignment, dwarf::DW_FORM_udata,1240 AlignInBytes);1241 1242 if (uint32_t NumExtraInhabitants = CTy->getNumExtraInhabitants())1243 addUInt(Buffer, dwarf::DW_AT_LLVM_num_extra_inhabitants, std::nullopt,1244 NumExtraInhabitants);1245 }1246}1247 1248void DwarfUnit::constructTemplateTypeParameterDIE(1249 DIE &Buffer, const DITemplateTypeParameter *TP) {1250 DIE &ParamDIE =1251 createAndAddDIE(dwarf::DW_TAG_template_type_parameter, Buffer);1252 // Add the type if it exists, it could be void and therefore no type.1253 if (TP->getType())1254 addType(ParamDIE, TP->getType());1255 if (!TP->getName().empty())1256 addString(ParamDIE, dwarf::DW_AT_name, TP->getName());1257 if (TP->isDefault() && isCompatibleWithVersion(5))1258 addFlag(ParamDIE, dwarf::DW_AT_default_value);1259}1260 1261void DwarfUnit::constructTemplateValueParameterDIE(1262 DIE &Buffer, const DITemplateValueParameter *VP) {1263 DIE &ParamDIE = createAndAddDIE(VP->getTag(), Buffer);1264 1265 // Add the type if there is one, template template and template parameter1266 // packs will not have a type.1267 if (VP->getTag() == dwarf::DW_TAG_template_value_parameter)1268 addType(ParamDIE, VP->getType());1269 if (!VP->getName().empty())1270 addString(ParamDIE, dwarf::DW_AT_name, VP->getName());1271 if (VP->isDefault() && isCompatibleWithVersion(5))1272 addFlag(ParamDIE, dwarf::DW_AT_default_value);1273 if (Metadata *Val = VP->getValue()) {1274 if (ConstantInt *CI = mdconst::dyn_extract<ConstantInt>(Val))1275 addConstantValue(ParamDIE, CI, VP->getType());1276 else if (ConstantFP *CF = mdconst::dyn_extract<ConstantFP>(Val))1277 addConstantFPValue(ParamDIE, CF);1278 else if (GlobalValue *GV = mdconst::dyn_extract<GlobalValue>(Val)) {1279 // We cannot describe the location of dllimport'd entities: the1280 // computation of their address requires loads from the IAT.1281 if (!GV->hasDLLImportStorageClass()) {1282 // For declaration non-type template parameters (such as global values1283 // and functions)1284 DIELoc *Loc = new (DIEValueAllocator) DIELoc;1285 addOpAddress(*Loc, Asm->getSymbol(GV));1286 // Emit DW_OP_stack_value to use the address as the immediate value of1287 // the parameter, rather than a pointer to it.1288 addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_stack_value);1289 addBlock(ParamDIE, dwarf::DW_AT_location, Loc);1290 }1291 } else if (VP->getTag() == dwarf::DW_TAG_GNU_template_template_param) {1292 assert(isa<MDString>(Val));1293 addString(ParamDIE, dwarf::DW_AT_GNU_template_name,1294 cast<MDString>(Val)->getString());1295 } else if (VP->getTag() == dwarf::DW_TAG_GNU_template_parameter_pack) {1296 addTemplateParams(ParamDIE, cast<MDTuple>(Val));1297 }1298 }1299}1300 1301DIE *DwarfUnit::getOrCreateNameSpace(const DINamespace *NS) {1302 // Construct the context before querying for the existence of the DIE in case1303 // such construction creates the DIE.1304 DIE *ContextDIE = getOrCreateContextDIE(NS->getScope());1305 1306 if (DIE *NDie = getDIE(NS))1307 return NDie;1308 DIE &NDie = createAndAddDIE(dwarf::DW_TAG_namespace, *ContextDIE, NS);1309 1310 StringRef Name = NS->getName();1311 if (!Name.empty())1312 addString(NDie, dwarf::DW_AT_name, NS->getName());1313 else1314 Name = "(anonymous namespace)";1315 DD->addAccelNamespace(*this, CUNode->getNameTableKind(), Name, NDie);1316 addGlobalName(Name, NDie, NS->getScope());1317 if (NS->getExportSymbols())1318 addFlag(NDie, dwarf::DW_AT_export_symbols);1319 return &NDie;1320}1321 1322DIE *DwarfUnit::getOrCreateModule(const DIModule *M) {1323 // Construct the context before querying for the existence of the DIE in case1324 // such construction creates the DIE.1325 DIE *ContextDIE = getOrCreateContextDIE(M->getScope());1326 1327 if (DIE *MDie = getDIE(M))1328 return MDie;1329 DIE &MDie = createAndAddDIE(dwarf::DW_TAG_module, *ContextDIE, M);1330 1331 if (!M->getName().empty()) {1332 addString(MDie, dwarf::DW_AT_name, M->getName());1333 addGlobalName(M->getName(), MDie, M->getScope());1334 }1335 if (!M->getConfigurationMacros().empty())1336 addString(MDie, dwarf::DW_AT_LLVM_config_macros,1337 M->getConfigurationMacros());1338 if (!M->getIncludePath().empty())1339 addString(MDie, dwarf::DW_AT_LLVM_include_path, M->getIncludePath());1340 if (!M->getAPINotesFile().empty())1341 addString(MDie, dwarf::DW_AT_LLVM_apinotes, M->getAPINotesFile());1342 if (M->getFile())1343 addUInt(MDie, dwarf::DW_AT_decl_file, std::nullopt,1344 getOrCreateSourceID(M->getFile()));1345 if (M->getLineNo())1346 addUInt(MDie, dwarf::DW_AT_decl_line, std::nullopt, M->getLineNo());1347 if (M->getIsDecl())1348 addFlag(MDie, dwarf::DW_AT_declaration);1349 1350 return &MDie;1351}1352 1353DIE *DwarfUnit::getOrCreateSubprogramDIE(const DISubprogram *SP,1354 const Function *FnHint, bool Minimal) {1355 // Construct the context before querying for the existence of the DIE in case1356 // such construction creates the DIE (as is the case for member function1357 // declarations).1358 DIE *ContextDIE =1359 getOrCreateSubprogramContextDIE(SP, shouldPlaceInUnitDIE(SP, Minimal));1360 1361 if (DIE *SPDie = getDIE(SP))1362 return SPDie;1363 1364 if (auto *SPDecl = SP->getDeclaration()) {1365 if (!Minimal) {1366 // Build the decl now to ensure it precedes the definition.1367 getOrCreateSubprogramDIE(SPDecl, nullptr);1368 // Check whether the DIE for SP has already been created after the call1369 // above.1370 // FIXME: Should the creation of definition subprogram DIE during1371 // the creation of declaration subprogram DIE be allowed?1372 // See https://github.com/llvm/llvm-project/pull/154636.1373 if (DIE *SPDie = getDIE(SP))1374 return SPDie;1375 }1376 }1377 1378 // DW_TAG_inlined_subroutine may refer to this DIE.1379 DIE &SPDie = createAndAddDIE(dwarf::DW_TAG_subprogram, *ContextDIE, SP);1380 1381 // Stop here and fill this in later, depending on whether or not this1382 // subprogram turns out to have inlined instances or not.1383 if (SP->isDefinition())1384 return &SPDie;1385 1386 static_cast<DwarfUnit *>(SPDie.getUnit())1387 ->applySubprogramAttributes(SP, SPDie);1388 return &SPDie;1389}1390 1391bool DwarfUnit::applySubprogramDefinitionAttributes(const DISubprogram *SP,1392 DIE &SPDie, bool Minimal) {1393 DIE *DeclDie = nullptr;1394 StringRef DeclLinkageName;1395 if (auto *SPDecl = SP->getDeclaration()) {1396 if (!Minimal) {1397 DITypeRefArray DeclArgs, DefinitionArgs;1398 DeclArgs = SPDecl->getType()->getTypeArray();1399 DefinitionArgs = SP->getType()->getTypeArray();1400 1401 if (DeclArgs.size() && DefinitionArgs.size())1402 if (DefinitionArgs[0] != nullptr && DeclArgs[0] != DefinitionArgs[0])1403 addType(SPDie, DefinitionArgs[0]);1404 1405 DeclDie = getDIE(SPDecl);1406 assert(DeclDie && "This DIE should've already been constructed when the "1407 "definition DIE was created in "1408 "getOrCreateSubprogramDIE");1409 // Look at the Decl's linkage name only if we emitted it.1410 if (DD->useAllLinkageNames())1411 DeclLinkageName = SPDecl->getLinkageName();1412 unsigned DeclID = getOrCreateSourceID(SPDecl->getFile());1413 unsigned DefID = getOrCreateSourceID(SP->getFile());1414 if (DeclID != DefID)1415 addUInt(SPDie, dwarf::DW_AT_decl_file, std::nullopt, DefID);1416 1417 if (SP->getLine() != SPDecl->getLine())1418 addUInt(SPDie, dwarf::DW_AT_decl_line, std::nullopt, SP->getLine());1419 }1420 }1421 1422 // Add function template parameters.1423 addTemplateParams(SPDie, SP->getTemplateParams());1424 1425 // Add the linkage name if we have one and it isn't in the Decl.1426 StringRef LinkageName = SP->getLinkageName();1427 // Always emit linkage name for abstract subprograms.1428 if (DeclLinkageName != LinkageName &&1429 (DD->useAllLinkageNames() || DU->getAbstractScopeDIEs().lookup(SP)))1430 addLinkageName(SPDie, LinkageName);1431 1432 if (!DeclDie)1433 return false;1434 1435 // Refer to the function declaration where all the other attributes will be1436 // found.1437 addDIEEntry(SPDie, dwarf::DW_AT_specification, *DeclDie);1438 return true;1439}1440 1441void DwarfUnit::applySubprogramAttributes(const DISubprogram *SP, DIE &SPDie,1442 bool SkipSPAttributes) {1443 // If -fdebug-info-for-profiling is enabled, need to emit the subprogram1444 // and its source location.1445 bool SkipSPSourceLocation = SkipSPAttributes &&1446 !CUNode->getDebugInfoForProfiling();1447 if (!SkipSPSourceLocation)1448 if (applySubprogramDefinitionAttributes(SP, SPDie, SkipSPAttributes))1449 return;1450 1451 // Constructors and operators for anonymous aggregates do not have names.1452 if (!SP->getName().empty())1453 addString(SPDie, dwarf::DW_AT_name, SP->getName());1454 1455 addAnnotation(SPDie, SP->getAnnotations());1456 1457 if (!SkipSPSourceLocation)1458 addSourceLine(SPDie, SP);1459 1460 // Skip the rest of the attributes under -gmlt to save space.1461 if (SkipSPAttributes)1462 return;1463 1464 // Add the prototype if we have a prototype and we have a C like1465 // language.1466 if (SP->isPrototyped() && dwarf::isC(getSourceLanguage()))1467 addFlag(SPDie, dwarf::DW_AT_prototyped);1468 1469 if (SP->isObjCDirect())1470 addFlag(SPDie, dwarf::DW_AT_APPLE_objc_direct);1471 1472 unsigned CC = 0;1473 DITypeRefArray Args;1474 if (const DISubroutineType *SPTy = SP->getType()) {1475 Args = SPTy->getTypeArray();1476 CC = SPTy->getCC();1477 }1478 1479 // Add a DW_AT_calling_convention if this has an explicit convention.1480 if (CC && CC != dwarf::DW_CC_normal)1481 addUInt(SPDie, dwarf::DW_AT_calling_convention, dwarf::DW_FORM_data1, CC);1482 1483 // Add a return type. If this is a type like a C/C++ void type we don't add a1484 // return type.1485 if (Args.size())1486 if (auto Ty = Args[0])1487 addType(SPDie, Ty);1488 1489 unsigned VK = SP->getVirtuality();1490 if (VK) {1491 addUInt(SPDie, dwarf::DW_AT_virtuality, dwarf::DW_FORM_data1, VK);1492 if (SP->getVirtualIndex() != -1u) {1493 DIELoc *Block = getDIELoc();1494 addUInt(*Block, dwarf::DW_FORM_data1, dwarf::DW_OP_constu);1495 addUInt(*Block, dwarf::DW_FORM_udata, SP->getVirtualIndex());1496 addBlock(SPDie, dwarf::DW_AT_vtable_elem_location, Block);1497 }1498 ContainingTypeMap.insert(std::make_pair(&SPDie, SP->getContainingType()));1499 }1500 1501 if (!SP->isDefinition()) {1502 addFlag(SPDie, dwarf::DW_AT_declaration);1503 1504 // Add arguments. Do not add arguments for subprogram definition. They will1505 // be handled while processing variables.1506 //1507 // Encode the object pointer as an index instead of a DIE reference in order1508 // to minimize the affect on the .debug_info size.1509 if (std::optional<unsigned> ObjectPointerIndex =1510 constructSubprogramArguments(SPDie, Args)) {1511 if (getDwarfDebug().tuneForLLDB() &&1512 getDwarfDebug().getDwarfVersion() >= 5) {1513 // 0th index in Args is the return type, hence adjust by 1. In DWARF1514 // we want the first parameter to be at index 0.1515 assert(*ObjectPointerIndex > 0);1516 addSInt(SPDie, dwarf::DW_AT_object_pointer,1517 dwarf::DW_FORM_implicit_const, *ObjectPointerIndex - 1);1518 }1519 }1520 }1521 1522 addThrownTypes(SPDie, SP->getThrownTypes());1523 1524 if (SP->isArtificial())1525 addFlag(SPDie, dwarf::DW_AT_artificial);1526 1527 if (!SP->isLocalToUnit())1528 addFlag(SPDie, dwarf::DW_AT_external);1529 1530 if (DD->useAppleExtensionAttributes()) {1531 if (SP->isOptimized())1532 addFlag(SPDie, dwarf::DW_AT_APPLE_optimized);1533 1534 if (unsigned isa = Asm->getISAEncoding())1535 addUInt(SPDie, dwarf::DW_AT_APPLE_isa, dwarf::DW_FORM_flag, isa);1536 }1537 1538 if (SP->isLValueReference())1539 addFlag(SPDie, dwarf::DW_AT_reference);1540 1541 if (SP->isRValueReference())1542 addFlag(SPDie, dwarf::DW_AT_rvalue_reference);1543 1544 if (SP->isNoReturn())1545 addFlag(SPDie, dwarf::DW_AT_noreturn);1546 1547 addAccess(SPDie, SP->getFlags());1548 1549 if (SP->isExplicit())1550 addFlag(SPDie, dwarf::DW_AT_explicit);1551 1552 if (SP->isMainSubprogram())1553 addFlag(SPDie, dwarf::DW_AT_main_subprogram);1554 if (SP->isPure())1555 addFlag(SPDie, dwarf::DW_AT_pure);1556 if (SP->isElemental())1557 addFlag(SPDie, dwarf::DW_AT_elemental);1558 if (SP->isRecursive())1559 addFlag(SPDie, dwarf::DW_AT_recursive);1560 1561 if (!SP->getTargetFuncName().empty())1562 addString(SPDie, dwarf::DW_AT_trampoline, SP->getTargetFuncName());1563 1564 if (DD->getDwarfVersion() >= 5 && SP->isDeleted())1565 addFlag(SPDie, dwarf::DW_AT_deleted);1566}1567 1568void DwarfUnit::constructSubrangeDIE(DIE &DW_Subrange, const DISubrangeType *SR,1569 bool ForArray) {1570 StringRef Name = SR->getName();1571 if (!Name.empty())1572 addString(DW_Subrange, dwarf::DW_AT_name, Name);1573 1574 if (SR->getBaseType())1575 addType(DW_Subrange, SR->getBaseType());1576 1577 addSourceLine(DW_Subrange, SR);1578 1579 if (uint64_t Size = SR->getSizeInBits())1580 addUInt(DW_Subrange, dwarf::DW_AT_byte_size, std::nullopt, Size >> 3);1581 if (uint32_t AlignInBytes = SR->getAlignInBytes())1582 addUInt(DW_Subrange, dwarf::DW_AT_alignment, dwarf::DW_FORM_udata,1583 AlignInBytes);1584 1585 if (SR->isBigEndian())1586 addUInt(DW_Subrange, dwarf::DW_AT_endianity, std::nullopt,1587 dwarf::DW_END_big);1588 else if (SR->isLittleEndian())1589 addUInt(DW_Subrange, dwarf::DW_AT_endianity, std::nullopt,1590 dwarf::DW_END_little);1591 1592 // The LowerBound value defines the lower bounds which is typically1593 // zero for C/C++. Values are 64 bit.1594 int64_t DefaultLowerBound = getDefaultLowerBound();1595 1596 auto AddBoundTypeEntry = [&](dwarf::Attribute Attr,1597 DISubrangeType::BoundType Bound) -> void {1598 if (auto *BV = dyn_cast_if_present<DIVariable *>(Bound)) {1599 if (auto *VarDIE = getDIE(BV))1600 addDIEEntry(DW_Subrange, Attr, *VarDIE);1601 } else if (auto *BE = dyn_cast_if_present<DIExpression *>(Bound)) {1602 addBlock(DW_Subrange, Attr, BE);1603 } else if (auto *BI = dyn_cast_if_present<ConstantInt *>(Bound)) {1604 if (Attr == dwarf::DW_AT_GNU_bias) {1605 if (BI->getSExtValue() != 0)1606 addUInt(DW_Subrange, Attr, dwarf::DW_FORM_sdata, BI->getSExtValue());1607 } else if (Attr != dwarf::DW_AT_lower_bound || DefaultLowerBound == -1 ||1608 BI->getSExtValue() != DefaultLowerBound || !ForArray)1609 addSInt(DW_Subrange, Attr, dwarf::DW_FORM_sdata, BI->getSExtValue());1610 }1611 };1612 1613 AddBoundTypeEntry(dwarf::DW_AT_lower_bound, SR->getLowerBound());1614 1615 AddBoundTypeEntry(dwarf::DW_AT_upper_bound, SR->getUpperBound());1616 1617 AddBoundTypeEntry(dwarf::DW_AT_bit_stride, SR->getStride());1618 1619 AddBoundTypeEntry(dwarf::DW_AT_GNU_bias, SR->getBias());1620}1621 1622void DwarfUnit::constructSubrangeDIE(DIE &Buffer, const DISubrange *SR) {1623 DIE &DW_Subrange = createAndAddDIE(dwarf::DW_TAG_subrange_type, Buffer);1624 1625 DIE *IdxTy = getIndexTyDie();1626 addDIEEntry(DW_Subrange, dwarf::DW_AT_type, *IdxTy);1627 1628 // The LowerBound value defines the lower bounds which is typically zero for1629 // C/C++. The Count value is the number of elements. Values are 64 bit. If1630 // Count == -1 then the array is unbounded and we do not emit1631 // DW_AT_lower_bound and DW_AT_count attributes.1632 int64_t DefaultLowerBound = getDefaultLowerBound();1633 1634 auto AddBoundTypeEntry = [&](dwarf::Attribute Attr,1635 DISubrange::BoundType Bound) -> void {1636 if (auto *BV = dyn_cast_if_present<DIVariable *>(Bound)) {1637 if (auto *VarDIE = getDIE(BV))1638 addDIEEntry(DW_Subrange, Attr, *VarDIE);1639 } else if (auto *BE = dyn_cast_if_present<DIExpression *>(Bound)) {1640 addBlock(DW_Subrange, Attr, BE);1641 } else if (auto *BI = dyn_cast_if_present<ConstantInt *>(Bound)) {1642 if (Attr == dwarf::DW_AT_count) {1643 if (BI->getSExtValue() != -1)1644 addUInt(DW_Subrange, Attr, std::nullopt, BI->getSExtValue());1645 } else if (Attr != dwarf::DW_AT_lower_bound || DefaultLowerBound == -1 ||1646 BI->getSExtValue() != DefaultLowerBound)1647 addSInt(DW_Subrange, Attr, dwarf::DW_FORM_sdata, BI->getSExtValue());1648 }1649 };1650 1651 AddBoundTypeEntry(dwarf::DW_AT_lower_bound, SR->getLowerBound());1652 1653 AddBoundTypeEntry(dwarf::DW_AT_count, SR->getCount());1654 1655 AddBoundTypeEntry(dwarf::DW_AT_upper_bound, SR->getUpperBound());1656 1657 AddBoundTypeEntry(dwarf::DW_AT_byte_stride, SR->getStride());1658}1659 1660void DwarfUnit::constructGenericSubrangeDIE(DIE &Buffer,1661 const DIGenericSubrange *GSR) {1662 DIE &DwGenericSubrange =1663 createAndAddDIE(dwarf::DW_TAG_generic_subrange, Buffer);1664 // Get an anonymous type for index type.1665 // FIXME: This type should be passed down from the front end1666 // as different languages may have different sizes for indexes.1667 DIE *IdxTy = getIndexTyDie();1668 addDIEEntry(DwGenericSubrange, dwarf::DW_AT_type, *IdxTy);1669 1670 int64_t DefaultLowerBound = getDefaultLowerBound();1671 1672 auto AddBoundTypeEntry = [&](dwarf::Attribute Attr,1673 DIGenericSubrange::BoundType Bound) -> void {1674 if (auto *BV = dyn_cast_if_present<DIVariable *>(Bound)) {1675 if (auto *VarDIE = getDIE(BV))1676 addDIEEntry(DwGenericSubrange, Attr, *VarDIE);1677 } else if (auto *BE = dyn_cast_if_present<DIExpression *>(Bound)) {1678 if (BE->isConstant() &&1679 DIExpression::SignedOrUnsignedConstant::SignedConstant ==1680 *BE->isConstant()) {1681 if (Attr != dwarf::DW_AT_lower_bound || DefaultLowerBound == -1 ||1682 static_cast<int64_t>(BE->getElement(1)) != DefaultLowerBound)1683 addSInt(DwGenericSubrange, Attr, dwarf::DW_FORM_sdata,1684 BE->getElement(1));1685 } else {1686 addBlock(DwGenericSubrange, Attr, BE);1687 }1688 }1689 };1690 1691 AddBoundTypeEntry(dwarf::DW_AT_lower_bound, GSR->getLowerBound());1692 AddBoundTypeEntry(dwarf::DW_AT_count, GSR->getCount());1693 AddBoundTypeEntry(dwarf::DW_AT_upper_bound, GSR->getUpperBound());1694 AddBoundTypeEntry(dwarf::DW_AT_byte_stride, GSR->getStride());1695}1696 1697DIE *DwarfUnit::getIndexTyDie() {1698 if (IndexTyDie)1699 return IndexTyDie;1700 // Construct an integer type to use for indexes.1701 IndexTyDie = &createAndAddDIE(dwarf::DW_TAG_base_type, getUnitDie());1702 StringRef Name = "__ARRAY_SIZE_TYPE__";1703 addString(*IndexTyDie, dwarf::DW_AT_name, Name);1704 addUInt(*IndexTyDie, dwarf::DW_AT_byte_size, std::nullopt, sizeof(int64_t));1705 addUInt(*IndexTyDie, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1,1706 dwarf::getArrayIndexTypeEncoding(getSourceLanguage()));1707 DD->addAccelType(*this, CUNode->getNameTableKind(), Name, *IndexTyDie,1708 /*Flags*/ 0);1709 return IndexTyDie;1710}1711 1712/// Returns true if the vector's size differs from the sum of sizes of elements1713/// the user specified. This can occur if the vector has been rounded up to1714/// fit memory alignment constraints.1715static bool hasVectorBeenPadded(const DICompositeType *CTy) {1716 assert(CTy && CTy->isVector() && "Composite type is not a vector");1717 const uint64_t ActualSize = CTy->getSizeInBits();1718 1719 // Obtain the size of each element in the vector.1720 DIType *BaseTy = CTy->getBaseType();1721 assert(BaseTy && "Unknown vector element type.");1722 const uint64_t ElementSize = BaseTy->getSizeInBits();1723 1724 // Locate the number of elements in the vector.1725 const DINodeArray Elements = CTy->getElements();1726 assert(Elements.size() == 1 &&1727 Elements[0]->getTag() == dwarf::DW_TAG_subrange_type &&1728 "Invalid vector element array, expected one element of type subrange");1729 const auto Subrange = cast<DISubrange>(Elements[0]);1730 const auto NumVecElements =1731 Subrange->getCount()1732 ? cast<ConstantInt *>(Subrange->getCount())->getSExtValue()1733 : 0;1734 1735 // Ensure we found the element count and that the actual size is wide1736 // enough to contain the requested size.1737 assert(ActualSize >= (NumVecElements * ElementSize) && "Invalid vector size");1738 return ActualSize != (NumVecElements * ElementSize);1739}1740 1741void DwarfUnit::constructArrayTypeDIE(DIE &Buffer, const DICompositeType *CTy) {1742 if (CTy->isVector()) {1743 addFlag(Buffer, dwarf::DW_AT_GNU_vector);1744 if (hasVectorBeenPadded(CTy))1745 addUInt(Buffer, dwarf::DW_AT_byte_size, std::nullopt,1746 CTy->getSizeInBits() / CHAR_BIT);1747 }1748 1749 if (DIVariable *Var = CTy->getDataLocation()) {1750 if (auto *VarDIE = getDIE(Var))1751 addDIEEntry(Buffer, dwarf::DW_AT_data_location, *VarDIE);1752 } else if (DIExpression *Expr = CTy->getDataLocationExp()) {1753 addBlock(Buffer, dwarf::DW_AT_data_location, Expr);1754 }1755 1756 if (DIVariable *Var = CTy->getAssociated()) {1757 if (auto *VarDIE = getDIE(Var))1758 addDIEEntry(Buffer, dwarf::DW_AT_associated, *VarDIE);1759 } else if (DIExpression *Expr = CTy->getAssociatedExp()) {1760 addBlock(Buffer, dwarf::DW_AT_associated, Expr);1761 }1762 1763 if (DIVariable *Var = CTy->getAllocated()) {1764 if (auto *VarDIE = getDIE(Var))1765 addDIEEntry(Buffer, dwarf::DW_AT_allocated, *VarDIE);1766 } else if (DIExpression *Expr = CTy->getAllocatedExp()) {1767 addBlock(Buffer, dwarf::DW_AT_allocated, Expr);1768 }1769 1770 if (auto *RankConst = CTy->getRankConst()) {1771 addSInt(Buffer, dwarf::DW_AT_rank, dwarf::DW_FORM_sdata,1772 RankConst->getSExtValue());1773 } else if (auto *RankExpr = CTy->getRankExp()) {1774 addBlock(Buffer, dwarf::DW_AT_rank, RankExpr);1775 }1776 1777 if (auto *BitStride = CTy->getBitStrideConst()) {1778 addUInt(Buffer, dwarf::DW_AT_bit_stride, {}, BitStride->getZExtValue());1779 }1780 1781 // Emit the element type.1782 addType(Buffer, CTy->getBaseType());1783 1784 // Add subranges to array type.1785 DINodeArray Elements = CTy->getElements();1786 for (DINode *E : Elements) {1787 if (auto *Element = dyn_cast_or_null<DISubrangeType>(E)) {1788 DIE &TyDIE = createAndAddDIE(Element->getTag(), Buffer, CTy);1789 constructSubrangeDIE(TyDIE, Element, true);1790 } else if (auto *Element = dyn_cast_or_null<DISubrange>(E))1791 constructSubrangeDIE(Buffer, Element);1792 else if (auto *Element = dyn_cast_or_null<DIGenericSubrange>(E))1793 constructGenericSubrangeDIE(Buffer, Element);1794 }1795}1796 1797void DwarfUnit::constructEnumTypeDIE(DIE &Buffer, const DICompositeType *CTy) {1798 const DIType *DTy = CTy->getBaseType();1799 bool IsUnsigned = DTy && DD->isUnsignedDIType(DTy);1800 if (DTy) {1801 if (!Asm->TM.Options.DebugStrictDwarf || DD->getDwarfVersion() >= 3)1802 addType(Buffer, DTy);1803 if (DD->getDwarfVersion() >= 4 && (CTy->getFlags() & DINode::FlagEnumClass))1804 addFlag(Buffer, dwarf::DW_AT_enum_class);1805 }1806 1807 if (auto Kind = CTy->getEnumKind())1808 addUInt(Buffer, dwarf::DW_AT_APPLE_enum_kind, dwarf::DW_FORM_data1, *Kind);1809 1810 auto *Context = CTy->getScope();1811 bool IndexEnumerators = !Context || isa<DICompileUnit>(Context) || isa<DIFile>(Context) ||1812 isa<DINamespace>(Context) || isa<DICommonBlock>(Context);1813 DINodeArray Elements = CTy->getElements();1814 1815 // Add enumerators to enumeration type.1816 for (const DINode *E : Elements) {1817 auto *Enum = dyn_cast_or_null<DIEnumerator>(E);1818 if (Enum) {1819 DIE &Enumerator = createAndAddDIE(dwarf::DW_TAG_enumerator, Buffer);1820 StringRef Name = Enum->getName();1821 addString(Enumerator, dwarf::DW_AT_name, Name);1822 addConstantValue(Enumerator, Enum->getValue(), IsUnsigned);1823 if (IndexEnumerators)1824 addGlobalName(Name, Enumerator, Context);1825 }1826 }1827}1828 1829void DwarfUnit::constructContainingTypeDIEs() {1830 for (auto &P : ContainingTypeMap) {1831 DIE &SPDie = *P.first;1832 const DINode *D = P.second;1833 if (!D)1834 continue;1835 DIE *NDie = getDIE(D);1836 if (!NDie)1837 continue;1838 addDIEEntry(SPDie, dwarf::DW_AT_containing_type, *NDie);1839 }1840}1841 1842DIE &DwarfUnit::constructMemberDIE(DIE &Buffer, const DIDerivedType *DT) {1843 DIE &MemberDie = createAndAddDIE(DT->getTag(), Buffer, DT);1844 StringRef Name = DT->getName();1845 if (!Name.empty())1846 addString(MemberDie, dwarf::DW_AT_name, Name);1847 1848 addAnnotation(MemberDie, DT->getAnnotations());1849 1850 if (DIType *Resolved = DT->getBaseType())1851 addType(MemberDie, Resolved);1852 1853 addSourceLine(MemberDie, DT);1854 1855 if (DT->getTag() == dwarf::DW_TAG_inheritance && DT->isVirtual()) {1856 1857 // For C++, virtual base classes are not at fixed offset. Use following1858 // expression to extract appropriate offset from vtable.1859 // BaseAddr = ObAddr + *((*ObAddr) - Offset)1860 1861 DIELoc *VBaseLocationDie = new (DIEValueAllocator) DIELoc;1862 addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_dup);1863 addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_deref);1864 addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_constu);1865 addUInt(*VBaseLocationDie, dwarf::DW_FORM_udata, DT->getOffsetInBits());1866 addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_minus);1867 addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_deref);1868 addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_plus);1869 1870 addBlock(MemberDie, dwarf::DW_AT_data_member_location, VBaseLocationDie);1871 } else {1872 uint64_t Size = 0;1873 uint64_t FieldSize = 0;1874 1875 bool IsBitfield = DT->isBitField();1876 1877 // Handle the size.1878 if (DT->getRawSizeInBits() == nullptr) {1879 // No size, just ignore.1880 } else if (auto *Var = dyn_cast<DIVariable>(DT->getRawSizeInBits())) {1881 if (auto *VarDIE = getDIE(Var))1882 addDIEEntry(MemberDie, dwarf::DW_AT_bit_size, *VarDIE);1883 } else if (auto *Exp = dyn_cast<DIExpression>(DT->getRawSizeInBits())) {1884 addBlock(MemberDie, dwarf::DW_AT_bit_size, Exp);1885 } else {1886 Size = DT->getSizeInBits();1887 FieldSize = DD->getBaseTypeSize(DT);1888 if (IsBitfield) {1889 // Handle bitfield, assume bytes are 8 bits.1890 if (DD->useDWARF2Bitfields())1891 addUInt(MemberDie, dwarf::DW_AT_byte_size, std::nullopt,1892 FieldSize / 8);1893 addUInt(MemberDie, dwarf::DW_AT_bit_size, std::nullopt, Size);1894 }1895 }1896 1897 // Handle the location. DW_AT_data_bit_offset won't allow an1898 // expression until DWARF 6, but it can be used as an extension.1899 // See https://dwarfstd.org/issues/250501.1.html1900 if (auto *Var = dyn_cast_or_null<DIVariable>(DT->getRawOffsetInBits())) {1901 if (!Asm->TM.Options.DebugStrictDwarf || DD->getDwarfVersion() >= 6) {1902 if (auto *VarDIE = getDIE(Var))1903 addDIEEntry(MemberDie, dwarf::DW_AT_data_bit_offset, *VarDIE);1904 }1905 } else if (auto *Expr =1906 dyn_cast_or_null<DIExpression>(DT->getRawOffsetInBits())) {1907 if (!Asm->TM.Options.DebugStrictDwarf || DD->getDwarfVersion() >= 6) {1908 addBlock(MemberDie, dwarf::DW_AT_data_bit_offset, Expr);1909 }1910 } else {1911 uint32_t AlignInBytes = DT->getAlignInBytes();1912 uint64_t OffsetInBytes;1913 1914 if (IsBitfield) {1915 assert(DT->getOffsetInBits() <=1916 (uint64_t)std::numeric_limits<int64_t>::max());1917 int64_t Offset = DT->getOffsetInBits();1918 // We can't use DT->getAlignInBits() here: AlignInBits for member type1919 // is non-zero if and only if alignment was forced (e.g. _Alignas()),1920 // which can't be done with bitfields. Thus we use FieldSize here.1921 uint32_t AlignInBits = FieldSize;1922 uint32_t AlignMask = ~(AlignInBits - 1);1923 // The bits from the start of the storage unit to the start of the1924 // field.1925 uint64_t StartBitOffset = Offset - (Offset & AlignMask);1926 // The byte offset of the field's aligned storage unit inside the1927 // struct.1928 OffsetInBytes = (Offset - StartBitOffset) / 8;1929 1930 if (DD->useDWARF2Bitfields()) {1931 uint64_t HiMark = (Offset + FieldSize) & AlignMask;1932 uint64_t FieldOffset = (HiMark - FieldSize);1933 Offset -= FieldOffset;1934 1935 // Maybe we need to work from the other end.1936 if (Asm->getDataLayout().isLittleEndian())1937 Offset = FieldSize - (Offset + Size);1938 1939 if (Offset < 0)1940 addSInt(MemberDie, dwarf::DW_AT_bit_offset, dwarf::DW_FORM_sdata,1941 Offset);1942 else1943 addUInt(MemberDie, dwarf::DW_AT_bit_offset, std::nullopt,1944 (uint64_t)Offset);1945 OffsetInBytes = FieldOffset >> 3;1946 } else {1947 addUInt(MemberDie, dwarf::DW_AT_data_bit_offset, std::nullopt,1948 Offset);1949 }1950 } else {1951 // This is not a bitfield.1952 OffsetInBytes = DT->getOffsetInBits() / 8;1953 if (AlignInBytes)1954 addUInt(MemberDie, dwarf::DW_AT_alignment, dwarf::DW_FORM_udata,1955 AlignInBytes);1956 }1957 1958 if (DD->getDwarfVersion() <= 2) {1959 DIELoc *MemLocationDie = new (DIEValueAllocator) DIELoc;1960 addUInt(*MemLocationDie, dwarf::DW_FORM_data1,1961 dwarf::DW_OP_plus_uconst);1962 addUInt(*MemLocationDie, dwarf::DW_FORM_udata, OffsetInBytes);1963 addBlock(MemberDie, dwarf::DW_AT_data_member_location, MemLocationDie);1964 } else if (!IsBitfield || DD->useDWARF2Bitfields()) {1965 // In DWARF v3, DW_FORM_data4/8 in DW_AT_data_member_location are1966 // interpreted as location-list pointers. Interpreting constants as1967 // pointers is not expected, so we use DW_FORM_udata to encode the1968 // constants here.1969 if (DD->getDwarfVersion() == 3)1970 addUInt(MemberDie, dwarf::DW_AT_data_member_location,1971 dwarf::DW_FORM_udata, OffsetInBytes);1972 else1973 addUInt(MemberDie, dwarf::DW_AT_data_member_location, std::nullopt,1974 OffsetInBytes);1975 }1976 }1977 }1978 1979 addAccess(MemberDie, DT->getFlags());1980 1981 if (DT->isVirtual())1982 addUInt(MemberDie, dwarf::DW_AT_virtuality, dwarf::DW_FORM_data1,1983 dwarf::DW_VIRTUALITY_virtual);1984 1985 // Objective-C properties.1986 if (DINode *PNode = DT->getObjCProperty())1987 if (DIE *PDie = getDIE(PNode))1988 addAttribute(MemberDie, dwarf::DW_AT_APPLE_property,1989 dwarf::DW_FORM_ref4, DIEEntry(*PDie));1990 1991 if (DT->isArtificial())1992 addFlag(MemberDie, dwarf::DW_AT_artificial);1993 1994 return MemberDie;1995}1996 1997DIE *DwarfUnit::getOrCreateStaticMemberDIE(const DIDerivedType *DT) {1998 if (!DT)1999 return nullptr;2000 2001 // Construct the context before querying for the existence of the DIE in case2002 // such construction creates the DIE.2003 DIE *ContextDIE = getOrCreateContextDIE(DT->getScope());2004 assert(dwarf::isType(ContextDIE->getTag()) &&2005 "Static member should belong to a type.");2006 2007 if (DIE *StaticMemberDIE = getDIE(DT))2008 return StaticMemberDIE;2009 2010 DwarfUnit *ContextUnit = static_cast<DwarfUnit *>(ContextDIE->getUnit());2011 DIE &StaticMemberDIE = createAndAddDIE(DT->getTag(), *ContextDIE, DT);2012 2013 const DIType *Ty = DT->getBaseType();2014 2015 addString(StaticMemberDIE, dwarf::DW_AT_name, DT->getName());2016 addType(StaticMemberDIE, Ty);2017 ContextUnit->addSourceLine(StaticMemberDIE, DT);2018 addFlag(StaticMemberDIE, dwarf::DW_AT_external);2019 addFlag(StaticMemberDIE, dwarf::DW_AT_declaration);2020 2021 // Consider the case when the static member was created by the compiler.2022 if (DT->isArtificial())2023 addFlag(StaticMemberDIE, dwarf::DW_AT_artificial);2024 2025 // FIXME: We could omit private if the parent is a class_type, and2026 // public if the parent is something else.2027 addAccess(StaticMemberDIE, DT->getFlags());2028 2029 if (const ConstantInt *CI = dyn_cast_or_null<ConstantInt>(DT->getConstant()))2030 addConstantValue(StaticMemberDIE, CI, Ty);2031 if (const ConstantFP *CFP = dyn_cast_or_null<ConstantFP>(DT->getConstant()))2032 addConstantFPValue(StaticMemberDIE, CFP);2033 2034 if (uint32_t AlignInBytes = DT->getAlignInBytes())2035 addUInt(StaticMemberDIE, dwarf::DW_AT_alignment, dwarf::DW_FORM_udata,2036 AlignInBytes);2037 2038 return &StaticMemberDIE;2039}2040 2041void DwarfUnit::emitCommonHeader(bool UseOffsets, dwarf::UnitType UT) {2042 // Emit size of content not including length itself2043 if (!DD->useSectionsAsReferences())2044 EndLabel = Asm->emitDwarfUnitLength(2045 isDwoUnit() ? "debug_info_dwo" : "debug_info", "Length of Unit");2046 else2047 Asm->emitDwarfUnitLength(getHeaderSize() + getUnitDie().getSize(),2048 "Length of Unit");2049 2050 Asm->OutStreamer->AddComment("DWARF version number");2051 unsigned Version = DD->getDwarfVersion();2052 Asm->emitInt16(Version);2053 2054 // DWARF v5 reorders the address size and adds a unit type.2055 if (Version >= 5) {2056 Asm->OutStreamer->AddComment("DWARF Unit Type");2057 Asm->emitInt8(UT);2058 Asm->OutStreamer->AddComment("Address Size (in bytes)");2059 Asm->emitInt8(Asm->MAI->getCodePointerSize());2060 }2061 2062 // We share one abbreviations table across all units so it's always at the2063 // start of the section. Use a relocatable offset where needed to ensure2064 // linking doesn't invalidate that offset.2065 Asm->OutStreamer->AddComment("Offset Into Abbrev. Section");2066 const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering();2067 if (UseOffsets)2068 Asm->emitDwarfLengthOrOffset(0);2069 else2070 Asm->emitDwarfSymbolReference(2071 TLOF.getDwarfAbbrevSection()->getBeginSymbol(), false);2072 2073 if (Version <= 4) {2074 Asm->OutStreamer->AddComment("Address Size (in bytes)");2075 Asm->emitInt8(Asm->MAI->getCodePointerSize());2076 }2077}2078 2079void DwarfTypeUnit::emitHeader(bool UseOffsets) {2080 if (!DD->useSplitDwarf()) {2081 LabelBegin = Asm->createTempSymbol("tu_begin");2082 Asm->OutStreamer->emitLabel(LabelBegin);2083 }2084 DwarfUnit::emitCommonHeader(UseOffsets,2085 DD->useSplitDwarf() ? dwarf::DW_UT_split_type2086 : dwarf::DW_UT_type);2087 Asm->OutStreamer->AddComment("Type Signature");2088 Asm->OutStreamer->emitIntValue(TypeSignature, sizeof(TypeSignature));2089 Asm->OutStreamer->AddComment("Type DIE Offset");2090 // In a skeleton type unit there is no type DIE so emit a zero offset.2091 Asm->emitDwarfLengthOrOffset(Ty ? Ty->getOffset() : 0);2092}2093 2094void DwarfUnit::addSectionDelta(DIE &Die, dwarf::Attribute Attribute,2095 const MCSymbol *Hi, const MCSymbol *Lo) {2096 addAttribute(Die, Attribute, DD->getDwarfSectionOffsetForm(),2097 new (DIEValueAllocator) DIEDelta(Hi, Lo));2098}2099 2100void DwarfUnit::addSectionLabel(DIE &Die, dwarf::Attribute Attribute,2101 const MCSymbol *Label, const MCSymbol *Sec) {2102 if (Asm->doesDwarfUseRelocationsAcrossSections())2103 addLabel(Die, Attribute, DD->getDwarfSectionOffsetForm(), Label);2104 else2105 addSectionDelta(Die, Attribute, Label, Sec);2106}2107 2108bool DwarfTypeUnit::isDwoUnit() const {2109 // Since there are no skeleton type units, all type units are dwo type units2110 // when split DWARF is being used.2111 return DD->useSplitDwarf();2112}2113 2114void DwarfTypeUnit::addGlobalName(StringRef Name, const DIE &Die,2115 const DIScope *Context) {2116 getCU().addGlobalNameForTypeUnit(Name, Context);2117}2118 2119void DwarfTypeUnit::addGlobalTypeImpl(const DIType *Ty, const DIE &Die,2120 const DIScope *Context) {2121 getCU().addGlobalTypeUnitType(Ty, Context);2122}2123 2124const MCSymbol *DwarfUnit::getCrossSectionRelativeBaseAddress() const {2125 if (!Asm->doesDwarfUseRelocationsAcrossSections())2126 return nullptr;2127 if (isDwoUnit())2128 return nullptr;2129 return getSection()->getBeginSymbol();2130}2131 2132void DwarfUnit::addStringOffsetsStart() {2133 const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering();2134 addSectionLabel(getUnitDie(), dwarf::DW_AT_str_offsets_base,2135 DU->getStringOffsetsStartSym(),2136 TLOF.getDwarfStrOffSection()->getBeginSymbol());2137}2138 2139void DwarfUnit::addRnglistsBase() {2140 assert(DD->getDwarfVersion() >= 5 &&2141 "DW_AT_rnglists_base requires DWARF version 5 or later");2142 const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering();2143 addSectionLabel(getUnitDie(), dwarf::DW_AT_rnglists_base,2144 DU->getRnglistsTableBaseSym(),2145 TLOF.getDwarfRnglistsSection()->getBeginSymbol());2146}2147 2148void DwarfTypeUnit::finishNonUnitTypeDIE(DIE& D, const DICompositeType *CTy) {2149 DD->getAddressPool().resetUsedFlag(true);2150}2151 2152bool DwarfUnit::isCompatibleWithVersion(uint16_t Version) const {2153 return !Asm->TM.Options.DebugStrictDwarf || DD->getDwarfVersion() >= Version;2154}2155