]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/llvm/include/llvm/DWARFLinker/DWARFLinker.h
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm-project / llvm / include / llvm / DWARFLinker / DWARFLinker.h
1 //===- DWARFLinker.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 LLVM_DWARFLINKER_DWARFLINKER_H
10 #define LLVM_DWARFLINKER_DWARFLINKER_H
11
12 #include "llvm/CodeGen/AccelTable.h"
13 #include "llvm/CodeGen/NonRelocatableStringpool.h"
14 #include "llvm/DWARFLinker/DWARFLinkerDeclContext.h"
15 #include "llvm/DebugInfo/DWARF/DWARFCompileUnit.h"
16 #include "llvm/DebugInfo/DWARF/DWARFContext.h"
17 #include "llvm/MC/MCDwarf.h"
18 #include <map>
19
20 namespace llvm {
21
22 enum class DwarfLinkerClient { Dsymutil, LLD, General };
23
24 /// Partial address range. Besides an offset, only the
25 /// HighPC is stored. The structure is stored in a map where the LowPC is the
26 /// key.
27 struct ObjFileAddressRange {
28   /// Function HighPC.
29   uint64_t HighPC;
30   /// Offset to apply to the linked address.
31   /// should be 0 for not-linked object file.
32   int64_t Offset;
33
34   ObjFileAddressRange(uint64_t EndPC, int64_t Offset)
35       : HighPC(EndPC), Offset(Offset) {}
36
37   ObjFileAddressRange() : HighPC(0), Offset(0) {}
38 };
39
40 /// Map LowPC to ObjFileAddressRange.
41 using RangesTy = std::map<uint64_t, ObjFileAddressRange>;
42
43 /// AddressesMap represents information about valid addresses used
44 /// by debug information. Valid addresses are those which points to
45 /// live code sections. i.e. relocations for these addresses point
46 /// into sections which would be/are placed into resulting binary.
47 class AddressesMap {
48 public:
49   virtual ~AddressesMap();
50
51   /// Returns true if represented addresses are from linked file.
52   /// Returns false if represented addresses are from not-linked
53   /// object file.
54   virtual bool areRelocationsResolved() const = 0;
55
56   /// Checks that there are valid relocations against a .debug_info
57   /// section. Reset current relocation pointer if neccessary.
58   virtual bool hasValidRelocs(bool ResetRelocsPtr = true) = 0;
59
60   /// Checks that there is a relocation against .debug_info
61   /// table between \p StartOffset and \p NextOffset.
62   ///
63   /// This function must be called with offsets in strictly ascending
64   /// order because it never looks back at relocations it already 'went past'.
65   /// \returns true and sets Info.InDebugMap if it is the case.
66   virtual bool hasValidRelocationAt(uint64_t StartOffset, uint64_t EndOffset,
67                                     CompileUnit::DIEInfo &Info) = 0;
68
69   /// Apply the valid relocations to the buffer \p Data, taking into
70   /// account that Data is at \p BaseOffset in the debug_info section.
71   ///
72   /// This function must be called with monotonic \p BaseOffset values.
73   ///
74   /// \returns true whether any reloc has been applied.
75   virtual bool applyValidRelocs(MutableArrayRef<char> Data, uint64_t BaseOffset,
76                                 bool IsLittleEndian) = 0;
77
78   /// Returns all valid functions address ranges(i.e., those ranges
79   /// which points to sections with code).
80   virtual RangesTy &getValidAddressRanges() = 0;
81
82   /// Erases all data.
83   virtual void clear() = 0;
84 };
85
86 /// DwarfEmitter presents interface to generate all debug info tables.
87 class DwarfEmitter {
88 public:
89   virtual ~DwarfEmitter();
90
91   /// Emit DIE containing warnings.
92   virtual void emitPaperTrailWarningsDie(const Triple &Triple, DIE &Die) = 0;
93
94   /// Emit section named SecName with content equals to
95   /// corresponding section in Obj.
96   virtual void emitSectionContents(const object::ObjectFile &Obj,
97                                    StringRef SecName) = 0;
98
99   /// Emit the abbreviation table \p Abbrevs to the debug_abbrev section.
100   virtual void
101   emitAbbrevs(const std::vector<std::unique_ptr<DIEAbbrev>> &Abbrevs,
102               unsigned DwarfVersion) = 0;
103
104   /// Emit the string table described by \p Pool.
105   virtual void emitStrings(const NonRelocatableStringpool &Pool) = 0;
106
107   /// Emit DWARF debug names.
108   virtual void
109   emitDebugNames(AccelTable<DWARF5AccelTableStaticData> &Table) = 0;
110
111   /// Emit Apple namespaces accelerator table.
112   virtual void
113   emitAppleNamespaces(AccelTable<AppleAccelTableStaticOffsetData> &Table) = 0;
114
115   /// Emit Apple names accelerator table.
116   virtual void
117   emitAppleNames(AccelTable<AppleAccelTableStaticOffsetData> &Table) = 0;
118
119   /// Emit Apple Objective-C accelerator table.
120   virtual void
121   emitAppleObjc(AccelTable<AppleAccelTableStaticOffsetData> &Table) = 0;
122
123   /// Emit Apple type accelerator table.
124   virtual void
125   emitAppleTypes(AccelTable<AppleAccelTableStaticTypeData> &Table) = 0;
126
127   /// Emit debug_ranges for \p FuncRange by translating the
128   /// original \p Entries.
129   virtual void emitRangesEntries(
130       int64_t UnitPcOffset, uint64_t OrigLowPc,
131       const FunctionIntervals::const_iterator &FuncRange,
132       const std::vector<DWARFDebugRangeList::RangeListEntry> &Entries,
133       unsigned AddressSize) = 0;
134
135   /// Emit debug_aranges entries for \p Unit and if \p DoRangesSection is true,
136   /// also emit the debug_ranges entries for the DW_TAG_compile_unit's
137   /// DW_AT_ranges attribute.
138   virtual void emitUnitRangesEntries(CompileUnit &Unit,
139                                      bool DoRangesSection) = 0;
140
141   /// Copy the debug_line over to the updated binary while unobfuscating the
142   /// file names and directories.
143   virtual void translateLineTable(DataExtractor LineData, uint64_t Offset) = 0;
144
145   /// Emit the line table described in \p Rows into the debug_line section.
146   virtual void emitLineTableForUnit(MCDwarfLineTableParams Params,
147                                     StringRef PrologueBytes,
148                                     unsigned MinInstLength,
149                                     std::vector<DWARFDebugLine::Row> &Rows,
150                                     unsigned AdddressSize) = 0;
151
152   /// Emit the .debug_pubnames contribution for \p Unit.
153   virtual void emitPubNamesForUnit(const CompileUnit &Unit) = 0;
154
155   /// Emit the .debug_pubtypes contribution for \p Unit.
156   virtual void emitPubTypesForUnit(const CompileUnit &Unit) = 0;
157
158   /// Emit a CIE.
159   virtual void emitCIE(StringRef CIEBytes) = 0;
160
161   /// Emit an FDE with data \p Bytes.
162   virtual void emitFDE(uint32_t CIEOffset, uint32_t AddreSize, uint32_t Address,
163                        StringRef Bytes) = 0;
164
165   /// Emit the debug_loc contribution for \p Unit by copying the entries from
166   /// \p Dwarf and offsetting them. Update the location attributes to point to
167   /// the new entries.
168   virtual void emitLocationsForUnit(
169       const CompileUnit &Unit, DWARFContext &Dwarf,
170       std::function<void(StringRef, SmallVectorImpl<uint8_t> &)>
171           ProcessExpr) = 0;
172
173   /// Emit the compilation unit header for \p Unit in the
174   /// debug_info section.
175   ///
176   /// As a side effect, this also switches the current Dwarf version
177   /// of the MC layer to the one of U.getOrigUnit().
178   virtual void emitCompileUnitHeader(CompileUnit &Unit) = 0;
179
180   /// Recursively emit the DIE tree rooted at \p Die.
181   virtual void emitDIE(DIE &Die) = 0;
182
183   /// Returns size of generated .debug_line section.
184   virtual uint64_t getLineSectionSize() const = 0;
185
186   /// Returns size of generated .debug_frame section.
187   virtual uint64_t getFrameSectionSize() const = 0;
188
189   /// Returns size of generated .debug_ranges section.
190   virtual uint64_t getRangesSectionSize() const = 0;
191
192   /// Returns size of generated .debug_info section.
193   virtual uint64_t getDebugInfoSectionSize() const = 0;
194 };
195
196 } // end namespace llvm
197
198 #endif // LLVM_DWARFLINKER_DWARFLINKER_H