Skip to content

Commit cfda8c8

Browse files
committed
[COFF] Initialize, save, and restore isUsedByRegularObj
Before this change, SymbolTable::insert set this boolean to a meaningful value before calling the appropriate Symbol constructor via replaceSymbol. I believe this is UB, it is probably valid for a compiler to zero out a bitfield in the constructor, rather than carefully preserving the single bit that existed prevoiusly. After this change, the constructor does the obvious thing, which is to zero initialize this field, and we explicitly copy the bitfield around the constructor call in replaceSymbol. This should be an alternative solution to the problems described in llvm#98447 .
1 parent 2da30f8 commit cfda8c8

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

lld/COFF/Symbols.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ class Symbol {
9898
friend SymbolTable;
9999
explicit Symbol(Kind k, StringRef n = "")
100100
: symbolKind(k), isExternal(true), isCOMDAT(false),
101-
writtenToSymtab(false), pendingArchiveLoad(false), isGCRoot(false),
102-
isRuntimePseudoReloc(false), deferUndefined(false), canInline(true),
103-
isWeak(false), nameSize(n.size()),
104-
nameData(n.empty() ? nullptr : n.data()) {
101+
writtenToSymtab(false), isUsedInRegularObj(false),
102+
pendingArchiveLoad(false), isGCRoot(false), isRuntimePseudoReloc(false),
103+
deferUndefined(false), canInline(true), isWeak(false),
104+
nameSize(n.size()), nameData(n.empty() ? nullptr : n.data()) {
105105
assert((!n.empty() || k <= LastDefinedCOFFKind) &&
106106
"If the name is empty, the Symbol must be a DefinedCOFF.");
107107
}
@@ -498,9 +498,13 @@ void replaceSymbol(Symbol *s, ArgT &&... arg) {
498498
"SymbolUnion not aligned enough");
499499
assert(static_cast<Symbol *>(static_cast<T *>(nullptr)) == nullptr &&
500500
"Not a Symbol");
501+
// These booleans are set to meaningful values during symbol table insertion.
502+
// Save and restore them after constructing the Symbol subclass.
501503
bool canInline = s->canInline;
504+
bool isUsedInRegularObj = s->isUsedInRegularObj;
502505
new (s) T(std::forward<ArgT>(arg)...);
503506
s->canInline = canInline;
507+
s->isUsedInRegularObj = isUsedInRegularObj;
504508
}
505509
} // namespace coff
506510

0 commit comments

Comments
 (0)