[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.
This commit is contained in:
Jacek Caban
2024-11-15 16:14:37 +01:00
committed by GitHub
parent 0fb8fac5d6
commit a9d94834cd
5 changed files with 38 additions and 8 deletions

View File

@@ -756,8 +756,15 @@ Error writeImportLibrary(StringRef ImportName, StringRef Path,
}
Name = std::move(*MangledName);
} else if (!E.Noname && ExportName.empty()) {
std::optional<std::string> DemangledName =
getArm64ECDemangledFunctionName(Name);
if (!DemangledName)
return make_error<StringError>(
StringRef(Twine("Invalid ARM64EC function name '" + Name + "'")
.str()),
object_error::parse_failed);
NameType = IMPORT_NAME_EXPORTAS;
ExportName = std::move(*getArm64ECDemangledFunctionName(Name));
ExportName = std::move(*DemangledName);
}
}

View File

@@ -243,8 +243,14 @@ int llvm::dlltoolDriverMain(llvm::ArrayRef<const char *> ArgsArr) {
}
std::string Path = std::string(Args.getLastArgValue(OPT_l));
if (!Path.empty() && writeImportLibrary(OutputFile, Path, Exports, Machine,
/*MinGW=*/true, NativeExports))
return 1;
if (!Path.empty()) {
if (Error E = writeImportLibrary(OutputFile, Path, Exports, Machine,
/*MinGW=*/true, NativeExports)) {
handleAllErrors(std::move(E), [&](const ErrorInfoBase &EI) {
llvm::errs() << EI.message() << "\n";
});
return 1;
}
}
return 0;
}

View File

@@ -419,10 +419,15 @@ int llvm::libDriverMain(ArrayRef<const char *> ArgsArr) {
OutputFile = std::move(NativeDef->OutputFile);
}
return writeImportLibrary(OutputFile, OutputPath, Def->Exports, LibMachine,
/*MinGW=*/false, NativeExports)
? 1
: 0;
if (Error E =
writeImportLibrary(OutputFile, OutputPath, Def->Exports, LibMachine,
/*MinGW=*/false, NativeExports)) {
handleAllErrors(std::move(E), [&](const ErrorInfoBase &EI) {
llvm::errs() << OutputPath << ": " << EI.message() << "\n";
});
return 1;
}
return 0;
}
// If no input files and not told otherwise, silently do nothing to match

View File

@@ -0,0 +1,6 @@
; RUN: not llvm-dlltool -m arm64ec -d %s -l %t.lib 2>&1 | FileCheck %s
; CHECK: Invalid ARM64EC function name '?func'
LIBRARY test.dll
EXPORTS
?func

View File

@@ -0,0 +1,6 @@
; RUN: not llvm-lib -machine:arm64ec -def:%s -out:%t.lib 2>&1 | FileCheck %s
; CHECK: Invalid ARM64EC function name '?func'
LIBRARY test.dll
EXPORTS
?func