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 170b57cec5SDimitry Andric namespace lld { 180b57cec5SDimitry Andric namespace elf { 190b57cec5SDimitry Andric 200b57cec5SDimitry Andric class InputSection; 210b57cec5SDimitry Andric 220b57cec5SDimitry Andric struct LLDDWARFSection final : public llvm::DWARFSection { 230b57cec5SDimitry Andric InputSectionBase *sec = nullptr; 240b57cec5SDimitry Andric }; 250b57cec5SDimitry Andric 260b57cec5SDimitry Andric template <class ELFT> class LLDDwarfObj final : public llvm::DWARFObject { 270b57cec5SDimitry Andric public: 280b57cec5SDimitry Andric explicit LLDDwarfObj(ObjFile<ELFT> *obj); 290b57cec5SDimitry Andric 300b57cec5SDimitry Andric void forEachInfoSections( 310b57cec5SDimitry Andric llvm::function_ref<void(const llvm::DWARFSection &)> f) const override { 320b57cec5SDimitry Andric f(infoSection); 330b57cec5SDimitry Andric } 340b57cec5SDimitry Andric 35*16d6b3b3SDimitry Andric InputSection *getInfoSection() const { 36*16d6b3b3SDimitry Andric return cast<InputSection>(infoSection.sec); 37*16d6b3b3SDimitry Andric } 38*16d6b3b3SDimitry Andric 395ffd83dbSDimitry Andric const llvm::DWARFSection &getLoclistsSection() const override { 405ffd83dbSDimitry Andric return loclistsSection; 415ffd83dbSDimitry Andric } 425ffd83dbSDimitry Andric 4385868e8aSDimitry Andric const llvm::DWARFSection &getRangesSection() const override { 4485868e8aSDimitry Andric return rangesSection; 450b57cec5SDimitry Andric } 460b57cec5SDimitry Andric 470b57cec5SDimitry Andric const llvm::DWARFSection &getRnglistsSection() const override { 4885868e8aSDimitry Andric return rnglistsSection; 4985868e8aSDimitry Andric } 5085868e8aSDimitry Andric 5185868e8aSDimitry Andric const llvm::DWARFSection &getStrOffsetsSection() const override { 5285868e8aSDimitry Andric return strOffsetsSection; 530b57cec5SDimitry Andric } 540b57cec5SDimitry Andric 550b57cec5SDimitry Andric const llvm::DWARFSection &getLineSection() const override { 560b57cec5SDimitry Andric return lineSection; 570b57cec5SDimitry Andric } 580b57cec5SDimitry Andric 590b57cec5SDimitry Andric const llvm::DWARFSection &getAddrSection() const override { 600b57cec5SDimitry Andric return addrSection; 610b57cec5SDimitry Andric } 620b57cec5SDimitry Andric 635ffd83dbSDimitry Andric const LLDDWARFSection &getGnuPubnamesSection() const override { 6485868e8aSDimitry Andric return gnuPubnamesSection; 650b57cec5SDimitry Andric } 660b57cec5SDimitry Andric 675ffd83dbSDimitry Andric const LLDDWARFSection &getGnuPubtypesSection() const override { 6885868e8aSDimitry Andric return gnuPubtypesSection; 690b57cec5SDimitry Andric } 700b57cec5SDimitry Andric 710b57cec5SDimitry Andric StringRef getFileName() const override { return ""; } 720b57cec5SDimitry Andric StringRef getAbbrevSection() const override { return abbrevSection; } 7385868e8aSDimitry Andric StringRef getStrSection() const override { return strSection; } 7485868e8aSDimitry Andric StringRef getLineStrSection() const override { return lineStrSection; } 750b57cec5SDimitry Andric 760b57cec5SDimitry Andric bool isLittleEndian() const override { 770b57cec5SDimitry Andric return ELFT::TargetEndianness == llvm::support::little; 780b57cec5SDimitry Andric } 790b57cec5SDimitry Andric 800b57cec5SDimitry Andric llvm::Optional<llvm::RelocAddrEntry> find(const llvm::DWARFSection &sec, 810b57cec5SDimitry Andric uint64_t pos) const override; 820b57cec5SDimitry Andric 830b57cec5SDimitry Andric private: 840b57cec5SDimitry Andric template <class RelTy> 850b57cec5SDimitry Andric llvm::Optional<llvm::RelocAddrEntry> findAux(const InputSectionBase &sec, 860b57cec5SDimitry Andric uint64_t pos, 870b57cec5SDimitry Andric ArrayRef<RelTy> rels) const; 880b57cec5SDimitry Andric 8985868e8aSDimitry Andric LLDDWARFSection gnuPubnamesSection; 9085868e8aSDimitry Andric LLDDWARFSection gnuPubtypesSection; 910b57cec5SDimitry Andric LLDDWARFSection infoSection; 925ffd83dbSDimitry Andric LLDDWARFSection loclistsSection; 9385868e8aSDimitry Andric LLDDWARFSection rangesSection; 9485868e8aSDimitry Andric LLDDWARFSection rnglistsSection; 9585868e8aSDimitry Andric LLDDWARFSection strOffsetsSection; 960b57cec5SDimitry Andric LLDDWARFSection lineSection; 970b57cec5SDimitry Andric LLDDWARFSection addrSection; 980b57cec5SDimitry Andric StringRef abbrevSection; 990b57cec5SDimitry Andric StringRef strSection; 10085868e8aSDimitry Andric StringRef lineStrSection; 1010b57cec5SDimitry Andric }; 1020b57cec5SDimitry Andric 1030b57cec5SDimitry Andric } // namespace elf 1040b57cec5SDimitry Andric } // namespace lld 1050b57cec5SDimitry Andric 1060b57cec5SDimitry Andric #endif 107