Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit b5ac700

Browse files
author
George Rimar
committed
Recommit "[DWARF] - Make collectAddressRanges() return section index in addition to Low/High PC"
With fix of uninitialized variable. Original commit message: This change is intended to use for LLD in D33183. Problem we have in LLD when building .gdb_index is that we need to know section which address range belongs to. Previously it was solved on LLD side by providing fake section addresses with use of llvm::LoadedObjectInfo interface. We assigned file offsets as addressed. Then after obtaining ranges lists, for each range we had to find section ID's. That not only was slow, but also complicated implementation and was the reason of incorrect behavior when sections share the same offsets, like D33176 shows. This patch makes DWARF parsers to return section index as well. That solves problem mentioned above. Differential revision: https://reviews.llvm.org/D33184 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@304078 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 6788678 commit b5ac700

File tree

18 files changed

+101
-42
lines changed

18 files changed

+101
-42
lines changed

include/llvm/DebugInfo/DWARF/DWARFContext.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ class raw_ostream;
4646
/// Reads a value from data extractor and applies a relocation to the result if
4747
/// one exists for the given offset.
4848
uint64_t getRelocatedValue(const DataExtractor &Data, uint32_t Size,
49-
uint32_t *Off, const RelocAddrMap *Relocs);
49+
uint32_t *Off, const RelocAddrMap *Relocs,
50+
uint64_t *SecNdx = nullptr);
5051

5152
/// DWARFContext
5253
/// This data structure is the top level entity that deals with dwarf debug

include/llvm/DebugInfo/DWARF/DWARFDebugRangeList.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class raw_ostream;
2525
struct DWARFAddressRange {
2626
uint64_t LowPC;
2727
uint64_t HighPC;
28+
uint64_t SectionIndex;
2829
};
2930

3031
/// DWARFAddressRangesVector - represents a set of absolute address ranges.
@@ -44,6 +45,8 @@ class DWARFDebugRangeList {
4445
/// address past the end of the address range. The ending address must
4546
/// be greater than or equal to the beginning address.
4647
uint64_t EndAddress;
48+
/// A section index this range belongs to.
49+
uint64_t SectionIndex;
4750

4851
/// The end of any given range list is marked by an end of list entry,
4952
/// which consists of a 0 for the beginning address offset

include/llvm/DebugInfo/DWARF/DWARFDie.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,8 @@ class DWARFDie {
195195

196196
/// Retrieves DW_AT_low_pc and DW_AT_high_pc from CU.
197197
/// Returns true if both attributes are present.
198-
bool getLowAndHighPC(uint64_t &LowPC, uint64_t &HighPC) const;
198+
bool getLowAndHighPC(uint64_t &LowPC, uint64_t &HighPC,
199+
uint64_t &SectionIndex) const;
199200

200201
/// Get the address ranges for this DIE.
201202
///

include/llvm/DebugInfo/DWARF/DWARFFormValue.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class DWARFFormValue {
4747
const char *cstr;
4848
};
4949
const uint8_t *data = nullptr;
50+
uint64_t SectionIndex; /// Section index for reference forms.
5051
};
5152

5253
dwarf::Form Form; /// Form for this value.
@@ -58,6 +59,7 @@ class DWARFFormValue {
5859

5960
dwarf::Form getForm() const { return Form; }
6061
uint64_t getRawUValue() const { return Value.uval; }
62+
uint64_t getSectionIndex() const { return Value.SectionIndex; }
6163
void setForm(dwarf::Form F) { Form = F; }
6264
void setUValue(uint64_t V) { Value.uval = V; }
6365
void setSValue(int64_t V) { Value.sval = V; }

include/llvm/DebugInfo/DWARF/DWARFRelocMap.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616

1717
namespace llvm {
1818

19+
/// RelocAddrEntry contains relocated value and section index.
20+
/// Section index is -1LL if relocation points to absolute symbol.
1921
struct RelocAddrEntry {
22+
uint64_t SectionIndex;
2023
uint64_t Value;
2124
};
2225

include/llvm/Object/COFF.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,7 @@ class COFFObjectFile : public ObjectFile {
782782
std::error_code getSectionName(DataRefImpl Sec,
783783
StringRef &Res) const override;
784784
uint64_t getSectionAddress(DataRefImpl Sec) const override;
785+
uint64_t getSectionIndex(DataRefImpl Sec) const override;
785786
uint64_t getSectionSize(DataRefImpl Sec) const override;
786787
std::error_code getSectionContents(DataRefImpl Sec,
787788
StringRef &Res) const override;

include/llvm/Object/ELFObjectFile.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ template <class ELFT> class ELFObjectFile : public ELFObjectFileBase {
235235
std::error_code getSectionName(DataRefImpl Sec,
236236
StringRef &Res) const override;
237237
uint64_t getSectionAddress(DataRefImpl Sec) const override;
238+
uint64_t getSectionIndex(DataRefImpl Sec) const override;
238239
uint64_t getSectionSize(DataRefImpl Sec) const override;
239240
std::error_code getSectionContents(DataRefImpl Sec,
240241
StringRef &Res) const override;
@@ -645,6 +646,17 @@ uint64_t ELFObjectFile<ELFT>::getSectionAddress(DataRefImpl Sec) const {
645646
return getSection(Sec)->sh_addr;
646647
}
647648

649+
template <class ELFT>
650+
uint64_t ELFObjectFile<ELFT>::getSectionIndex(DataRefImpl Sec) const {
651+
auto SectionsOrErr = EF.sections();
652+
handleAllErrors(std::move(SectionsOrErr.takeError()),
653+
[](const ErrorInfoBase &) {
654+
llvm_unreachable("unable to get section index");
655+
});
656+
const Elf_Shdr *First = SectionsOrErr->begin();
657+
return getSection(Sec) - First;
658+
}
659+
648660
template <class ELFT>
649661
uint64_t ELFObjectFile<ELFT>::getSectionSize(DataRefImpl Sec) const {
650662
return getSection(Sec)->sh_size;

include/llvm/Object/MachO.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ class MachOObjectFile : public ObjectFile {
290290
std::error_code getSectionName(DataRefImpl Sec,
291291
StringRef &Res) const override;
292292
uint64_t getSectionAddress(DataRefImpl Sec) const override;
293+
uint64_t getSectionIndex(DataRefImpl Sec) const override;
293294
uint64_t getSectionSize(DataRefImpl Sec) const override;
294295
std::error_code getSectionContents(DataRefImpl Sec,
295296
StringRef &Res) const override;

include/llvm/Object/ObjectFile.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ class SectionRef {
9595

9696
std::error_code getName(StringRef &Result) const;
9797
uint64_t getAddress() const;
98+
uint64_t getIndex() const;
9899
uint64_t getSize() const;
99100
std::error_code getContents(StringRef &Result) const;
100101

@@ -222,6 +223,7 @@ class ObjectFile : public SymbolicFile {
222223
virtual std::error_code getSectionName(DataRefImpl Sec,
223224
StringRef &Res) const = 0;
224225
virtual uint64_t getSectionAddress(DataRefImpl Sec) const = 0;
226+
virtual uint64_t getSectionIndex(DataRefImpl Sec) const = 0;
225227
virtual uint64_t getSectionSize(DataRefImpl Sec) const = 0;
226228
virtual std::error_code getSectionContents(DataRefImpl Sec,
227229
StringRef &Res) const = 0;
@@ -393,6 +395,10 @@ inline uint64_t SectionRef::getAddress() const {
393395
return OwningObject->getSectionAddress(SectionPimpl);
394396
}
395397

398+
inline uint64_t SectionRef::getIndex() const {
399+
return OwningObject->getSectionIndex(SectionPimpl);
400+
}
401+
396402
inline uint64_t SectionRef::getSize() const {
397403
return OwningObject->getSectionSize(SectionPimpl);
398404
}

include/llvm/Object/Wasm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ class WasmObjectFile : public ObjectFile {
119119
std::error_code getSectionName(DataRefImpl Sec,
120120
StringRef &Res) const override;
121121
uint64_t getSectionAddress(DataRefImpl Sec) const override;
122+
uint64_t getSectionIndex(DataRefImpl Sec) const override;
122123
uint64_t getSectionSize(DataRefImpl Sec) const override;
123124
std::error_code getSectionContents(DataRefImpl Sec,
124125
StringRef &Res) const override;

0 commit comments

Comments
 (0)