[lld] 6f87d14 - [ELF] Initialize Ctx members

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sat Nov 16 16:23:05 PST 2024


Author: Fangrui Song
Date: 2024-11-16T16:22:59-08:00
New Revision: 6f87d1437ebd6a72ee67f26fbe5b1fa906ffb574

URL: https://github.com/llvm/llvm-project/commit/6f87d1437ebd6a72ee67f26fbe5b1fa906ffb574
DIFF: https://github.com/llvm/llvm-project/commit/6f87d1437ebd6a72ee67f26fbe5b1fa906ffb574.diff

LOG: [ELF] Initialize Ctx members

Prevent use of uninitialized memory when `ctx` becomes a local variable.

Added: 
    

Modified: 
    lld/ELF/Config.h

Removed: 
    


################################################################################
diff  --git a/lld/ELF/Config.h b/lld/ELF/Config.h
index 3198b77353fc1d..0c65364e35046e 100644
--- a/lld/ELF/Config.h
+++ b/lld/ELF/Config.h
@@ -552,9 +552,9 @@ struct Ctx {
 
   // These variables are initialized by Writer and should not be used before
   // Writer is initialized.
-  uint8_t *bufferStart;
-  Partition *mainPart;
-  PhdrEntry *tlsPhdr;
+  uint8_t *bufferStart = nullptr;
+  Partition *mainPart = nullptr;
+  PhdrEntry *tlsPhdr = nullptr;
   struct OutSections {
     OutputSection *elfHeader;
     OutputSection *programHeaders;
@@ -562,7 +562,7 @@ struct Ctx {
     OutputSection *initArray;
     OutputSection *finiArray;
   };
-  OutSections out;
+  OutSections out{};
   SmallVector<OutputSection *, 0> outputSections;
   std::vector<Partition> partitions;
 
@@ -606,7 +606,7 @@ struct Ctx {
     // _TLS_MODULE_BASE_ on targets that support TLSDESC.
     Defined *tlsModuleBase;
   };
-  ElfSym sym;
+  ElfSym sym{};
   std::unique_ptr<SymbolTable> symtab;
 
   SmallVector<std::unique_ptr<MemoryBuffer>> memoryBuffers;
@@ -637,7 +637,7 @@ struct Ctx {
   // archive.
   std::unique_ptr<llvm::TarWriter> tar;
   // InputFile for linker created symbols with no source location.
-  InputFile *internalFile;
+  InputFile *internalFile = nullptr;
   // True if SHT_LLVM_SYMPART is used.
   std::atomic<bool> hasSympart{false};
   // True if there are TLS IE relocations. Set DF_STATIC_TLS if -shared.
@@ -646,7 +646,7 @@ struct Ctx {
   std::atomic<bool> needsTlsLd{false};
   // True if all native vtable symbols have corresponding type info symbols
   // during LTO.
-  bool ltoAllVtablesHaveTypeInfos;
+  bool ltoAllVtablesHaveTypeInfos = false;
 
   // Each symbol assignment and DEFINED(sym) reference is assigned an increasing
   // order. Each DEFINED(sym) evaluation checks whether the reference happens


        


More information about the llvm-commits mailing list