Skip to content

Commit c35214c

Browse files
committed
[ELF] Initialize TargetInfo members
Prevent use of uninitialized memory when ctx.target no longer uses points to static storage duration. Specifically, uninitialized `trapInstr` caused llvm-objdump output differences. (#111260 (comment))
1 parent 4647a46 commit c35214c

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

lld/ELF/Target.h

+14-14
Original file line numberDiff line numberDiff line change
@@ -124,20 +124,20 @@ class TargetInfo {
124124
bool gotBaseSymInGotPlt = false;
125125

126126
static constexpr RelType noneRel = 0;
127-
RelType copyRel;
128-
RelType gotRel;
129-
RelType pltRel;
130-
RelType relativeRel;
131-
RelType iRelativeRel;
132-
RelType symbolicRel;
133-
RelType tlsDescRel;
134-
RelType tlsGotRel;
135-
RelType tlsModuleIndexRel;
136-
RelType tlsOffsetRel;
127+
RelType copyRel = 0;
128+
RelType gotRel = 0;
129+
RelType pltRel = 0;
130+
RelType relativeRel = 0;
131+
RelType iRelativeRel = 0;
132+
RelType symbolicRel = 0;
133+
RelType tlsDescRel = 0;
134+
RelType tlsGotRel = 0;
135+
RelType tlsModuleIndexRel = 0;
136+
RelType tlsOffsetRel = 0;
137137
unsigned gotEntrySize = ctx.arg.wordsize;
138-
unsigned pltEntrySize;
139-
unsigned pltHeaderSize;
140-
unsigned ipltEntrySize;
138+
unsigned pltEntrySize = 0;
139+
unsigned pltHeaderSize = 0;
140+
unsigned ipltEntrySize = 0;
141141

142142
// At least on x86_64 positions 1 and 2 are used by the first plt entry
143143
// to support lazy loading.
@@ -156,7 +156,7 @@ class TargetInfo {
156156

157157
// A 4-byte field corresponding to one or more trap instructions, used to pad
158158
// executable OutputSections.
159-
std::array<uint8_t, 4> trapInstr;
159+
std::array<uint8_t, 4> trapInstr = {};
160160

161161
// Stores the NOP instructions of different sizes for the target and is used
162162
// to pad sections that are relaxed.

0 commit comments

Comments
 (0)