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

View File

@ -91,6 +91,14 @@ bool Symbol::isLive() const {
return true; 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) { void Symbol::replaceKeepingName(Symbol *other, size_t size) {
StringRef origName = getName(); StringRef origName = getName();
memcpy(this, other, size); memcpy(this, other, size);

View File

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