LLVM 24.0.0git
RelocationFixups.h
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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_RELOCATIONFIXUPS_H
10#define LLVM_DWARFLINKER_RELOCATIONFIXUPS_H
11
16#include <cstdint>
17#include <optional>
18
19namespace llvm {
20namespace dwarf_linker {
21
22/// Where the attributes of a unit were cloned to, so that their relocations can
23/// be saved once the output offsets of the unit are known.
25public:
26 /// Where the operations of an expression were cloned to. An operation copied
27 /// as is keeps the relocations of its bytes, while one rewritten from
28 /// DW_OP_addrx or DW_OP_constx takes those of its .debug_addr entry.
30 public:
31 struct Operation {
33 /// In .debug_addr, or from the start of the input expression.
36 /// From the start of the output expression, or of the attribute after
37 /// addOutputPrefix().
39 };
40
42
44 uint64_t OutputOffset) {
45 Operations.push_back(
46 {RelocSectionKind::DebugInfo, InputStart, Size, OutputOffset});
47 }
48
49 void noteDebugAddrOperand(uint64_t EntryOffset, uint8_t AddrSize,
50 uint64_t OutputOffset) {
51 Operations.push_back(
52 {RelocSectionKind::DebugAddr, EntryOffset, AddrSize, OutputOffset});
53 }
54
55 /// Moves the operations by \p Size, the bytes the attribute has ahead of
56 /// the expression.
58 for (Operation &Op : Operations)
59 Op.OutputOffset += Size;
60 }
61
62 /// The size of the input expression, which ends its attribute.
65 };
66
67 /// An address attribute cloned from one .debug_addr entry into another.
70 /// In the address table of the output unit.
72 };
73
74 /// What an attribute being cloned was cloned from.
76 std::optional<ClonedExpression> Expression;
77 std::optional<DebugAddrEntry> Entry;
78
79 void clear() {
80 Expression.reset();
81 Entry.reset();
82 }
83 };
84
85 /// Notes that the attribute \p Attr of a DIE tagged \p Tag was cloned from
86 /// [\p InputStart, \p InputEnd) of .debug_info to \p OutputOffset, which does
87 /// not count the abbreviation number of the DIE yet.
89 uint64_t InputStart, uint64_t InputEnd,
90 uint64_t OutputOffset,
91 const AttributeSource &Source);
92
93 /// Completes the attributes noted since the previous call, once the DIE has
94 /// an abbreviation number.
95 LLVM_ABI void finishDIE(uint64_t AbbrevNumberSize);
96
97 /// Notes that a location list operation kept an index into .debug_addr.
99 DebugAddrFixups.push_back({Entry, /*IsLowPC=*/false});
100 }
101
103 DebugAddrTableOffset = Offset;
104 }
105
106 /// Saves the relocations, for the unit at \p UnitOffset in the input.
107 LLVM_ABI void save(AddressesMap &Addresses, uint64_t UnitOffset,
108 uint8_t AddrSize) const;
109
110 bool empty() const {
111 return DIEFixups.empty() && DebugInfoFixups.empty() &&
112 DebugAddrFixups.empty();
113 }
114
115 LLVM_ABI void clear();
116
117private:
118 /// Relocations moved into .debug_info.
119 struct DebugInfoFixup {
120 RelocSectionKind InputSection;
121 uint64_t InputStart;
122 uint64_t InputEnd;
123 int64_t LinkedOffset;
124 };
125
126 struct DebugAddrFixup {
127 DebugAddrEntry Entry;
128 bool IsLowPC;
129 };
130
131 /// Those of the DIE being cloned.
132 SmallVector<DebugInfoFixup> DIEFixups;
133 SmallVector<DebugInfoFixup> DebugInfoFixups;
134 SmallVector<DebugAddrFixup> DebugAddrFixups;
135 std::optional<uint64_t> DebugAddrTableOffset;
136};
137
138} // end of namespace dwarf_linker
139} // end of namespace llvm
140
141#endif // LLVM_DWARFLINKER_RELOCATIONFIXUPS_H
uint64_t uint64_t
#define LLVM_ABI
Definition Compiler.h:211
This file contains constants used for implementing Dwarf debug support.
This file defines the SmallVector class.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
AddressesMap represents information about valid addresses used by debug information.
void addOutputPrefix(uint64_t Size)
Moves the operations by Size, the bytes the attribute has ahead of the expression.
void noteDebugAddrOperand(uint64_t EntryOffset, uint8_t AddrSize, uint64_t OutputOffset)
void noteCopiedBytes(uint64_t InputStart, uint64_t Size, uint64_t OutputOffset)
uint64_t InputSize
The size of the input expression, which ends its attribute.
Where the attributes of a unit were cloned to, so that their relocations can be saved once the output...
void noteDebugAddrEntry(DebugAddrEntry Entry)
Notes that a location list operation kept an index into .debug_addr.
LLVM_ABI void noteAttribute(dwarf::Tag Tag, dwarf::Attribute Attr, uint64_t InputStart, uint64_t InputEnd, uint64_t OutputOffset, const AttributeSource &Source)
Notes that the attribute Attr of a DIE tagged Tag was cloned from [InputStart, InputEnd) of ....
LLVM_ABI void save(AddressesMap &Addresses, uint64_t UnitOffset, uint8_t AddrSize) const
Saves the relocations, for the unit at UnitOffset in the input.
LLVM_ABI void finishDIE(uint64_t AbbrevNumberSize)
Completes the attributes noted since the previous call, once the DIE has an abbreviation number.
void setDebugAddrTableOffset(uint64_t Offset)
RelocSectionKind
The debug sections holding relocations which the linker can save.
Attribute
Attributes.
Definition Dwarf.h:125
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:577
DWARFExpression::Operation Op
What an attribute being cloned was cloned from.
uint64_t InputStart
In .debug_addr, or from the start of the input expression.
uint64_t OutputOffset
From the start of the output expression, or of the attribute after addOutputPrefix().
An address attribute cloned from one .debug_addr entry into another.
uint64_t OutputIndex
In the address table of the output unit.