[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
Mon Apr 10 16:18:45 PDT 2023
This revision was automatically updated to reflect the committed changes.
Closed by commit rG420526fb22f3: [ifs] Print an error when llvm-ifs is supplied with an unknown arch (authored by haowei).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D146672/new/
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,13 @@
"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 createStringError(
+ std::make_error_code(std::errc::invalid_argument),
+ "IFS arch '" + *Stub->Target.ArchString + "' is unsupported");
+ Stub->Target.Arch = eMachine;
}
return std::move(Stub);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146672.512282.patch
Type: text/x-patch
Size: 3015 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230410/2db154f5/attachment.bin>
More information about the llvm-commits
mailing list