Skip to content

Commit a9d9483

Browse files
authored
[llvm-lib][llvm-dlltool] Fix handling of invalid ARM64EC function names (#116250)
This is a follow-up to #115567. Emit an error for invalid function names, similar to MSVC's `lib.exe` behavior. Returning an error from `writeImportLibrary` exposed bugs in error handling by its callers, which have been addressed in this patch.
1 parent 0fb8fac commit a9d9483

File tree

5 files changed

+38
-8
lines changed

5 files changed

+38
-8
lines changed

llvm/lib/Object/COFFImportFile.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,8 +756,15 @@ Error writeImportLibrary(StringRef ImportName, StringRef Path,
756756
}
757757
Name = std::move(*MangledName);
758758
} else if (!E.Noname && ExportName.empty()) {
759+
std::optional<std::string> DemangledName =
760+
getArm64ECDemangledFunctionName(Name);
761+
if (!DemangledName)
762+
return make_error<StringError>(
763+
StringRef(Twine("Invalid ARM64EC function name '" + Name + "'")
764+
.str()),
765+
object_error::parse_failed);
759766
NameType = IMPORT_NAME_EXPORTAS;
760-
ExportName = std::move(*getArm64ECDemangledFunctionName(Name));
767+
ExportName = std::move(*DemangledName);
761768
}
762769
}
763770

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,14 @@ int llvm::dlltoolDriverMain(llvm::ArrayRef<const char *> ArgsArr) {
243243
}
244244

245245
std::string Path = std::string(Args.getLastArgValue(OPT_l));
246-
if (!Path.empty() && writeImportLibrary(OutputFile, Path, Exports, Machine,
247-
/*MinGW=*/true, NativeExports))
248-
return 1;
246+
if (!Path.empty()) {
247+
if (Error E = writeImportLibrary(OutputFile, Path, Exports, Machine,
248+
/*MinGW=*/true, NativeExports)) {
249+
handleAllErrors(std::move(E), [&](const ErrorInfoBase &EI) {
250+
llvm::errs() << EI.message() << "\n";
251+
});
252+
return 1;
253+
}
254+
}
249255
return 0;
250256
}

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -419,10 +419,15 @@ int llvm::libDriverMain(ArrayRef<const char *> ArgsArr) {
419419
OutputFile = std::move(NativeDef->OutputFile);
420420
}
421421

422-
return writeImportLibrary(OutputFile, OutputPath, Def->Exports, LibMachine,
423-
/*MinGW=*/false, NativeExports)
424-
? 1
425-
: 0;
422+
if (Error E =
423+
writeImportLibrary(OutputFile, OutputPath, Def->Exports, LibMachine,
424+
/*MinGW=*/false, NativeExports)) {
425+
handleAllErrors(std::move(E), [&](const ErrorInfoBase &EI) {
426+
llvm::errs() << OutputPath << ": " << EI.message() << "\n";
427+
});
428+
return 1;
429+
}
430+
return 0;
426431
}
427432

428433
// If no input files and not told otherwise, silently do nothing to match
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
; RUN: not llvm-dlltool -m arm64ec -d %s -l %t.lib 2>&1 | FileCheck %s
2+
; CHECK: Invalid ARM64EC function name '?func'
3+
4+
LIBRARY test.dll
5+
EXPORTS
6+
?func
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
; RUN: not llvm-lib -machine:arm64ec -def:%s -out:%t.lib 2>&1 | FileCheck %s
2+
; CHECK: Invalid ARM64EC function name '?func'
3+
4+
LIBRARY test.dll
5+
EXPORTS
6+
?func

0 commit comments

Comments
 (0)