xref: /freebsd/contrib/llvm-project/lld/ELF/DWARF.h (revision 85868e8a1daeaae7a0e48effb2ea2310ae3b02c6)
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*85868e8aSDimitry Andric   const llvm::DWARFSection &getRangesSection() const override {
36*85868e8aSDimitry Andric     return rangesSection;
370b57cec5SDimitry Andric   }
380b57cec5SDimitry Andric 
390b57cec5SDimitry Andric   const llvm::DWARFSection &getRnglistsSection() const override {
40*85868e8aSDimitry Andric     return rnglistsSection;
41*85868e8aSDimitry Andric   }
42*85868e8aSDimitry Andric 
43*85868e8aSDimitry Andric   const llvm::DWARFSection &getStrOffsetsSection() const override {
44*85868e8aSDimitry Andric     return strOffsetsSection;
450b57cec5SDimitry Andric   }
460b57cec5SDimitry Andric 
470b57cec5SDimitry Andric   const llvm::DWARFSection &getLineSection() const override {
480b57cec5SDimitry Andric     return lineSection;
490b57cec5SDimitry Andric   }
500b57cec5SDimitry Andric 
510b57cec5SDimitry Andric   const llvm::DWARFSection &getAddrSection() const override {
520b57cec5SDimitry Andric     return addrSection;
530b57cec5SDimitry Andric   }
540b57cec5SDimitry Andric 
55*85868e8aSDimitry Andric   const llvm::DWARFSection &getGnuPubnamesSection() const override {
56*85868e8aSDimitry Andric     return gnuPubnamesSection;
570b57cec5SDimitry Andric   }
580b57cec5SDimitry Andric 
59*85868e8aSDimitry Andric   const llvm::DWARFSection &getGnuPubtypesSection() const override {
60*85868e8aSDimitry Andric     return gnuPubtypesSection;
610b57cec5SDimitry Andric   }
620b57cec5SDimitry Andric 
630b57cec5SDimitry Andric   StringRef getFileName() const override { return ""; }
640b57cec5SDimitry Andric   StringRef getAbbrevSection() const override { return abbrevSection; }
65*85868e8aSDimitry Andric   StringRef getStrSection() const override { return strSection; }
66*85868e8aSDimitry Andric   StringRef getLineStrSection() const override { return lineStrSection; }
670b57cec5SDimitry Andric 
680b57cec5SDimitry Andric   bool isLittleEndian() const override {
690b57cec5SDimitry Andric     return ELFT::TargetEndianness == llvm::support::little;
700b57cec5SDimitry Andric   }
710b57cec5SDimitry Andric 
720b57cec5SDimitry Andric   llvm::Optional<llvm::RelocAddrEntry> find(const llvm::DWARFSection &sec,
730b57cec5SDimitry Andric                                             uint64_t pos) const override;
740b57cec5SDimitry Andric 
750b57cec5SDimitry Andric private:
760b57cec5SDimitry Andric   template <class RelTy>
770b57cec5SDimitry Andric   llvm::Optional<llvm::RelocAddrEntry> findAux(const InputSectionBase &sec,
780b57cec5SDimitry Andric                                                uint64_t pos,
790b57cec5SDimitry Andric                                                ArrayRef<RelTy> rels) const;
800b57cec5SDimitry Andric 
81*85868e8aSDimitry Andric   LLDDWARFSection gnuPubnamesSection;
82*85868e8aSDimitry Andric   LLDDWARFSection gnuPubtypesSection;
830b57cec5SDimitry Andric   LLDDWARFSection infoSection;
84*85868e8aSDimitry Andric   LLDDWARFSection rangesSection;
85*85868e8aSDimitry Andric   LLDDWARFSection rnglistsSection;
86*85868e8aSDimitry Andric   LLDDWARFSection strOffsetsSection;
870b57cec5SDimitry Andric   LLDDWARFSection lineSection;
880b57cec5SDimitry Andric   LLDDWARFSection addrSection;
890b57cec5SDimitry Andric   StringRef abbrevSection;
900b57cec5SDimitry Andric   StringRef strSection;
91*85868e8aSDimitry Andric   StringRef lineStrSection;
920b57cec5SDimitry Andric };
930b57cec5SDimitry Andric 
940b57cec5SDimitry Andric } // namespace elf
950b57cec5SDimitry Andric } // namespace lld
960b57cec5SDimitry Andric 
970b57cec5SDimitry Andric #endif
98