Skip to content

Commit 4612208

Browse files
authored
[Object][COFF][NFC] Make writeImportLibrary NativeExports argument optional. (#81600)
It's not interesting for majority of downstream users.
1 parent 742ec3a commit 4612208

File tree

5 files changed

+26
-18
lines changed

5 files changed

+26
-18
lines changed

lld/COFF/Driver.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ std::string LinkerDriver::getImportName(bool asLib) {
939939

940940
void LinkerDriver::createImportLibrary(bool asLib) {
941941
llvm::TimeTraceScope timeScope("Create import library");
942-
std::vector<COFFShortExport> exports, nativeExports;
942+
std::vector<COFFShortExport> exports;
943943
for (Export &e1 : ctx.config.exports) {
944944
COFFShortExport e2;
945945
e2.Name = std::string(e1.name);
@@ -958,8 +958,8 @@ void LinkerDriver::createImportLibrary(bool asLib) {
958958
std::string path = getImplibPath();
959959

960960
if (!ctx.config.incremental) {
961-
checkError(writeImportLibrary(libName, path, exports, nativeExports,
962-
ctx.config.machine, ctx.config.mingw));
961+
checkError(writeImportLibrary(libName, path, exports, ctx.config.machine,
962+
ctx.config.mingw));
963963
return;
964964
}
965965

@@ -968,8 +968,8 @@ void LinkerDriver::createImportLibrary(bool asLib) {
968968
ErrorOr<std::unique_ptr<MemoryBuffer>> oldBuf = MemoryBuffer::getFile(
969969
path, /*IsText=*/false, /*RequiresNullTerminator=*/false);
970970
if (!oldBuf) {
971-
checkError(writeImportLibrary(libName, path, exports, nativeExports,
972-
ctx.config.machine, ctx.config.mingw));
971+
checkError(writeImportLibrary(libName, path, exports, ctx.config.machine,
972+
ctx.config.mingw));
973973
return;
974974
}
975975

@@ -979,7 +979,7 @@ void LinkerDriver::createImportLibrary(bool asLib) {
979979
fatal("cannot create temporary file for import library " + path + ": " +
980980
ec.message());
981981

982-
if (Error e = writeImportLibrary(libName, tmpName, exports, nativeExports,
982+
if (Error e = writeImportLibrary(libName, tmpName, exports,
983983
ctx.config.machine, ctx.config.mingw)) {
984984
checkError(std::move(e));
985985
return;

llvm/include/llvm/Object/COFFImportFile.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,20 @@ struct COFFShortExport {
135135
}
136136
};
137137

138-
Error writeImportLibrary(StringRef ImportName, StringRef Path,
139-
ArrayRef<COFFShortExport> Exports,
140-
ArrayRef<COFFShortExport> NativeExports,
141-
COFF::MachineTypes Machine, bool MinGW);
138+
/// Writes a COFF import library containing entries described by the Exports
139+
/// array.
140+
///
141+
/// For hybrid targets such as ARM64EC, additional native entry points can be
142+
/// exposed using the NativeExports parameter. When NativeExports is used, the
143+
/// output import library will expose these native ARM64 imports alongside the
144+
/// entries described in the Exports array. Such a library can be used for
145+
/// linking both ARM64EC and pure ARM64 objects, and the linker will pick only
146+
/// the exports relevant to the target platform. For non-hybrid targets,
147+
/// the NativeExports parameter should not be used.
148+
Error writeImportLibrary(
149+
StringRef ImportName, StringRef Path, ArrayRef<COFFShortExport> Exports,
150+
COFF::MachineTypes Machine, bool MinGW,
151+
ArrayRef<COFFShortExport> NativeExports = std::nullopt);
142152

143153
} // namespace object
144154
} // namespace llvm

llvm/lib/Object/COFFImportFile.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,8 +625,8 @@ NewArchiveMember ObjectFactory::createWeakExternal(StringRef Sym,
625625

626626
Error writeImportLibrary(StringRef ImportName, StringRef Path,
627627
ArrayRef<COFFShortExport> Exports,
628-
ArrayRef<COFFShortExport> NativeExports,
629-
MachineTypes Machine, bool MinGW) {
628+
MachineTypes Machine, bool MinGW,
629+
ArrayRef<COFFShortExport> NativeExports) {
630630

631631
MachineTypes NativeMachine =
632632
isArm64EC(Machine) ? IMAGE_FILE_MACHINE_ARM64 : Machine;

llvm/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,8 @@ int llvm::dlltoolDriverMain(llvm::ArrayRef<const char *> ArgsArr) {
215215
}
216216
}
217217

218-
if (!Path.empty() &&
219-
writeImportLibrary(Def->OutputFile, Path, Def->Exports, std::nullopt,
220-
Machine, /*MinGW=*/true))
218+
if (!Path.empty() && writeImportLibrary(Def->OutputFile, Path, Def->Exports,
219+
Machine, /*MinGW=*/true))
221220
return 1;
222221
return 0;
223222
}

llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -418,9 +418,8 @@ int llvm::libDriverMain(ArrayRef<const char *> ArgsArr) {
418418
OutputFile = std::move(NativeDef->OutputFile);
419419
}
420420

421-
return writeImportLibrary(OutputFile, OutputPath, Def->Exports,
422-
NativeExports, LibMachine,
423-
/*MinGW=*/false)
421+
return writeImportLibrary(OutputFile, OutputPath, Def->Exports, LibMachine,
422+
/*MinGW=*/false, NativeExports)
424423
? 1
425424
: 0;
426425
}

0 commit comments

Comments
 (0)