1//===- DWARF.h -----------------------------------------------*- C++ -*-===//
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-exception
6//
7//===-------------------------------------------------------------------===//
8
9#ifndef LLD_ELF_DWARF_H
10#define LLD_ELF_DWARF_H
11
12#include "InputFiles.h"
13#include "llvm/ADT/STLExtras.h"
14#include "llvm/DebugInfo/DWARF/DWARFContext.h"
15#include "llvm/Object/ELF.h"
16#include <optional>
17
18namespace lld::elf {
19
20class InputSection;
21
22struct LLDDWARFSection final : public llvm::DWARFSection {
23 InputSectionBase *sec = nullptr;
24};
25
26template <class ELFT> class LLDDwarfObj final : public llvm::DWARFObject {
27public:
28 explicit LLDDwarfObj(ObjFile<ELFT> *obj);
29
30 void forEachInfoSections(
31 llvm::function_ref<void(const llvm::DWARFSection &)> f) const override {
32 f(infoSection);
33 }
34
35 InputSection *getInfoSection() const {
36 return cast<InputSection>(Val: infoSection.sec);
37 }
38
39 const llvm::DWARFSection &getLoclistsSection() const override {
40 return loclistsSection;
41 }
42
43 const llvm::DWARFSection &getRangesSection() const override {
44 return rangesSection;
45 }
46
47 const llvm::DWARFSection &getRnglistsSection() const override {
48 return rnglistsSection;
49 }
50
51 const llvm::DWARFSection &getStrOffsetsSection() const override {
52 return strOffsetsSection;
53 }
54
55 const llvm::DWARFSection &getLineSection() const override {
56 return lineSection;
57 }
58
59 const llvm::DWARFSection &getAddrSection() const override {
60 return addrSection;
61 }
62
63 const LLDDWARFSection &getGnuPubnamesSection() const override {
64 return gnuPubnamesSection;
65 }
66
67 const LLDDWARFSection &getGnuPubtypesSection() const override {
68 return gnuPubtypesSection;
69 }
70
71 StringRef getFileName() const override { return ""; }
72 StringRef getAbbrevSection() const override { return abbrevSection; }
73 StringRef getStrSection() const override { return strSection; }
74 StringRef getLineStrSection() const override { return lineStrSection; }
75
76 bool isLittleEndian() const override {
77 return ELFT::TargetEndianness == llvm::endianness::little;
78 }
79
80 std::optional<llvm::RelocAddrEntry> find(const llvm::DWARFSection &sec,
81 uint64_t pos) const override;
82
83private:
84 template <class RelTy>
85 std::optional<llvm::RelocAddrEntry> findAux(const InputSectionBase &sec,
86 uint64_t pos,
87 ArrayRef<RelTy> rels) const;
88
89 LLDDWARFSection gnuPubnamesSection;
90 LLDDWARFSection gnuPubtypesSection;
91 LLDDWARFSection infoSection;
92 LLDDWARFSection loclistsSection;
93 LLDDWARFSection rangesSection;
94 LLDDWARFSection rnglistsSection;
95 LLDDWARFSection strOffsetsSection;
96 LLDDWARFSection lineSection;
97 LLDDWARFSection addrSection;
98 StringRef abbrevSection;
99 StringRef strSection;
100 StringRef lineStrSection;
101};
102
103} // namespace lld::elf
104
105#endif
106

source code of lld/ELF/DWARF.h