aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Object/COFFImportFile.cpp
diff options
context:
space:
mode:
authorMartin Storsjö <martin@martin.st>2024-07-16 23:10:29 +0300
committerGitHub <noreply@github.com>2024-07-16 23:10:29 +0300
commit80e18b93c5abfcbf296b6e2b45cea1ee77633f1e (patch)
tree2c376da8716df1c5e78f5d6265b6c5a41c2586af /llvm/lib/Object/COFFImportFile.cpp
parentd01d9abf851fe688dd5f24649db2728431ca5c0d (diff)
downloadllvm-80e18b93c5abfcbf296b6e2b45cea1ee77633f1e.zip
llvm-80e18b93c5abfcbf296b6e2b45cea1ee77633f1e.tar.gz
llvm-80e18b93c5abfcbf296b6e2b45cea1ee77633f1e.tar.bz2
[llvm-dlltool] Remove the i386 underscore prefix from COFFImportFile::ImportName. NFC. (#98226)
On i386, regular C level symbols are given an underscore prefix in the symbols on the object file level. However, the exported names from DLLs usually don't have this leading underscore. When specified in a def file like "symbol == dllname", the "dllname" is the name of the exported symbol from the DLL, which will be linked against from an object file symbol named "_symbol" (on i386). The mechanism where one symbol is redirected to another one in an import library is implemented with weak aliases. In that case, we need to have the object file symbol level name for the target of the import, as we make one object file symbol point at another one. Therefore, we added an underscore to the ImportName field. (This mechanism, with weak aliases, only works as long as the target also is exported as is, in that form - this issue is dealt with in a later commit.) For clarity, for potentially handling the import renaming in other ways, store the ImportName field unprefixed, containing the actual name to import from the DLL. When creating the aliases, add the prefix as needed. This requires passing an extra AddUnderscores parameter to the writeImportLibrary function; this is a temporary measure, until alias creation is reworked in a later commit. This doesn't preserve the corner case of checking !isDecorated() before adding the prefix. This corner case isn't tested by any of our existing tests, and only would trigger for fastcall/vectorcall/MS C++ functions - while these kinds of renames primarily are used in mingw-w64-crt import libraries (which primarily handle cdecl and stdcall functions).
Diffstat (limited to 'llvm/lib/Object/COFFImportFile.cpp')
-rw-r--r--llvm/lib/Object/COFFImportFile.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/llvm/lib/Object/COFFImportFile.cpp b/llvm/lib/Object/COFFImportFile.cpp
index a9f150a..03af492 100644
--- a/llvm/lib/Object/COFFImportFile.cpp
+++ b/llvm/lib/Object/COFFImportFile.cpp
@@ -645,7 +645,8 @@ NewArchiveMember ObjectFactory::createWeakExternal(StringRef Sym,
Error writeImportLibrary(StringRef ImportName, StringRef Path,
ArrayRef<COFFShortExport> Exports,
MachineTypes Machine, bool MinGW,
- ArrayRef<COFFShortExport> NativeExports) {
+ ArrayRef<COFFShortExport> NativeExports,
+ bool AddUnderscores) {
MachineTypes NativeMachine = Machine;
if (isArm64EC(Machine)) {
@@ -691,10 +692,15 @@ Error writeImportLibrary(StringRef ImportName, StringRef Path,
}
if (!E.ImportName.empty() && Name != E.ImportName) {
+ StringRef Prefix = "";
+ if (Machine == IMAGE_FILE_MACHINE_I386 && AddUnderscores)
+ Prefix = "_";
+
if (ImportType == IMPORT_CODE)
- Members.push_back(
- OF.createWeakExternal(E.ImportName, Name, false, M));
- Members.push_back(OF.createWeakExternal(E.ImportName, Name, true, M));
+ Members.push_back(OF.createWeakExternal((Prefix + E.ImportName).str(),
+ Name, false, M));
+ Members.push_back(OF.createWeakExternal((Prefix + E.ImportName).str(),
+ Name, true, M));
continue;
}