Path: blob/main/contrib/llvm-project/llvm/lib/DWARFLinker/Parallel/DIEAttributeCloner.h
35291 views
//===- DIEAttributeCloner.h -------------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef LLVM_LIB_DWARFLINKER_PARALLEL_DIEATTRIBUTECLONER_H9#define LLVM_LIB_DWARFLINKER_PARALLEL_DIEATTRIBUTECLONER_H1011#include "ArrayList.h"12#include "DIEGenerator.h"13#include "DWARFLinkerCompileUnit.h"14#include "DWARFLinkerGlobalData.h"15#include "DWARFLinkerTypeUnit.h"1617namespace llvm {18namespace dwarf_linker {19namespace parallel {2021/// Information gathered and exchanged between the various22/// clone*Attr helpers about the attributes of a particular DIE.23struct AttributesInfo {24/// Short Name.25StringEntry *Name = nullptr;2627/// Mangled Name.28StringEntry *MangledName = nullptr;2930/// Does the DIE have an address pointing to live code section?31bool HasLiveAddress = false;3233/// Is this DIE only a declaration?34bool IsDeclaration = false;3536/// Does the DIE have a ranges attribute?37bool HasRanges = false;3839/// Does the DIE have a string offset attribute?40bool HasStringOffsetBaseAttr = false;41};4243/// This class creates clones of input DIE attributes.44/// It enumerates attributes of input DIE, creates clone for each45/// attribute, adds cloned attribute to the output DIE.46class DIEAttributeCloner {47public:48DIEAttributeCloner(DIE *OutDIE, CompileUnit &InUnit, CompileUnit *OutUnit,49const DWARFDebugInfoEntry *InputDieEntry,50DIEGenerator &Generator,51std::optional<int64_t> FuncAddressAdjustment,52std::optional<int64_t> VarAddressAdjustment,53bool HasLocationExpressionAddress)54: DIEAttributeCloner(OutDIE, InUnit,55CompileUnit::OutputUnitVariantPtr(OutUnit),56InputDieEntry, Generator, FuncAddressAdjustment,57VarAddressAdjustment, HasLocationExpressionAddress) {58}5960DIEAttributeCloner(DIE *OutDIE, CompileUnit &InUnit, TypeUnit *OutUnit,61const DWARFDebugInfoEntry *InputDieEntry,62DIEGenerator &Generator,63std::optional<int64_t> FuncAddressAdjustment,64std::optional<int64_t> VarAddressAdjustment,65bool HasLocationExpressionAddress)66: DIEAttributeCloner(OutDIE, InUnit,67CompileUnit::OutputUnitVariantPtr(OutUnit),68InputDieEntry, Generator, FuncAddressAdjustment,69VarAddressAdjustment, HasLocationExpressionAddress) {70}7172/// Clone attributes of input DIE.73void clone();7475/// Create abbreviations for the output DIE after all attributes are cloned.76unsigned finalizeAbbreviations(bool HasChildrenToClone);7778/// Cannot be used concurrently.79AttributesInfo AttrInfo;8081unsigned getOutOffset() { return AttrOutOffset; }8283protected:84DIEAttributeCloner(DIE *OutDIE, CompileUnit &InUnit,85CompileUnit::OutputUnitVariantPtr OutUnit,86const DWARFDebugInfoEntry *InputDieEntry,87DIEGenerator &Generator,88std::optional<int64_t> FuncAddressAdjustment,89std::optional<int64_t> VarAddressAdjustment,90bool HasLocationExpressionAddress)91: OutDIE(OutDIE), InUnit(InUnit), OutUnit(OutUnit),92DebugInfoOutputSection(93OutUnit->getSectionDescriptor(DebugSectionKind::DebugInfo)),94InputDieEntry(InputDieEntry), Generator(Generator),95FuncAddressAdjustment(FuncAddressAdjustment),96VarAddressAdjustment(VarAddressAdjustment),97HasLocationExpressionAddress(HasLocationExpressionAddress) {98InputDIEIdx = InUnit.getDIEIndex(InputDieEntry);99100// Use DW_FORM_strp form for string attributes for DWARF version less than 5101// or if output unit is type unit and we need to produce deterministic102// result. (We can not generate deterministic results for debug_str_offsets103// section when attributes are cloned parallelly).104Use_DW_FORM_strp =105(InUnit.getVersion() < 5) ||106(OutUnit.isTypeUnit() &&107((InUnit.getGlobalData().getOptions().Threads != 1) &&108!InUnit.getGlobalData().getOptions().AllowNonDeterministicOutput));109}110111/// Clone string attribute.112size_t113cloneStringAttr(const DWARFFormValue &Val,114const DWARFAbbreviationDeclaration::AttributeSpec &AttrSpec);115116/// Clone attribute referencing another DIE.117size_t118cloneDieRefAttr(const DWARFFormValue &Val,119const DWARFAbbreviationDeclaration::AttributeSpec &AttrSpec);120121/// Clone scalar attribute.122size_t123cloneScalarAttr(const DWARFFormValue &Val,124const DWARFAbbreviationDeclaration::AttributeSpec &AttrSpec);125126/// Clone block or exprloc attribute.127size_t128cloneBlockAttr(const DWARFFormValue &Val,129const DWARFAbbreviationDeclaration::AttributeSpec &AttrSpec);130131/// Clone address attribute.132size_t133cloneAddressAttr(const DWARFFormValue &Val,134const DWARFAbbreviationDeclaration::AttributeSpec &AttrSpec);135136/// Returns true if attribute should be skipped.137bool138shouldSkipAttribute(DWARFAbbreviationDeclaration::AttributeSpec AttrSpec);139140/// Output DIE.141DIE *OutDIE = nullptr;142143/// Input compilation unit.144CompileUnit &InUnit;145146/// Output unit(either "plain" compilation unit, either artificial type unit).147CompileUnit::OutputUnitVariantPtr OutUnit;148149/// .debug_info section descriptor.150SectionDescriptor &DebugInfoOutputSection;151152/// Input DIE entry.153const DWARFDebugInfoEntry *InputDieEntry = nullptr;154155/// Input DIE index.156uint32_t InputDIEIdx = 0;157158/// Output DIE generator.159DIEGenerator &Generator;160161/// Relocation adjustment for the function address ranges.162std::optional<int64_t> FuncAddressAdjustment;163164/// Relocation adjustment for the variable locations.165std::optional<int64_t> VarAddressAdjustment;166167/// Indicates whether InputDieEntry has an location attribute168/// containg address expression.169bool HasLocationExpressionAddress = false;170171/// Output offset after all attributes.172unsigned AttrOutOffset = 0;173174/// Patches for the cloned attributes.175OffsetsPtrVector PatchesOffsets;176177/// This flag forces using DW_FORM_strp for string attributes.178bool Use_DW_FORM_strp = false;179};180181} // end of namespace parallel182} // end of namespace dwarf_linker183} // end of namespace llvm184185#endif // LLVM_LIB_DWARFLINKER_PARALLEL_DIEATTRIBUTECLONER_H186187188