summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorMartin Storsjo <martin@martin.st>2018-01-20 11:44:32 +0000
committerMartin Storsjo <martin@martin.st>2018-01-20 11:44:32 +0000
commitf641d0d4f23f76bc6a6e96ab73f1579d8eb0bf4c (patch)
tree69c1c7b0d5853ec29548a499f372662bc82f16de /llvm
parent990eb1fc94583d516163784005173da304dbe758 (diff)
downloadbcm5719-llvm-f641d0d4f23f76bc6a6e96ab73f1579d8eb0bf4c.tar.gz
bcm5719-llvm-f641d0d4f23f76bc6a6e96ab73f1579d8eb0bf4c.zip
[COFF] Keep the underscore on exported decorated stdcall functions in MSVC mode
This (together with the corresponding LLD commit, that contains the testcase updates) fixes PR35733. Differential Revision: https://reviews.llvm.org/D41631 llvm-svn: 323035
Diffstat (limited to 'llvm')
-rw-r--r--llvm/include/llvm/Object/COFFImportFile.h3
-rw-r--r--llvm/lib/Object/COFFImportFile.cpp15
-rw-r--r--llvm/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp2
3 files changed, 15 insertions, 5 deletions
diff --git a/llvm/include/llvm/Object/COFFImportFile.h b/llvm/include/llvm/Object/COFFImportFile.h
index 4b284de679b..7ca416ff1b2 100644
--- a/llvm/include/llvm/Object/COFFImportFile.h
+++ b/llvm/include/llvm/Object/COFFImportFile.h
@@ -98,7 +98,8 @@ struct COFFShortExport {
Error writeImportLibrary(StringRef ImportName, StringRef Path,
ArrayRef<COFFShortExport> Exports,
- COFF::MachineTypes Machine, bool MakeWeakAliases);
+ COFF::MachineTypes Machine, bool MakeWeakAliases,
+ bool MinGW);
} // namespace object
} // namespace llvm
diff --git a/llvm/lib/Object/COFFImportFile.cpp b/llvm/lib/Object/COFFImportFile.cpp
index 93631f1ad81..c249a6d97b4 100644
--- a/llvm/lib/Object/COFFImportFile.cpp
+++ b/llvm/lib/Object/COFFImportFile.cpp
@@ -91,7 +91,15 @@ static void writeStringTable(std::vector<uint8_t> &B,
}
static ImportNameType getNameType(StringRef Sym, StringRef ExtName,
- MachineTypes Machine) {
+ MachineTypes Machine, bool MinGW) {
+ // A decorated stdcall function in MSVC is exported with the
+ // type IMPORT_NAME, and the exported function name includes the
+ // the leading underscore. In MinGW on the other hand, a decorated
+ // stdcall function still omits the underscore (IMPORT_NAME_NOPREFIX).
+ // See the comment in isDecorated in COFFModuleDefinition.cpp for more
+ // details.
+ if (ExtName.startswith("_") && ExtName.contains('@') && !MinGW)
+ return IMPORT_NAME;
if (Sym != ExtName)
return IMPORT_NAME_UNDECORATE;
if (Machine == IMAGE_FILE_MACHINE_I386 && Sym.startswith("_"))
@@ -558,7 +566,8 @@ NewArchiveMember ObjectFactory::createWeakExternal(StringRef Sym,
Error writeImportLibrary(StringRef ImportName, StringRef Path,
ArrayRef<COFFShortExport> Exports,
- MachineTypes Machine, bool MakeWeakAliases) {
+ MachineTypes Machine, bool MakeWeakAliases,
+ bool MinGW) {
std::vector<NewArchiveMember> Members;
ObjectFactory OF(llvm::sys::path::filename(ImportName), Machine);
@@ -589,7 +598,7 @@ Error writeImportLibrary(StringRef ImportName, StringRef Path,
ImportType = IMPORT_CONST;
StringRef SymbolName = E.SymbolName.empty() ? E.Name : E.SymbolName;
- ImportNameType NameType = getNameType(SymbolName, E.Name, Machine);
+ ImportNameType NameType = getNameType(SymbolName, E.Name, Machine, MinGW);
Expected<std::string> Name = E.ExtName.empty()
? SymbolName
: replace(SymbolName, E.Name, E.ExtName);
diff --git a/llvm/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp b/llvm/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp
index 964844922f0..684617e7945 100644
--- a/llvm/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp
+++ b/llvm/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp
@@ -173,7 +173,7 @@ int llvm::dlltoolDriverMain(llvm::ArrayRef<const char *> ArgsArr) {
}
}
- if (writeImportLibrary(Def->OutputFile, Path, Def->Exports, Machine, true))
+ if (writeImportLibrary(Def->OutputFile, Path, Def->Exports, Machine, true, true))
return 1;
return 0;
}
OpenPOWER on IntegriCloud