[lld] 45c0dec - [LLD] [COFF] Zero-intialization & proper constructor invocation in COFF's Symbol (#98447)

via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 22 03:12:18 PDT 2024


Author: Vikash Gupta
Date: 2024-07-22T15:42:15+05:30
New Revision: 45c0decdda5eee6b4d13d4bf241a45c56e412c05

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

LOG: [LLD] [COFF] Zero-intialization & proper constructor invocation in COFF's Symbol (#98447)

It happened due to lld's COFF linker multiple regression tests failure.
It got reliably reproduced after the needed intialization of
isUsedinRegularObject bit in the Symbol's ctor, but not handled at
replaceSymbol API properly while creating a specific symbol to insert in
symbol table.

So, now while creating the specific symbol using replaceSymbol, by
explicitly setting the value of isUsedinRegularObject to newly created
symbol around the ctor call of symbol would solve the regression failure

Added: 
    

Modified: 
    lld/COFF/Symbols.h

Removed: 
    


################################################################################
diff  --git a/lld/COFF/Symbols.h b/lld/COFF/Symbols.h
index 5ef46f5af6a6c..56b137d56873a 100644
--- a/lld/COFF/Symbols.h
+++ b/lld/COFF/Symbols.h
@@ -98,10 +98,10 @@ class Symbol {
   friend SymbolTable;
   explicit Symbol(Kind k, StringRef n = "")
       : symbolKind(k), isExternal(true), isCOMDAT(false),
-        writtenToSymtab(false), pendingArchiveLoad(false), isGCRoot(false),
-        isRuntimePseudoReloc(false), deferUndefined(false), canInline(true),
-        isWeak(false), nameSize(n.size()),
-        nameData(n.empty() ? nullptr : n.data()) {
+        writtenToSymtab(false), isUsedInRegularObj(false),
+        pendingArchiveLoad(false), isGCRoot(false), isRuntimePseudoReloc(false),
+        deferUndefined(false), canInline(true), isWeak(false),
+        nameSize(n.size()), nameData(n.empty() ? nullptr : n.data()) {
     assert((!n.empty() || k <= LastDefinedCOFFKind) &&
            "If the name is empty, the Symbol must be a DefinedCOFF.");
   }
@@ -499,8 +499,10 @@ void replaceSymbol(Symbol *s, ArgT &&... arg) {
   assert(static_cast<Symbol *>(static_cast<T *>(nullptr)) == nullptr &&
          "Not a Symbol");
   bool canInline = s->canInline;
+  bool isUsedInRegularObj = s->isUsedInRegularObj;
   new (s) T(std::forward<ArgT>(arg)...);
   s->canInline = canInline;
+  s->isUsedInRegularObj = isUsedInRegularObj;
 }
 } // namespace coff
 


        


More information about the llvm-commits mailing list