Skip to content

Commit 6f87d14

Browse files
committed
[ELF] Initialize Ctx members
Prevent use of uninitialized memory when `ctx` becomes a local variable.
1 parent 7d13775 commit 6f87d14

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

lld/ELF/Config.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -552,17 +552,17 @@ struct Ctx {
552552

553553
// These variables are initialized by Writer and should not be used before
554554
// Writer is initialized.
555-
uint8_t *bufferStart;
556-
Partition *mainPart;
557-
PhdrEntry *tlsPhdr;
555+
uint8_t *bufferStart = nullptr;
556+
Partition *mainPart = nullptr;
557+
PhdrEntry *tlsPhdr = nullptr;
558558
struct OutSections {
559559
OutputSection *elfHeader;
560560
OutputSection *programHeaders;
561561
OutputSection *preinitArray;
562562
OutputSection *initArray;
563563
OutputSection *finiArray;
564564
};
565-
OutSections out;
565+
OutSections out{};
566566
SmallVector<OutputSection *, 0> outputSections;
567567
std::vector<Partition> partitions;
568568

@@ -606,7 +606,7 @@ struct Ctx {
606606
// _TLS_MODULE_BASE_ on targets that support TLSDESC.
607607
Defined *tlsModuleBase;
608608
};
609-
ElfSym sym;
609+
ElfSym sym{};
610610
std::unique_ptr<SymbolTable> symtab;
611611

612612
SmallVector<std::unique_ptr<MemoryBuffer>> memoryBuffers;
@@ -637,7 +637,7 @@ struct Ctx {
637637
// archive.
638638
std::unique_ptr<llvm::TarWriter> tar;
639639
// InputFile for linker created symbols with no source location.
640-
InputFile *internalFile;
640+
InputFile *internalFile = nullptr;
641641
// True if SHT_LLVM_SYMPART is used.
642642
std::atomic<bool> hasSympart{false};
643643
// True if there are TLS IE relocations. Set DF_STATIC_TLS if -shared.
@@ -646,7 +646,7 @@ struct Ctx {
646646
std::atomic<bool> needsTlsLd{false};
647647
// True if all native vtable symbols have corresponding type info symbols
648648
// during LTO.
649-
bool ltoAllVtablesHaveTypeInfos;
649+
bool ltoAllVtablesHaveTypeInfos = false;
650650

651651
// Each symbol assignment and DEFINED(sym) reference is assigned an increasing
652652
// order. Each DEFINED(sym) evaluation checks whether the reference happens

0 commit comments

Comments
 (0)