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 17 namespace lld::elf { 18 19 class InputSection; 20 21 struct LLDDWARFSection final : public llvm::DWARFSection { 22 InputSectionBase *sec = nullptr; 23 }; 24 25 template <class ELFT> class LLDDwarfObj final : public llvm::DWARFObject { 26 public: 27 explicit LLDDwarfObj(ObjFile<ELFT> *obj); 28 forEachInfoSections(llvm::function_ref<void (const llvm::DWARFSection &)> f)29 void forEachInfoSections( 30 llvm::function_ref<void(const llvm::DWARFSection &)> f) const override { 31 f(infoSection); 32 } 33 getInfoSection()34 InputSection *getInfoSection() const { 35 return cast<InputSection>(infoSection.sec); 36 } 37 getLoclistsSection()38 const llvm::DWARFSection &getLoclistsSection() const override { 39 return loclistsSection; 40 } 41 getRangesSection()42 const llvm::DWARFSection &getRangesSection() const override { 43 return rangesSection; 44 } 45 getRnglistsSection()46 const llvm::DWARFSection &getRnglistsSection() const override { 47 return rnglistsSection; 48 } 49 getStrOffsetsSection()50 const llvm::DWARFSection &getStrOffsetsSection() const override { 51 return strOffsetsSection; 52 } 53 getLineSection()54 const llvm::DWARFSection &getLineSection() const override { 55 return lineSection; 56 } 57 getAddrSection()58 const llvm::DWARFSection &getAddrSection() const override { 59 return addrSection; 60 } 61 getGnuPubnamesSection()62 const LLDDWARFSection &getGnuPubnamesSection() const override { 63 return gnuPubnamesSection; 64 } 65 getGnuPubtypesSection()66 const LLDDWARFSection &getGnuPubtypesSection() const override { 67 return gnuPubtypesSection; 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::TargetEndianness == llvm::support::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 gnuPubnamesSection; 89 LLDDWARFSection gnuPubtypesSection; 90 LLDDWARFSection infoSection; 91 LLDDWARFSection loclistsSection; 92 LLDDWARFSection rangesSection; 93 LLDDWARFSection rnglistsSection; 94 LLDDWARFSection strOffsetsSection; 95 LLDDWARFSection lineSection; 96 LLDDWARFSection addrSection; 97 StringRef abbrevSection; 98 StringRef strSection; 99 StringRef lineStrSection; 100 }; 101 102 } // namespace lld::elf 103 104 #endif 105