blob: 74d80e13148017137e8a99ac6443183075beb653 [file] [log] [blame]
//===- DIEAttributeCloner.h -------------------------------------*- C++ -*-===//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#include "ArrayList.h"
#include "DIEGenerator.h"
#include "DWARFLinkerCompileUnit.h"
#include "DWARFLinkerGlobalData.h"
namespace llvm {
namespace dwarflinker_parallel {
/// Information gathered and exchanged between the various
/// clone*Attr helpers about the attributes of a particular DIE.
struct AttributesInfo {
/// Short Name.
StringEntry *Name = nullptr;
/// Mangled Name.
StringEntry *MangledName = nullptr;
/// Does the DIE have an address pointing to live code section?
bool HasLiveAddress = false;
/// Is this DIE only a declaration?
bool IsDeclaration = false;
/// Does the DIE have a ranges attribute?
bool HasRanges = false;
/// Does the DIE have a string offset attribute?
bool HasStringOffsetBaseAttr = false;
/// This class creates clones of input DIE attributes.
/// It enumerates attributes of input DIE, creates clone for each
/// attribute, adds cloned attribute to the output DIE.
class DIEAttributeCloner {
DIEAttributeCloner(DIE *OutDIE, CompileUnit &CU,
const DWARFDebugInfoEntry *InputDieEntry,
DIEGenerator &Generator,
std::optional<int64_t> FuncAddressAdjustment,
std::optional<int64_t> VarAddressAdjustment,
bool HasLocationExpressionAddress)
: OutDIE(OutDIE), CU(CU),
InputDieEntry(InputDieEntry), Generator(Generator),
HasLocationExpressionAddress(HasLocationExpressionAddress) {
InputDIEIdx = CU.getDIEIndex(InputDieEntry);
/// Clone attributes of input DIE.
void clone();
/// Create abbreviations for the output DIE after all attributes are cloned.
unsigned finalizeAbbreviations(bool HasChildrenToClone);
/// Cannot be used concurrently.
AttributesInfo AttrInfo;
/// Clone string attribute.
cloneStringAttr(const DWARFFormValue &Val,
const DWARFAbbreviationDeclaration::AttributeSpec &AttrSpec);
/// Clone attribute referencing another DIE.
cloneDieRefAttr(const DWARFFormValue &Val,
const DWARFAbbreviationDeclaration::AttributeSpec &AttrSpec);
/// Clone scalar attribute.
cloneScalarAttr(const DWARFFormValue &Val,
const DWARFAbbreviationDeclaration::AttributeSpec &AttrSpec);
/// Clone block or exprloc attribute.
cloneBlockAttr(const DWARFFormValue &Val,
const DWARFAbbreviationDeclaration::AttributeSpec &AttrSpec);
/// Clone address attribute.
cloneAddressAttr(const DWARFFormValue &Val,
const DWARFAbbreviationDeclaration::AttributeSpec &AttrSpec);
/// Returns true if attribute should be skipped.
shouldSkipAttribute(DWARFAbbreviationDeclaration::AttributeSpec AttrSpec);
/// Update patches offsets with the size of abbreviation number.
updatePatchesWithSizeOfAbbreviationNumber(unsigned SizeOfAbbreviationNumber) {
for (uint64_t *OffsetPtr : PatchesOffsets)
*OffsetPtr += SizeOfAbbreviationNumber;
/// Output DIE.
DIE *OutDIE = nullptr;
/// Compile unit for the output DIE.
CompileUnit &CU;
/// .debug_info section descriptor.
SectionDescriptor &DebugInfoOutputSection;
/// Input DIE entry.
const DWARFDebugInfoEntry *InputDieEntry = nullptr;
/// Input DIE index.
uint32_t InputDIEIdx = 0;
/// Output DIE generator.
DIEGenerator &Generator;
/// Relocation adjustment for the function address ranges.
std::optional<int64_t> FuncAddressAdjustment;
/// Relocation adjustment for the variable locations.
std::optional<int64_t> VarAddressAdjustment;
/// Indicates whether InputDieEntry has an location attribute
/// containg address expression.
bool HasLocationExpressionAddress = false;
/// Output offset after all attributes.
unsigned AttrOutOffset = 0;
/// Patches for the cloned attributes.
OffsetsPtrVector PatchesOffsets;
} // end of namespace dwarflinker_parallel
} // end namespace llvm