for (auto &P : Config->AlternateNames) {
StringRef From = P.first;
StringRef To = P.second;
- // If From is already resolved to a Defined type, do nothing.
- // Otherwise, rename it to see if To can be resolved instead.
- if (Symtab.find(From))
- continue;
- if (Config->Verbose)
- llvm::outs() << "/alternatename:" << From << "=" << To << "\n";
if (auto EC = Symtab.rename(From, To)) {
llvm::errs() << EC.message() << "\n";
return false;
// Resolve To, and make From an alias to To.
std::error_code SymbolTable::rename(StringRef From, StringRef To) {
+ // If From is not undefined, do nothing.
+ // Otherwise, rename it to see if To can be resolved instead.
+ auto It = Symtab.find(From);
+ if (It == Symtab.end())
+ return std::error_code();
+ Symbol *Sym = It->second;
+ if (!isa<Undefined>(Sym->Body))
+ return std::error_code();
SymbolBody *Body = new (Alloc) Undefined(To);
if (auto EC = resolve(Body))
return EC;
- Symtab[From]->Body = Body->getReplacement();
+ Sym->Body = Body->getReplacement();
+ Body->setBackref(Sym);
return std::error_code();
}
# RUN: lld -flavor link2 /entry:foo /subsystem:console \
# RUN: /alternatename:foo=mainCRTStartup \
# RUN: /alternatename:foo=mainCRTStartup \
+# RUN: /alternatename:nosuchsym1=nosuchsym2 \
# RUN: /out:%t.exe %t.obj
# RUN: yaml2obj < %s > %t.obj