diff --git a/llvm/include/llvm/DWARFLinker/DWARFLinker.h b/llvm/include/llvm/DWARFLinker/DWARFLinker.h index 351363c312c20e..0637f712f52a50 100644 --- a/llvm/include/llvm/DWARFLinker/DWARFLinker.h +++ b/llvm/include/llvm/DWARFLinker/DWARFLinker.h @@ -63,28 +63,21 @@ class AddressesMap { public: virtual ~AddressesMap(); - /// Returns true if represented addresses are from linked file. - /// Returns false if represented addresses are from not-linked - /// object file. - virtual bool areRelocationsResolved() const = 0; - /// Checks that there are valid relocations against a .debug_info /// section. virtual bool hasValidRelocs() = 0; - /// Checks that the specified DIE has a DW_AT_Location attribute - /// that references into a live code section. - /// + /// Checks that the specified variable \p DIE references live code section. + /// Allowed kind of input die: DW_TAG_variable, DW_TAG_constant. /// \returns true and sets Info.InDebugMap if it is the case. - virtual bool hasLiveMemoryLocation(const DWARFDie &DIE, - CompileUnit::DIEInfo &Info) = 0; + virtual bool isLiveVariable(const DWARFDie &DIE, + CompileUnit::DIEInfo &Info) = 0; - /// Checks that the specified DIE has a DW_AT_Low_pc attribute - /// that references into a live code section. - /// + /// Checks that the specified subprogram \p DIE references live code section. + /// Allowed kind of input die: DW_TAG_subprogram, DW_TAG_label. /// \returns true and sets Info.InDebugMap if it is the case. - virtual bool hasLiveAddressRange(const DWARFDie &DIE, - CompileUnit::DIEInfo &Info) = 0; + virtual bool isLiveSubprogram(const DWARFDie &DIE, + CompileUnit::DIEInfo &Info) = 0; /// Apply the valid relocations to the buffer \p Data, taking into /// account that Data is at \p BaseOffset in the .debug_info section. diff --git a/llvm/lib/DWARFLinker/DWARFLinker.cpp b/llvm/lib/DWARFLinker/DWARFLinker.cpp index e0e961d7f56287..de4fa63951d606 100644 --- a/llvm/lib/DWARFLinker/DWARFLinker.cpp +++ b/llvm/lib/DWARFLinker/DWARFLinker.cpp @@ -440,8 +440,7 @@ unsigned DWARFLinker::shouldKeepVariableDIE(AddressesMap &RelocMgr, // if the variable has a valid relocation, so that the DIEInfo is filled. // However, we don't want a static variable in a function to force us to keep // the enclosing function, unless requested explicitly. - const bool HasLiveMemoryLocation = - RelocMgr.hasLiveMemoryLocation(DIE, MyInfo); + const bool HasLiveMemoryLocation = RelocMgr.isLiveVariable(DIE, MyInfo); if (!HasLiveMemoryLocation || ((Flags & TF_InFunctionScope) && !LLVM_UNLIKELY(Options.KeepFunctionForStatic))) return Flags; @@ -470,7 +469,7 @@ unsigned DWARFLinker::shouldKeepSubprogramDIE( return Flags; assert(LowPc.hasValue() && "low_pc attribute is not an address."); - if (!RelocMgr.hasLiveAddressRange(DIE, MyInfo)) + if (!RelocMgr.isLiveSubprogram(DIE, MyInfo)) return Flags; if (Options.Verbose) { @@ -1385,8 +1384,7 @@ DIE *DWARFLinker::DIECloner::cloneDIE(const DWARFDie &InputDIE, DWARFDataExtractor(DIECopy, Data.isLittleEndian(), Data.getAddressSize()); // Modify the copy with relocated addresses. - if (ObjFile.Addresses->areRelocationsResolved() && - ObjFile.Addresses->applyValidRelocs(DIECopy, Offset, + if (ObjFile.Addresses->applyValidRelocs(DIECopy, Offset, Data.isLittleEndian())) { // If we applied relocations, we store the value of high_pc that was // potentially stored in the input DIE. If high_pc is an address diff --git a/llvm/tools/dsymutil/DwarfLinkerForBinary.cpp b/llvm/tools/dsymutil/DwarfLinkerForBinary.cpp index fef9f25bf7c273..12d5af24e6e4d5 100644 --- a/llvm/tools/dsymutil/DwarfLinkerForBinary.cpp +++ b/llvm/tools/dsymutil/DwarfLinkerForBinary.cpp @@ -941,7 +941,7 @@ getAttributeOffsets(const DWARFAbbreviationDeclaration *Abbrev, unsigned Idx, return std::make_pair(Offset, End); } -bool DwarfLinkerForBinary::AddressManager::hasLiveMemoryLocation( +bool DwarfLinkerForBinary::AddressManager::isLiveVariable( const DWARFDie &DIE, CompileUnit::DIEInfo &MyInfo) { const auto *Abbrev = DIE.getAbbreviationDeclarationPtr(); @@ -960,7 +960,7 @@ bool DwarfLinkerForBinary::AddressManager::hasLiveMemoryLocation( LocationEndOffset, MyInfo); } -bool DwarfLinkerForBinary::AddressManager::hasLiveAddressRange( +bool DwarfLinkerForBinary::AddressManager::isLiveSubprogram( const DWARFDie &DIE, CompileUnit::DIEInfo &MyInfo) { const auto *Abbrev = DIE.getAbbreviationDeclarationPtr(); @@ -1010,7 +1010,6 @@ DwarfLinkerForBinary::AddressManager::relocate(const ValidReloc &Reloc) const { /// \returns whether any reloc has been applied. bool DwarfLinkerForBinary::AddressManager::applyValidRelocs( MutableArrayRef Data, uint64_t BaseOffset, bool IsLittleEndian) { - assert(areRelocationsResolved()); std::vector Relocs = getRelocations( ValidDebugInfoRelocs, BaseOffset, BaseOffset + Data.size()); diff --git a/llvm/tools/dsymutil/DwarfLinkerForBinary.h b/llvm/tools/dsymutil/DwarfLinkerForBinary.h index dd29b1ff98acbd..bb9e3c1be45fcd 100644 --- a/llvm/tools/dsymutil/DwarfLinkerForBinary.h +++ b/llvm/tools/dsymutil/DwarfLinkerForBinary.h @@ -139,8 +139,6 @@ class DwarfLinkerForBinary { } virtual ~AddressManager() override { clear(); } - virtual bool areRelocationsResolved() const override { return true; } - bool hasValidRelocs() override { return !ValidDebugInfoRelocs.empty() || !ValidDebugAddrRelocs.empty(); } @@ -171,10 +169,10 @@ class DwarfLinkerForBinary { uint64_t StartOffset, uint64_t EndOffset, CompileUnit::DIEInfo &Info); - bool hasLiveMemoryLocation(const DWARFDie &DIE, - CompileUnit::DIEInfo &Info) override; - bool hasLiveAddressRange(const DWARFDie &DIE, - CompileUnit::DIEInfo &Info) override; + bool isLiveVariable(const DWARFDie &DIE, + CompileUnit::DIEInfo &Info) override; + bool isLiveSubprogram(const DWARFDie &DIE, + CompileUnit::DIEInfo &Info) override; bool applyValidRelocs(MutableArrayRef Data, uint64_t BaseOffset, bool IsLittleEndian) override;