Skip to content

[llvm-lib][llvm-dlltool] Fix handling of invalid ARM64EC function names #116250

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
Nov 15, 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
9 changes: 8 additions & 1 deletion llvm/lib/Object/COFFImportFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
12 changes: 9 additions & 3 deletions llvm/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
13 changes: 9 additions & 4 deletions llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions llvm/test/tools/llvm-dlltool/arm64ec-invalid-name.test
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions llvm/test/tools/llvm-lib/arm64ec-invalid-name.test
Original file line number Diff line number Diff line change
@@ -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
Loading