[lld] r240075 - COFF: Allow identical alternatename options.
Rui Ueyama
ruiu at google.com
Thu Jun 18 16:04:26 PDT 2015
Author: ruiu
Date: Thu Jun 18 18:04:26 2015
New Revision: 240075
URL: http://llvm.org/viewvc/llvm-project?rev=240075&view=rev
Log:
COFF: Allow identical alternatename options.
Alternatename option is in the form of /alternatename:<from>=<to>.
It is an error if there are two options having the same <from> but
different <to>. It is *not* an error if both are the same.
Modified:
lld/trunk/COFF/Config.h
lld/trunk/COFF/Driver.cpp
lld/trunk/COFF/DriverUtils.cpp
lld/trunk/test/COFF/alternatename.test
Modified: lld/trunk/COFF/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Config.h?rev=240075&r1=240074&r2=240075&view=diff
==============================================================================
--- lld/trunk/COFF/Config.h (original)
+++ lld/trunk/COFF/Config.h Thu Jun 18 18:04:26 2015
@@ -71,7 +71,7 @@ struct Configuration {
std::map<StringRef, StringRef> MustMatch;
// Used for /alternatename.
- std::vector<std::pair<StringRef, StringRef>> AlternateNames;
+ std::map<StringRef, StringRef> AlternateNames;
uint64_t ImageBase = 0x140000000;
uint64_t StackReserve = 1024 * 1024;
Modified: lld/trunk/COFF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.cpp?rev=240075&r1=240074&r2=240075&view=diff
==============================================================================
--- lld/trunk/COFF/Driver.cpp (original)
+++ lld/trunk/COFF/Driver.cpp Thu Jun 18 18:04:26 2015
@@ -514,9 +514,9 @@ bool LinkerDriver::link(int Argc, const
// Add weak aliases. Weak aliases is a mechanism to give remaining
// undefined symbols final chance to be resolved successfully.
// This is symbol renaming.
- for (size_t I = 0; I < Config->AlternateNames.size(); ++I) {
- StringRef From = Config->AlternateNames[I].first;
- StringRef To = Config->AlternateNames[I].second;
+ 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))
Modified: lld/trunk/COFF/DriverUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/DriverUtils.cpp?rev=240075&r1=240074&r2=240075&view=diff
==============================================================================
--- lld/trunk/COFF/DriverUtils.cpp (original)
+++ lld/trunk/COFF/DriverUtils.cpp Thu Jun 18 18:04:26 2015
@@ -163,13 +163,12 @@ std::error_code parseAlternateName(Strin
llvm::errs() << "/alternatename: invalid argument: " << S << "\n";
return make_error_code(LLDError::InvalidOption);
}
- for (std::pair<StringRef, StringRef> &P : Config->AlternateNames) {
- if (From == P.first) {
- llvm::errs() << "/alternatename: conflicts: " << S << "\n";
- return make_error_code(LLDError::InvalidOption);
- }
+ auto It = Config->AlternateNames.find(From);
+ if (It != Config->AlternateNames.end() && It->second != To) {
+ llvm::errs() << "/alternatename: conflicts: " << S << "\n";
+ return make_error_code(LLDError::InvalidOption);
}
- Config->AlternateNames.push_back(std::make_pair(From, To));
+ Config->AlternateNames.insert(It, std::make_pair(From, To));
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=240075&r1=240074&r2=240075&view=diff
==============================================================================
--- lld/trunk/test/COFF/alternatename.test (original)
+++ lld/trunk/test/COFF/alternatename.test Thu Jun 18 18:04:26 2015
@@ -1,6 +1,10 @@
# 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
+# RUN: lld -flavor link2 /entry:foo /subsystem:console \
+# RUN: /alternatename:foo=mainCRTStartup \
+# RUN: /alternatename:foo=mainCRTStartup \
+# RUN: /out:%t.exe %t.obj
# RUN: yaml2obj < %s > %t.obj
# RUN: lld -flavor link2 /entry:foo /subsystem:console /out:%t.exe %t.obj
More information about the llvm-commits
mailing list