[lld] c35214c - [ELF] Initialize TargetInfo members

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 7 23:07:56 PDT 2024


Author: Fangrui Song
Date: 2024-10-07T23:07:50-07:00
New Revision: c35214c131c0bc7f54dc18ceb75c75cba89f58ee

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

LOG: [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.
(https://github.com/llvm/llvm-project/pull/111260#issuecomment-2397498034)

Added: 
    

Modified: 
    lld/ELF/Target.h

Removed: 
    


################################################################################
diff  --git a/lld/ELF/Target.h b/lld/ELF/Target.h
index 0bc5e3881190e5..ca2706aefc263b 100644
--- a/lld/ELF/Target.h
+++ b/lld/ELF/Target.h
@@ -124,20 +124,20 @@ class TargetInfo {
   bool gotBaseSymInGotPlt = false;
 
   static constexpr RelType noneRel = 0;
-  RelType copyRel;
-  RelType gotRel;
-  RelType pltRel;
-  RelType relativeRel;
-  RelType iRelativeRel;
-  RelType symbolicRel;
-  RelType tlsDescRel;
-  RelType tlsGotRel;
-  RelType tlsModuleIndexRel;
-  RelType tlsOffsetRel;
+  RelType copyRel = 0;
+  RelType gotRel = 0;
+  RelType pltRel = 0;
+  RelType relativeRel = 0;
+  RelType iRelativeRel = 0;
+  RelType symbolicRel = 0;
+  RelType tlsDescRel = 0;
+  RelType tlsGotRel = 0;
+  RelType tlsModuleIndexRel = 0;
+  RelType tlsOffsetRel = 0;
   unsigned gotEntrySize = ctx.arg.wordsize;
-  unsigned pltEntrySize;
-  unsigned pltHeaderSize;
-  unsigned ipltEntrySize;
+  unsigned pltEntrySize = 0;
+  unsigned pltHeaderSize = 0;
+  unsigned ipltEntrySize = 0;
 
   // At least on x86_64 positions 1 and 2 are used by the first plt entry
   // to support lazy loading.
@@ -156,7 +156,7 @@ class TargetInfo {
 
   // A 4-byte field corresponding to one or more trap instructions, used to pad
   // executable OutputSections.
-  std::array<uint8_t, 4> trapInstr;
+  std::array<uint8_t, 4> trapInstr = {};
 
   // Stores the NOP instructions of 
diff erent sizes for the target and is used
   // to pad sections that are relaxed.


        


More information about the llvm-commits mailing list