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" 14*0fca6ea1SDimitry Andric #include "llvm/ADT/STLFunctionalExtras.h" 150b57cec5SDimitry Andric #include "llvm/DebugInfo/DWARF/DWARFContext.h" 160b57cec5SDimitry Andric #include "llvm/Object/ELF.h" 175f757f3fSDimitry Andric #include <optional> 180b57cec5SDimitry Andric 19bdd1243dSDimitry Andric namespace lld::elf { 200b57cec5SDimitry Andric 210b57cec5SDimitry Andric class InputSection; 220b57cec5SDimitry Andric 230b57cec5SDimitry Andric struct LLDDWARFSection final : public llvm::DWARFSection { 240b57cec5SDimitry Andric InputSectionBase *sec = nullptr; 250b57cec5SDimitry Andric }; 260b57cec5SDimitry Andric 270b57cec5SDimitry Andric template <class ELFT> class LLDDwarfObj final : public llvm::DWARFObject { 280b57cec5SDimitry Andric public: 290b57cec5SDimitry Andric explicit LLDDwarfObj(ObjFile<ELFT> *obj); 300b57cec5SDimitry Andric forEachInfoSections(llvm::function_ref<void (const llvm::DWARFSection &)> f)310b57cec5SDimitry Andric void forEachInfoSections( 320b57cec5SDimitry Andric llvm::function_ref<void(const llvm::DWARFSection &)> f) const override { 330b57cec5SDimitry Andric f(infoSection); 340b57cec5SDimitry Andric } 350b57cec5SDimitry Andric getInfoSection()3616d6b3b3SDimitry Andric InputSection *getInfoSection() const { 3716d6b3b3SDimitry Andric return cast<InputSection>(infoSection.sec); 3816d6b3b3SDimitry Andric } 3916d6b3b3SDimitry Andric getAddrSection()40*0fca6ea1SDimitry Andric const llvm::DWARFSection &getAddrSection() const override { 41*0fca6ea1SDimitry Andric return addrSection; 425ffd83dbSDimitry Andric } getLineSection()430b57cec5SDimitry Andric const llvm::DWARFSection &getLineSection() const override { 440b57cec5SDimitry Andric return lineSection; 450b57cec5SDimitry Andric } getLoclistsSection()46*0fca6ea1SDimitry Andric const llvm::DWARFSection &getLoclistsSection() const override { 47*0fca6ea1SDimitry Andric return loclistsSection; 48*0fca6ea1SDimitry Andric } getRangesSection()49*0fca6ea1SDimitry Andric const llvm::DWARFSection &getRangesSection() const override { 50*0fca6ea1SDimitry Andric return rangesSection; 51*0fca6ea1SDimitry Andric } getRnglistsSection()52*0fca6ea1SDimitry Andric const llvm::DWARFSection &getRnglistsSection() const override { 53*0fca6ea1SDimitry Andric return rnglistsSection; 54*0fca6ea1SDimitry Andric } getStrOffsetsSection()55*0fca6ea1SDimitry Andric const llvm::DWARFSection &getStrOffsetsSection() const override { 56*0fca6ea1SDimitry Andric return strOffsetsSection; 570b57cec5SDimitry Andric } 580b57cec5SDimitry Andric getGnuPubnamesSection()595ffd83dbSDimitry Andric const LLDDWARFSection &getGnuPubnamesSection() const override { 6085868e8aSDimitry Andric return gnuPubnamesSection; 610b57cec5SDimitry Andric } getGnuPubtypesSection()625ffd83dbSDimitry Andric const LLDDWARFSection &getGnuPubtypesSection() const override { 6385868e8aSDimitry Andric return gnuPubtypesSection; 640b57cec5SDimitry Andric } getNamesSection()65*0fca6ea1SDimitry Andric const LLDDWARFSection &getNamesSection() const override { 66*0fca6ea1SDimitry Andric return namesSection; 67*0fca6ea1SDimitry Andric } 680b57cec5SDimitry Andric getFileName()690b57cec5SDimitry Andric StringRef getFileName() const override { return ""; } getAbbrevSection()700b57cec5SDimitry Andric StringRef getAbbrevSection() const override { return abbrevSection; } getStrSection()7185868e8aSDimitry Andric StringRef getStrSection() const override { return strSection; } getLineStrSection()7285868e8aSDimitry Andric StringRef getLineStrSection() const override { return lineStrSection; } 730b57cec5SDimitry Andric isLittleEndian()740b57cec5SDimitry Andric bool isLittleEndian() const override { 75*0fca6ea1SDimitry Andric return ELFT::Endianness == llvm::endianness::little; 760b57cec5SDimitry Andric } 770b57cec5SDimitry Andric 78bdd1243dSDimitry Andric std::optional<llvm::RelocAddrEntry> find(const llvm::DWARFSection &sec, 790b57cec5SDimitry Andric uint64_t pos) const override; 800b57cec5SDimitry Andric 810b57cec5SDimitry Andric private: 820b57cec5SDimitry Andric template <class RelTy> 83bdd1243dSDimitry Andric std::optional<llvm::RelocAddrEntry> findAux(const InputSectionBase &sec, 840b57cec5SDimitry Andric uint64_t pos, 850b57cec5SDimitry Andric ArrayRef<RelTy> rels) const; 860b57cec5SDimitry Andric 87*0fca6ea1SDimitry Andric LLDDWARFSection addrSection; 8885868e8aSDimitry Andric LLDDWARFSection gnuPubnamesSection; 8985868e8aSDimitry Andric LLDDWARFSection gnuPubtypesSection; 900b57cec5SDimitry Andric LLDDWARFSection infoSection; 91*0fca6ea1SDimitry Andric LLDDWARFSection lineSection; 925ffd83dbSDimitry Andric LLDDWARFSection loclistsSection; 93*0fca6ea1SDimitry Andric LLDDWARFSection namesSection; 9485868e8aSDimitry Andric LLDDWARFSection rangesSection; 9585868e8aSDimitry Andric LLDDWARFSection rnglistsSection; 9685868e8aSDimitry Andric LLDDWARFSection strOffsetsSection; 970b57cec5SDimitry Andric StringRef abbrevSection; 9885868e8aSDimitry Andric StringRef lineStrSection; 99*0fca6ea1SDimitry Andric StringRef strSection; 1000b57cec5SDimitry Andric }; 1010b57cec5SDimitry Andric 102bdd1243dSDimitry Andric } // namespace lld::elf 1030b57cec5SDimitry Andric 1040b57cec5SDimitry Andric #endif 105