[LLD][COFF] Introduce Symbol::getDefined helper. (NFC) (#151253)

This commit is contained in:
Jacek Caban 2025-07-31 03:58:45 -07:00 committed by GitHub
parent 1e504bef20
commit aac70d69f6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 14 additions and 10 deletions

View File

@ -1318,13 +1318,9 @@ void LinkerDriver::convertResources() {
}
void LinkerDriver::maybeCreateECExportThunk(StringRef name, Symbol *&sym) {
Defined *def;
if (!sym)
return;
if (auto undef = dyn_cast<Undefined>(sym))
def = undef->getDefinedWeakAlias();
else
def = dyn_cast<Defined>(sym);
Defined *def = sym->getDefined();
if (!def)
return;
@ -1356,11 +1352,7 @@ void LinkerDriver::createECExportThunks() {
Symbol *sym = ctx.symtab.find(targetName);
if (!sym)
continue;
Defined *targetSym;
if (auto undef = dyn_cast<Undefined>(sym))
targetSym = undef->getDefinedWeakAlias();
else
targetSym = dyn_cast<Defined>(sym);
Defined *targetSym = sym->getDefined();
if (!targetSym)
continue;

View File

@ -91,6 +91,14 @@ bool Symbol::isLive() const {
return true;
}
Defined *Symbol::getDefined() {
if (auto d = dyn_cast<Defined>(this))
return d;
if (auto u = dyn_cast<Undefined>(this))
return u->getDefinedWeakAlias();
return nullptr;
}
void Symbol::replaceKeepingName(Symbol *other, size_t size) {
StringRef origName = getName();
memcpy(this, other, size);

View File

@ -95,6 +95,10 @@ public:
symbolKind == LazyDLLSymbolKind;
}
// Get the Defined symbol associated with this symbol, either itself or its
// weak alias.
Defined *getDefined();
private:
void computeName();