aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
diff options
context:
space:
mode:
authorJacek Caban <jacek@codeweavers.com>2024-02-13 01:49:45 +0100
committerGitHub <noreply@github.com>2024-02-13 01:49:45 +0100
commita38152e2156a467520dae29fa3760802c308d54c (patch)
tree5a32ba1bd272e34f138d201b2588f3862dc88ac1 /llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
parentecd63afafd635d3f37ec25e3ded1db0410e97de3 (diff)
downloadllvm-a38152e2156a467520dae29fa3760802c308d54c.zip
llvm-a38152e2156a467520dae29fa3760802c308d54c.tar.gz
llvm-a38152e2156a467520dae29fa3760802c308d54c.tar.bz2
[llvm-lib] Add support for -defArm64Native argument. (#81426)
This can be used to create import libraries that contain both ARM64EC and native exports. The implementation follows observed MSVC lib.exe behaviour. It's ignored on targets other than ARM64EC.
Diffstat (limited to 'llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp')
-rw-r--r--llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp30
1 files changed, 28 insertions, 2 deletions
diff --git a/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp b/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
index 5d7ec0f..3baa0a08c 100644
--- a/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
+++ b/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
@@ -392,8 +392,34 @@ int llvm::libDriverMain(ArrayRef<const char *> ArgsArr) {
return 1;
}
- return writeImportLibrary(Def->OutputFile, OutputPath, Def->Exports,
- LibMachine,
+ std::vector<COFFShortExport> NativeExports;
+ std::string OutputFile = Def->OutputFile;
+
+ if (isArm64EC(LibMachine) && Args.hasArg(OPT_nativedeffile)) {
+ std::unique_ptr<MemoryBuffer> NativeMB =
+ openFile(Args.getLastArg(OPT_nativedeffile)->getValue());
+ if (!NativeMB)
+ return 1;
+
+ if (!NativeMB->getBufferSize()) {
+ llvm::errs() << "native definition file empty\n";
+ return 1;
+ }
+
+ Expected<COFFModuleDefinition> NativeDef =
+ parseCOFFModuleDefinition(*NativeMB, COFF::IMAGE_FILE_MACHINE_ARM64);
+
+ if (!NativeDef) {
+ llvm::errs() << "error parsing native definition\n"
+ << errorToErrorCode(NativeDef.takeError()).message();
+ return 1;
+ }
+ NativeExports = std::move(NativeDef->Exports);
+ OutputFile = std::move(NativeDef->OutputFile);
+ }
+
+ return writeImportLibrary(OutputFile, OutputPath, Def->Exports,
+ NativeExports, LibMachine,
/*MinGW=*/false)
? 1
: 0;