diff --git a/llvm/lib/InterfaceStub/IFSHandler.cpp b/llvm/lib/InterfaceStub/IFSHandler.cpp --- a/llvm/lib/InterfaceStub/IFSHandler.cpp +++ b/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); } diff --git a/llvm/test/tools/llvm-ifs/ifs-read-invalid-arch.test b/llvm/test/tools/llvm-ifs/ifs-read-invalid-arch.test new file mode 100644 --- /dev/null +++ b/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 diff --git a/llvm/test/tools/llvm-ifs/write-stub.test b/llvm/test/tools/llvm-ifs/write-stub.test --- a/llvm/test/tools/llvm-ifs/write-stub.test +++ b/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]]' diff --git a/llvm/tools/llvm-ifs/llvm-ifs.cpp b/llvm/tools/llvm-ifs/llvm-ifs.cpp --- a/llvm/tools/llvm-ifs/llvm-ifs.cpp +++ b/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());