[PATCH] D63735: [MachOObjectFile]Added Valid Architecture Function
Anusha Basana via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 24 12:29:04 PDT 2019
anushabasana created this revision.
anushabasana added reviewers: smeenai, alexshap, compnerd, mtrent.
anushabasana added a project: LLVM.
Herald added subscribers: llvm-commits, hiraditya.
Added array of valid architectures and function returning array.
Modified llvm-lipo to include list of valid architectures in error message for invalid arch.
Test Plan:
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D63735
Files:
llvm/include/llvm/Object/MachO.h
llvm/lib/Object/MachOObjectFile.cpp
llvm/test/tools/llvm-lipo/thin-universal-binary.test
llvm/tools/llvm-lipo/llvm-lipo.cpp
Index: llvm/tools/llvm-lipo/llvm-lipo.cpp
===================================================================
--- llvm/tools/llvm-lipo/llvm-lipo.cpp
+++ llvm/tools/llvm-lipo/llvm-lipo.cpp
@@ -93,8 +93,17 @@
} // end namespace
static void validateArchitectureName(StringRef ArchitectureName) {
- if (Triple(ArchitectureName).getArch() == Triple::ArchType::UnknownArch)
- reportError("Invalid architecture: " + ArchitectureName);
+ if (!MachOObjectFile::isValidArch(ArchitectureName)) {
+ std::string Buf;
+ raw_string_ostream OS(Buf);
+ OS << "Invalid architecture: " << ArchitectureName
+ << "\nValid architecture flags are:";
+ ArrayRef<StringRef> valid = MachOObjectFile::getValidArchs();
+
+ for (auto arch : valid)
+ OS << " " << arch;
+ reportError(OS.str());
+ }
}
static Config parseLipoOptions(ArrayRef<const char *> ArgsArr) {
Index: llvm/test/tools/llvm-lipo/thin-universal-binary.test
===================================================================
--- llvm/test/tools/llvm-lipo/thin-universal-binary.test
+++ llvm/test/tools/llvm-lipo/thin-universal-binary.test
@@ -1,7 +1,7 @@
# RUN: yaml2obj %s > %t
-# RUN: not llvm-lipo %t -thin arc -output %t.out 2>&1 | FileCheck --check-prefix=ARCH_NOT_IN_FILE %s
-# ARCH_NOT_IN_FILE: does not contain the specified architecture arc to thin it to
+# RUN: not llvm-lipo %t -thin arm64_32 -output %t.out 2>&1 | FileCheck --check-prefix=ARCH_NOT_IN_FILE %s
+# ARCH_NOT_IN_FILE: does not contain the specified architecture arm64_32 to thin it to
# RUN: not llvm-lipo %t -thin aarch101 -output %t.out 2>&1 | FileCheck --check-prefix=INVALID_ARCH %s
# INVALID_ARCH: Invalid architecture: aarch101
Index: llvm/lib/Object/MachOObjectFile.cpp
===================================================================
--- llvm/lib/Object/MachOObjectFile.cpp
+++ llvm/lib/Object/MachOObjectFile.cpp
@@ -55,6 +55,11 @@
char segname[16];
};
+ std::array<StringRef, 17> validArchs = {
+ "i386", "x86_64", "x86_64h", "armv4t", "arm", "armv5e",
+ "armv6", "armv6m", "armv7", "armv7em", "armv7k", "armv7m",
+ "armv7s", "arm64", "arm64_32", "ppc", "ppc64"};
+
} // end anonymous namespace
static Error malformedError(const Twine &Msg) {
@@ -2718,25 +2723,12 @@
}
bool MachOObjectFile::isValidArch(StringRef ArchFlag) {
- return StringSwitch<bool>(ArchFlag)
- .Case("i386", true)
- .Case("x86_64", true)
- .Case("x86_64h", true)
- .Case("armv4t", true)
- .Case("arm", true)
- .Case("armv5e", true)
- .Case("armv6", true)
- .Case("armv6m", true)
- .Case("armv7", true)
- .Case("armv7em", true)
- .Case("armv7k", true)
- .Case("armv7m", true)
- .Case("armv7s", true)
- .Case("arm64", true)
- .Case("arm64_32", true)
- .Case("ppc", true)
- .Case("ppc64", true)
- .Default(false);
+ return std::find(validArchs.begin(), validArchs.end(), ArchFlag) !=
+ validArchs.end();
+}
+
+ArrayRef<StringRef> MachOObjectFile::getValidArchs() {
+ return ArrayRef<StringRef>(validArchs);
}
Triple::ArchType MachOObjectFile::getArch() const {
Index: llvm/include/llvm/Object/MachO.h
===================================================================
--- llvm/include/llvm/Object/MachO.h
+++ llvm/include/llvm/Object/MachO.h
@@ -571,6 +571,7 @@
const char **McpuDefault = nullptr,
const char **ArchFlag = nullptr);
static bool isValidArch(StringRef ArchFlag);
+ static ArrayRef<StringRef> getValidArchs();
static Triple getHostArch();
bool isRelocatableObject() const override;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63735.206280.patch
Type: text/x-patch
Size: 3669 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190624/8befb0a7/attachment.bin>
More information about the llvm-commits
mailing list