[lld] r240161 - COFF: Don't add new undefined symbols for /alternatename.
Rui Ueyama
ruiu at google.com
Fri Jun 19 12:23:44 PDT 2015
Author: ruiu
Date: Fri Jun 19 14:23:43 2015
New Revision: 240161
URL: http://llvm.org/viewvc/llvm-project?rev=240161&view=rev
Log:
COFF: Don't add new undefined symbols for /alternatename.
Alternatename option is in the form of /alternatename:<from>=<to>.
It's effect is to resolve <from> as <to> if <from> is still undefined
at end of name resolution.
If <from> is not undefined but completely a new symbol, alternatename
shouldn't do anything. Previously, it introduced a new undefined
symbol for <from>, which resulted in undefined symbol error.
Modified:
lld/trunk/COFF/Driver.cpp
lld/trunk/COFF/SymbolTable.cpp
lld/trunk/test/COFF/alternatename.test
Modified: lld/trunk/COFF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.cpp?rev=240161&r1=240160&r2=240161&view=diff
==============================================================================
--- lld/trunk/COFF/Driver.cpp (original)
+++ lld/trunk/COFF/Driver.cpp Fri Jun 19 14:23:43 2015
@@ -525,12 +525,6 @@ bool LinkerDriver::link(int Argc, const
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;
Modified: lld/trunk/COFF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/SymbolTable.cpp?rev=240161&r1=240160&r2=240161&view=diff
==============================================================================
--- lld/trunk/COFF/SymbolTable.cpp (original)
+++ lld/trunk/COFF/SymbolTable.cpp Fri Jun 19 14:23:43 2015
@@ -232,10 +232,19 @@ std::error_code SymbolTable::addUndefine
// 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();
}
Modified: lld/trunk/test/COFF/alternatename.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/alternatename.test?rev=240161&r1=240160&r2=240161&view=diff
==============================================================================
--- lld/trunk/test/COFF/alternatename.test (original)
+++ lld/trunk/test/COFF/alternatename.test Fri Jun 19 14:23:43 2015
@@ -4,6 +4,7 @@
# 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
More information about the llvm-commits
mailing list