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