From 205dbe759d3517bb01cd268544ffb57d7891deef Mon Sep 17 00:00:00 2001 From: vg0204 Date: Thu, 11 Jul 2024 14:05:34 +0530 Subject: [PATCH] [LLD] Zero-initialization & explicit set-up of isUsedinRegObject in Symbol class 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. Eventually, the issue was about not handling exported symbols properly, when dealing with defining undefined symbols for COFF linker. It got resolved by explicit setting up the isUsedinRegularObject bit around the ctor invocation of symbol class in replaceSymbol API. --- lld/COFF/Symbols.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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(static_cast(nullptr)) == nullptr && "Not a Symbol"); bool canInline = s->canInline; + bool isUsedInRegularObj = s->isUsedInRegularObj; new (s) T(std::forward(arg)...); s->canInline = canInline; + s->isUsedInRegularObj = isUsedInRegularObj; } } // namespace coff