summaryrefslogtreecommitdiff
path: root/llvm/lib/ToolDrivers
diff options
context:
space:
mode:
authorMartin Storsjö <martin@martin.st>2024-07-16 23:19:39 +0300
committerGitHub <noreply@github.com>2024-07-16 23:19:39 +0300
commitf2d6d74cd2a8dccc5ec47bb5debb003e06249db3 (patch)
treef21031d4cca77c18de8de2e5f8a24d7cda6a650c /llvm/lib/ToolDrivers
parent446965070149d53374ee4d3010789673083fb11c (diff)
[llvm-dlltool] Fix renamed imports without a separate regular import entry (#98229)
Normally, when doing renamed imports, we do this by providing a weak alias, towards another regular import, for the symbol we want to actually import. In a def file, this looks like this: regularfunc renamedfunc == regularfunc However, if we want to link against a function in a DLL, where we (intentionally) don't provide a regular import for that symbol with the name in its DLL, doing the renamed import with a weak alias doesn't work, as there's no symbol that the weak alias can point towards. We can't make up such an import either, as we may intentionally not want to provide a regular import for that name. This situation can either be resolved by using the "long" import library format (as e.g. produced by GNU dlltool), or by using the new short import library name type "export as". This patch implements it by using the "export as" name type. When producing a renamed import, defer emitting it until all regular imports have been produced. If the renamed import refers to a symbol that does exist as a regular import entry, produce a weak alias, just as before. (This implementation also avoids needing to know whether the symbol that the alias points towards actually is prefixed or not, too.) If the renamed import points at a symbol that isn't otherwise available (or is available as a renamed symbol itself), generate an "export as" import entry. This name type is new, and is normally used in ARM64EC import libraries, but can also be used for other architectures.
Diffstat (limited to 'llvm/lib/ToolDrivers')
-rw-r--r--llvm/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp5
1 files changed, 2 insertions, 3 deletions
diff --git a/llvm/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp b/llvm/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp
index 012ad246888f..15e4cac08cd4 100644
--- a/llvm/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp
+++ b/llvm/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp
@@ -243,9 +243,8 @@ int llvm::dlltoolDriverMain(llvm::ArrayRef<const char *> ArgsArr) {
}
std::string Path = std::string(Args.getLastArgValue(OPT_l));
- if (!Path.empty() &&
- writeImportLibrary(OutputFile, Path, Exports, Machine,
- /*MinGW=*/true, NativeExports, AddUnderscores))
+ if (!Path.empty() && writeImportLibrary(OutputFile, Path, Exports, Machine,
+ /*MinGW=*/true, NativeExports))
return 1;
return 0;
}