10b57cec5SDimitry Andric //===- DWARF.h -----------------------------------------------*- C++ -*-===// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===-------------------------------------------------------------------===// 80b57cec5SDimitry Andric 90b57cec5SDimitry Andric #ifndef LLD_ELF_DWARF_H 100b57cec5SDimitry Andric #define LLD_ELF_DWARF_H 110b57cec5SDimitry Andric 120b57cec5SDimitry Andric #include "InputFiles.h" 130b57cec5SDimitry Andric #include "llvm/ADT/STLExtras.h" 140b57cec5SDimitry Andric #include "llvm/DebugInfo/DWARF/DWARFContext.h" 150b57cec5SDimitry Andric #include "llvm/Object/ELF.h" 160b57cec5SDimitry Andric 17*bdd1243dSDimitry Andric namespace lld::elf { 180b57cec5SDimitry Andric 190b57cec5SDimitry Andric class InputSection; 200b57cec5SDimitry Andric 210b57cec5SDimitry Andric struct LLDDWARFSection final : public llvm::DWARFSection { 220b57cec5SDimitry Andric InputSectionBase *sec = nullptr; 230b57cec5SDimitry Andric }; 240b57cec5SDimitry Andric 250b57cec5SDimitry Andric template <class ELFT> class LLDDwarfObj final : public llvm::DWARFObject { 260b57cec5SDimitry Andric public: 270b57cec5SDimitry Andric explicit LLDDwarfObj(ObjFile<ELFT> *obj); 280b57cec5SDimitry Andric 290b57cec5SDimitry Andric void forEachInfoSections( 300b57cec5SDimitry Andric llvm::function_ref<void(const llvm::DWARFSection &)> f) const override { 310b57cec5SDimitry Andric f(infoSection); 320b57cec5SDimitry Andric } 330b57cec5SDimitry Andric 3416d6b3b3SDimitry Andric InputSection *getInfoSection() const { 3516d6b3b3SDimitry Andric return cast<InputSection>(infoSection.sec); 3616d6b3b3SDimitry Andric } 3716d6b3b3SDimitry Andric 385ffd83dbSDimitry Andric const llvm::DWARFSection &getLoclistsSection() const override { 395ffd83dbSDimitry Andric return loclistsSection; 405ffd83dbSDimitry Andric } 415ffd83dbSDimitry Andric 4285868e8aSDimitry Andric const llvm::DWARFSection &getRangesSection() const override { 4385868e8aSDimitry Andric return rangesSection; 440b57cec5SDimitry Andric } 450b57cec5SDimitry Andric 460b57cec5SDimitry Andric const llvm::DWARFSection &getRnglistsSection() const override { 4785868e8aSDimitry Andric return rnglistsSection; 4885868e8aSDimitry Andric } 4985868e8aSDimitry Andric 5085868e8aSDimitry Andric const llvm::DWARFSection &getStrOffsetsSection() const override { 5185868e8aSDimitry Andric return strOffsetsSection; 520b57cec5SDimitry Andric } 530b57cec5SDimitry Andric 540b57cec5SDimitry Andric const llvm::DWARFSection &getLineSection() const override { 550b57cec5SDimitry Andric return lineSection; 560b57cec5SDimitry Andric } 570b57cec5SDimitry Andric 580b57cec5SDimitry Andric const llvm::DWARFSection &getAddrSection() const override { 590b57cec5SDimitry Andric return addrSection; 600b57cec5SDimitry Andric } 610b57cec5SDimitry Andric 625ffd83dbSDimitry Andric const LLDDWARFSection &getGnuPubnamesSection() const override { 6385868e8aSDimitry Andric return gnuPubnamesSection; 640b57cec5SDimitry Andric } 650b57cec5SDimitry Andric 665ffd83dbSDimitry Andric const LLDDWARFSection &getGnuPubtypesSection() const override { 6785868e8aSDimitry Andric return gnuPubtypesSection; 680b57cec5SDimitry Andric } 690b57cec5SDimitry Andric 700b57cec5SDimitry Andric StringRef getFileName() const override { return ""; } 710b57cec5SDimitry Andric StringRef getAbbrevSection() const override { return abbrevSection; } 7285868e8aSDimitry Andric StringRef getStrSection() const override { return strSection; } 7385868e8aSDimitry Andric StringRef getLineStrSection() const override { return lineStrSection; } 740b57cec5SDimitry Andric 750b57cec5SDimitry Andric bool isLittleEndian() const override { 760b57cec5SDimitry Andric return ELFT::TargetEndianness == llvm::support::little; 770b57cec5SDimitry Andric } 780b57cec5SDimitry Andric 79*bdd1243dSDimitry Andric std::optional<llvm::RelocAddrEntry> find(const llvm::DWARFSection &sec, 800b57cec5SDimitry Andric uint64_t pos) const override; 810b57cec5SDimitry Andric 820b57cec5SDimitry Andric private: 830b57cec5SDimitry Andric template <class RelTy> 84*bdd1243dSDimitry Andric std::optional<llvm::RelocAddrEntry> findAux(const InputSectionBase &sec, 850b57cec5SDimitry Andric uint64_t pos, 860b57cec5SDimitry Andric ArrayRef<RelTy> rels) const; 870b57cec5SDimitry Andric 8885868e8aSDimitry Andric LLDDWARFSection gnuPubnamesSection; 8985868e8aSDimitry Andric LLDDWARFSection gnuPubtypesSection; 900b57cec5SDimitry Andric LLDDWARFSection infoSection; 915ffd83dbSDimitry Andric LLDDWARFSection loclistsSection; 9285868e8aSDimitry Andric LLDDWARFSection rangesSection; 9385868e8aSDimitry Andric LLDDWARFSection rnglistsSection; 9485868e8aSDimitry Andric LLDDWARFSection strOffsetsSection; 950b57cec5SDimitry Andric LLDDWARFSection lineSection; 960b57cec5SDimitry Andric LLDDWARFSection addrSection; 970b57cec5SDimitry Andric StringRef abbrevSection; 980b57cec5SDimitry Andric StringRef strSection; 9985868e8aSDimitry Andric StringRef lineStrSection; 1000b57cec5SDimitry Andric }; 1010b57cec5SDimitry Andric 102*bdd1243dSDimitry Andric } // namespace lld::elf 1030b57cec5SDimitry Andric 1040b57cec5SDimitry Andric #endif 105