}
}
+ // Add weak aliases. Weak aliases is a mechanism to give remaining
+ // undefined symbols final chance to be resolved successfully.
+ // This is symbol renaming.
+ for (auto *Arg : Args->filtered(OPT_alternatename)) {
+ StringRef From, To;
+ std::tie(From, To) = StringRef(Arg->getValue()).split('=');
+ if (From.empty() || To.empty()) {
+ llvm::errs() << "/alternatename: invalid argument: "
+ << Arg->getValue() << "\n";
+ return false;
+ }
+ // If it's already resolved as some Defined type, do nothing.
+ // Otherwise, rename it to see if To can be resolved successfully.
+ if (Symtab.find(From))
+ continue;
+ if (auto EC = Symtab.rename(From, To)) {
+ llvm::errs() << EC.message() << "\n";
+ return false;
+ }
+ }
+
// Windows specific -- If entry point name is not given, we need to
// infer that from user-defined entry name. The symbol table takes
// care of details.
return addSymbol(new Undefined(Name));
}
+// Resolve To, and make From an alias to To.
+std::error_code SymbolTable::rename(StringRef From, StringRef To) {
+ SymbolBody *Body = new (Alloc) Undefined(To);
+ if (auto EC = resolve(Body))
+ return EC;
+ Symtab[From]->Body = Body->getReplacement();
+ return std::error_code();
+}
+
std::error_code SymbolTable::addSymbol(SymbolBody *Body) {
OwningSymbols.push_back(std::unique_ptr<SymbolBody>(Body));
return resolve(Body);
// Creates an Undefined symbol for a given name.
std::error_code addUndefined(StringRef Name);
+ // Rename From -> To in the symbol table.
+ std::error_code rename(StringRef From, StringRef To);
+
private:
std::error_code addObject(ObjectFile *File);
std::error_code addArchive(ArchiveFile *File);
--- /dev/null
+# RUN: yaml2obj < %p/Inputs/ret42.yaml > %t.obj
+
+# RUN: lld -flavor link2 /entry:foo /subsystem:console \
+# RUN: /alternatename:foo=mainCRTStartup /out:%t.exe %t.obj