Skip to content

[Object][COFF][NFC] Make writeImportLibrary NativeExports argument optional. #81600

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions lld/COFF/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
Expand Down
18 changes: 14 additions & 4 deletions llvm/include/llvm/Object/COFFImportFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Object/COFFImportFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions llvm/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
5 changes: 2 additions & 3 deletions llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down