[PATCH] D146672: [ifs] Print an error when llvm-ifs is supplied with an unknown arch
Haowei Wu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 22 16:55:26 PDT 2023
haowei created this revision.
haowei added reviewers: mcgrathr, phosek, abrachet.
Herald added subscribers: jhenderson, s.egerton, simoncook, asb, hiraditya.
Herald added a project: All.
haowei requested review of this revision.
Herald added subscribers: llvm-commits, pcwang-thead.
Herald added a project: LLVM.
This patch makes llvm-ifs print an error when the arch string from
'--arch' flag or the IFS file 'Arch' field is unknown.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D146672
Files:
llvm/lib/InterfaceStub/IFSHandler.cpp
llvm/test/tools/llvm-ifs/ifs-read-invalid-arch.test
llvm/test/tools/llvm-ifs/write-stub.test
llvm/tools/llvm-ifs/llvm-ifs.cpp
Index: llvm/tools/llvm-ifs/llvm-ifs.cpp
===================================================================
--- llvm/tools/llvm-ifs/llvm-ifs.cpp
+++ llvm/tools/llvm-ifs/llvm-ifs.cpp
@@ -333,9 +333,13 @@
if (!Config.OutputFormat)
OptionNotFound("--output-format", A->getValue());
}
- if (const opt::Arg *A = Args.getLastArg(OPT_arch_EQ))
- Config.OverrideArch = ELF::convertArchNameToEMachine(A->getValue());
-
+ if (const opt::Arg *A = Args.getLastArg(OPT_arch_EQ)) {
+ uint16_t eMachine = ELF::convertArchNameToEMachine(A->getValue());
+ if (eMachine == ELF::EM_NONE) {
+ fatalError(Twine("Unknown arch '") + A->getValue() + "'!");
+ }
+ Config.OverrideArch = eMachine;
+ }
if (const opt::Arg *A = Args.getLastArg(OPT_bitwidth_EQ)) {
size_t Width;
llvm::StringRef S(A->getValue());
Index: llvm/test/tools/llvm-ifs/write-stub.test
===================================================================
--- llvm/test/tools/llvm-ifs/write-stub.test
+++ llvm/test/tools/llvm-ifs/write-stub.test
@@ -38,6 +38,8 @@
# RUN: llvm-ifs --output-elf=- --target=riscv64-linux-gnu %s | llvm-readelf -h - | FileCheck %s --check-prefix=MACHINE
+# RUN: not llvm-ifs --output-elf=- --arch=riscv64 --endianness=little --bitwidth=64 %s 2>&1 | FileCheck %s -DMSG=riscv64 --check-prefix=ARCHERR
+
--- !ifs-v1
IfsVersion: 3.0
NeededLibs:
@@ -207,3 +209,5 @@
# CONFLICTERR: error: Supplied [[MSG]] conflicts with the text stub
# MACHINE: Machine: RISC-V
+
+# ARCHERR: error: Unknown arch '[[MSG]]'!
Index: llvm/test/tools/llvm-ifs/ifs-read-invalid-arch.test
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-ifs/ifs-read-invalid-arch.test
@@ -0,0 +1,15 @@
+# RUN: not llvm-ifs --output-ifs=- %s 2>&1 | FileCheck %s
+
+--- !ifs-v1
+SoName: somelib.so
+IfsVersion: 3.0
+Target: { ObjectFormat: ELF, Arch: RiscV64, Endianness: little, BitWidth: 64 }
+Symbols:
+ - { Name: foo, Type: Func }
+ - { Name: bar, Type: Object, Size: 42 }
+ - { Name: baz, Type: Object, Size: 8 }
+ - { Name: not, Type: Object, Size: 128, Undefined: true }
+ - { Name: nor, Type: Func, Undefined: true }
+...
+
+# CHECK: error: IFS Arch 'RiscV64' is unsupported.
Index: llvm/lib/InterfaceStub/IFSHandler.cpp
===================================================================
--- llvm/lib/InterfaceStub/IFSHandler.cpp
+++ llvm/lib/InterfaceStub/IFSHandler.cpp
@@ -193,8 +193,14 @@
"IFS version " + Stub->IfsVersion.getAsString() + " is unsupported.",
std::make_error_code(std::errc::invalid_argument));
if (Stub->Target.ArchString) {
- Stub->Target.Arch =
+ uint16_t eMachine =
ELF::convertArchNameToEMachine(*Stub->Target.ArchString);
+ if (eMachine == ELF::EM_NONE) {
+ return make_error<StringError>(
+ "IFS Arch '" + *Stub->Target.ArchString + "' is unsupported.",
+ std::make_error_code(std::errc::invalid_argument));
+ }
+ Stub->Target.Arch = eMachine;
}
return std::move(Stub);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146672.507551.patch
Type: text/x-patch
Size: 3034 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230322/85e2cd6d/attachment.bin>
More information about the llvm-commits
mailing list