[lld] r246620 - COFF: Preserve original spelling of DLL file name.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 2 00:27:31 PDT 2015
Author: ruiu
Date: Wed Sep 2 02:27:31 2015
New Revision: 246620
URL: http://llvm.org/viewvc/llvm-project?rev=246620&view=rev
Log:
COFF: Preserve original spelling of DLL file name.
This patch fixes a subtle incompatibility with MSVC linker.
MSVC linker preserves the original spelling of a DLL in the
import descriptor table. LLD previously converted all
characters to lowercase. Usually this difference is benign,
but if a program explicitly checks for DLL file names, the
program could fail.
Modified:
lld/trunk/COFF/Config.h
lld/trunk/COFF/DLL.cpp
lld/trunk/COFF/InputFiles.cpp
lld/trunk/COFF/Writer.cpp
lld/trunk/test/COFF/export.test
Modified: lld/trunk/COFF/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Config.h?rev=246620&r1=246619&r2=246620&view=diff
==============================================================================
--- lld/trunk/COFF/Config.h (original)
+++ lld/trunk/COFF/Config.h Wed Sep 2 02:27:31 2015
@@ -81,7 +81,7 @@ struct Configuration {
StringRef Implib;
std::vector<Export> Exports;
std::set<std::string> DelayLoads;
- std::map<StringRef, int> DLLOrder;
+ std::map<std::string, int> DLLOrder;
Undefined *DelayLoadHelper = nullptr;
// Used for SafeSEH.
Modified: lld/trunk/COFF/DLL.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/DLL.cpp?rev=246620&r1=246619&r2=246620&view=diff
==============================================================================
--- lld/trunk/COFF/DLL.cpp (original)
+++ lld/trunk/COFF/DLL.cpp Wed Sep 2 02:27:31 2015
@@ -128,13 +128,13 @@ static std::vector<std::vector<DefinedIm
binImports(const std::vector<DefinedImportData *> &Imports) {
// Group DLL-imported symbols by DLL name because that's how
// symbols are layed out in the import descriptor table.
- auto Less = [](StringRef A, StringRef B) {
+ auto Less = [](const std::string &A, const std::string &B) {
return Config->DLLOrder[A] < Config->DLLOrder[B];
};
- std::map<StringRef, std::vector<DefinedImportData *>,
- bool(*)(StringRef, StringRef)> M(Less);
+ std::map<std::string, std::vector<DefinedImportData *>,
+ bool(*)(const std::string &, const std::string &)> M(Less);
for (DefinedImportData *Sym : Imports)
- M[Sym->getDLLName()].push_back(Sym);
+ M[Sym->getDLLName().lower()].push_back(Sym);
std::vector<std::vector<DefinedImportData *>> V;
for (auto &P : M) {
Modified: lld/trunk/COFF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/InputFiles.cpp?rev=246620&r1=246619&r2=246620&view=diff
==============================================================================
--- lld/trunk/COFF/InputFiles.cpp (original)
+++ lld/trunk/COFF/InputFiles.cpp Wed Sep 2 02:27:31 2015
@@ -281,7 +281,7 @@ void ImportFile::parse() {
StringRef Name = StringAlloc.save(StringRef(Buf + sizeof(*Hdr)));
StringRef ImpName = StringAlloc.save(Twine("__imp_") + Name);
const char *NameStart = Buf + sizeof(coff_import_header) + Name.size() + 1;
- DLLName = StringRef(NameStart).lower();
+ DLLName = StringRef(NameStart);
StringRef ExtName;
switch (Hdr->getNameType()) {
case IMPORT_ORDINAL:
Modified: lld/trunk/COFF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Writer.cpp?rev=246620&r1=246619&r2=246620&view=diff
==============================================================================
--- lld/trunk/COFF/Writer.cpp (original)
+++ lld/trunk/COFF/Writer.cpp Wed Sep 2 02:27:31 2015
@@ -369,9 +369,11 @@ void Writer::createImportTables() {
// Initialize DLLOrder so that import entries are ordered in
// the same order as in the command line. (That affects DLL
// initialization order, and this ordering is MSVC-compatible.)
- for (ImportFile *File : Symtab->ImportFiles)
- if (Config->DLLOrder.count(File->DLLName) == 0)
- Config->DLLOrder[File->DLLName] = Config->DLLOrder.size();
+ for (ImportFile *File : Symtab->ImportFiles) {
+ std::string DLL = StringRef(File->DLLName).lower();
+ if (Config->DLLOrder.count(DLL) == 0)
+ Config->DLLOrder[DLL] = Config->DLLOrder.size();
+ }
OutputSection *Text = createSection(".text");
for (ImportFile *File : Symtab->ImportFiles) {
Modified: lld/trunk/test/COFF/export.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/export.test?rev=246620&r1=246619&r2=246620&view=diff
==============================================================================
--- lld/trunk/test/COFF/export.test (original)
+++ lld/trunk/test/COFF/export.test Wed Sep 2 02:27:31 2015
@@ -65,7 +65,7 @@ CHECK5-NEXT: 2 0x1010 fn2
CHECK5-NEXT: 3 0x1008 exportfn1
CHECK5-NEXT: 4 0x1010 exportfn3
-# RUN: lld-link /out:%t.dll /dll %t.obj /export:exportfn1 /export:exportfn2 \
+# RUN: lld-link /out:%t.DLL /dll %t.obj /export:exportfn1 /export:exportfn2 \
# RUN: /export:exportfn1 /export:exportfn2, at 5 >& %t.log
# RUN: FileCheck -check-prefix=CHECK6 %s < %t.log
@@ -74,9 +74,9 @@ CHECK6-NOT: duplicate /export option: ex
# RUN: llvm-nm -M %t.lib | FileCheck --check-prefix=SYMTAB %s
-SYMTAB: __imp_exportfn1 in export.test.tmp.dll
-SYMTAB: exportfn1 in export.test.tmp.dll
-SYMTAB: __imp_exportfn2 in export.test.tmp.dll
-SYMTAB: exportfn2 in export.test.tmp.dll
-SYMTAB: __imp_exportfn3 in export.test.tmp.dll
-SYMTAB: exportfn3 in export.test.tmp.dll
+SYMTAB: __imp_exportfn1 in export.test.tmp.DLL
+SYMTAB: exportfn1 in export.test.tmp.DLL
+SYMTAB: __imp_exportfn2 in export.test.tmp.DLL
+SYMTAB: exportfn2 in export.test.tmp.DLL
+SYMTAB: __imp_exportfn3 in export.test.tmp.DLL
+SYMTAB: exportfn3 in export.test.tmp.DLL
More information about the llvm-commits
mailing list