[lld] 4612208 - [Object][COFF][NFC] Make writeImportLibrary NativeExports argument optional. (#81600)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 13 06:17:31 PST 2024
Author: Jacek Caban
Date: 2024-02-13T15:17:28+01:00
New Revision: 46122082a61ef5bb2871d2d9158739133ad0e113
URL: https://github.com/llvm/llvm-project/commit/46122082a61ef5bb2871d2d9158739133ad0e113
DIFF: https://github.com/llvm/llvm-project/commit/46122082a61ef5bb2871d2d9158739133ad0e113.diff
LOG: [Object][COFF][NFC] Make writeImportLibrary NativeExports argument optional. (#81600)
It's not interesting for majority of downstream users.
Added:
Modified:
lld/COFF/Driver.cpp
llvm/include/llvm/Object/COFFImportFile.h
llvm/lib/Object/COFFImportFile.cpp
llvm/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp
llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
Removed:
################################################################################
diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index 091aa0df207410..22ee2f133be98a 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -939,7 +939,7 @@ std::string LinkerDriver::getImportName(bool asLib) {
void LinkerDriver::createImportLibrary(bool asLib) {
llvm::TimeTraceScope timeScope("Create import library");
- std::vector<COFFShortExport> exports, nativeExports;
+ std::vector<COFFShortExport> exports;
for (Export &e1 : ctx.config.exports) {
COFFShortExport e2;
e2.Name = std::string(e1.name);
@@ -958,8 +958,8 @@ void LinkerDriver::createImportLibrary(bool asLib) {
std::string path = getImplibPath();
if (!ctx.config.incremental) {
- checkError(writeImportLibrary(libName, path, exports, nativeExports,
- ctx.config.machine, ctx.config.mingw));
+ checkError(writeImportLibrary(libName, path, exports, ctx.config.machine,
+ ctx.config.mingw));
return;
}
@@ -968,8 +968,8 @@ void LinkerDriver::createImportLibrary(bool asLib) {
ErrorOr<std::unique_ptr<MemoryBuffer>> oldBuf = MemoryBuffer::getFile(
path, /*IsText=*/false, /*RequiresNullTerminator=*/false);
if (!oldBuf) {
- checkError(writeImportLibrary(libName, path, exports, nativeExports,
- ctx.config.machine, ctx.config.mingw));
+ checkError(writeImportLibrary(libName, path, exports, ctx.config.machine,
+ ctx.config.mingw));
return;
}
@@ -979,7 +979,7 @@ void LinkerDriver::createImportLibrary(bool asLib) {
fatal("cannot create temporary file for import library " + path + ": " +
ec.message());
- if (Error e = writeImportLibrary(libName, tmpName, exports, nativeExports,
+ if (Error e = writeImportLibrary(libName, tmpName, exports,
ctx.config.machine, ctx.config.mingw)) {
checkError(std::move(e));
return;
diff --git a/llvm/include/llvm/Object/COFFImportFile.h b/llvm/include/llvm/Object/COFFImportFile.h
index 23c3e6a1f0784a..402ded0d64fef2 100644
--- a/llvm/include/llvm/Object/COFFImportFile.h
+++ b/llvm/include/llvm/Object/COFFImportFile.h
@@ -135,10 +135,20 @@ struct COFFShortExport {
}
};
-Error writeImportLibrary(StringRef ImportName, StringRef Path,
- ArrayRef<COFFShortExport> Exports,
- ArrayRef<COFFShortExport> NativeExports,
- COFF::MachineTypes Machine, bool MinGW);
+/// Writes a COFF import library containing entries described by the Exports
+/// array.
+///
+/// For hybrid targets such as ARM64EC, additional native entry points can be
+/// exposed using the NativeExports parameter. When NativeExports is used, the
+/// output import library will expose these native ARM64 imports alongside the
+/// entries described in the Exports array. Such a library can be used for
+/// linking both ARM64EC and pure ARM64 objects, and the linker will pick only
+/// the exports relevant to the target platform. For non-hybrid targets,
+/// the NativeExports parameter should not be used.
+Error writeImportLibrary(
+ StringRef ImportName, StringRef Path, ArrayRef<COFFShortExport> Exports,
+ COFF::MachineTypes Machine, bool MinGW,
+ ArrayRef<COFFShortExport> NativeExports = std::nullopt);
} // namespace object
} // namespace llvm
diff --git a/llvm/lib/Object/COFFImportFile.cpp b/llvm/lib/Object/COFFImportFile.cpp
index 9175c3ee2a2c4b..f6f6cf2a1602cf 100644
--- a/llvm/lib/Object/COFFImportFile.cpp
+++ b/llvm/lib/Object/COFFImportFile.cpp
@@ -625,8 +625,8 @@ NewArchiveMember ObjectFactory::createWeakExternal(StringRef Sym,
Error writeImportLibrary(StringRef ImportName, StringRef Path,
ArrayRef<COFFShortExport> Exports,
- ArrayRef<COFFShortExport> NativeExports,
- MachineTypes Machine, bool MinGW) {
+ MachineTypes Machine, bool MinGW,
+ ArrayRef<COFFShortExport> NativeExports) {
MachineTypes NativeMachine =
isArm64EC(Machine) ? IMAGE_FILE_MACHINE_ARM64 : Machine;
diff --git a/llvm/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp b/llvm/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp
index 0749580c78a570..834903857a88eb 100644
--- a/llvm/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp
+++ b/llvm/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp
@@ -215,9 +215,8 @@ int llvm::dlltoolDriverMain(llvm::ArrayRef<const char *> ArgsArr) {
}
}
- if (!Path.empty() &&
- writeImportLibrary(Def->OutputFile, Path, Def->Exports, std::nullopt,
- Machine, /*MinGW=*/true))
+ if (!Path.empty() && writeImportLibrary(Def->OutputFile, Path, Def->Exports,
+ Machine, /*MinGW=*/true))
return 1;
return 0;
}
diff --git a/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp b/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
index 3baa0a08c73d1e..c3015d895230ea 100644
--- a/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
+++ b/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
@@ -418,9 +418,8 @@ int llvm::libDriverMain(ArrayRef<const char *> ArgsArr) {
OutputFile = std::move(NativeDef->OutputFile);
}
- return writeImportLibrary(OutputFile, OutputPath, Def->Exports,
- NativeExports, LibMachine,
- /*MinGW=*/false)
+ return writeImportLibrary(OutputFile, OutputPath, Def->Exports, LibMachine,
+ /*MinGW=*/false, NativeExports)
? 1
: 0;
}
More information about the llvm-commits
mailing list