From f6c27eb345ff9c9b1a02a94df930ef2074aae760 Mon Sep 17 00:00:00 2001 From: Alexander Shaposhnikov Date: Mon, 7 Oct 2019 21:14:22 +0000 Subject: [PATCH] [llvm-lipo] Relax the check of the specified input file architecture cctools lipo only compares the cputypes when it verifies that the specified (via -arch) input file and the architecture match. This diff adjusts the behavior of llvm-lipo accordingly. Differential revision: https://reviews.llvm.org/D68319 Test plan: make check-all git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@373966 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llvm-lipo/llvm-lipo.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tools/llvm-lipo/llvm-lipo.cpp b/tools/llvm-lipo/llvm-lipo.cpp index 5eb3332c02e..e746db41405 100644 --- a/tools/llvm-lipo/llvm-lipo.cpp +++ b/tools/llvm-lipo/llvm-lipo.cpp @@ -23,6 +23,7 @@ #include "llvm/Support/FileOutputBuffer.h" #include "llvm/Support/InitLLVM.h" #include "llvm/Support/WithColor.h" +#include "llvm/TextAPI/MachO/Architecture.h" using namespace llvm; using namespace llvm::object; @@ -438,14 +439,19 @@ readInputBinaries(ArrayRef InputFiles) { if (!B->isArchive() && !B->isMachO() && !B->isMachOUniversalBinary()) reportError("File " + IF.FileName + " has unsupported binary format"); if (IF.ArchType && (B->isMachO() || B->isArchive())) { - const auto ArchType = - B->isMachO() ? Slice(cast(B)).getArchString() - : Slice(cast(B)).getArchString(); - if (Triple(*IF.ArchType).getArch() != Triple(ArchType).getArch()) + const auto S = B->isMachO() ? Slice(cast(B)) + : Slice(cast(B)); + const auto SpecifiedCPUType = + MachO::getCPUTypeFromArchitecture( + MachO::mapToArchitecture(Triple(*IF.ArchType))) + .first; + // For compatibility with cctools' lipo the comparison is relaxed just to + // checking cputypes. + if (S.getCPUType() != SpecifiedCPUType) reportError("specified architecture: " + *IF.ArchType + " for file: " + B->getFileName() + - " does not match the file's architecture (" + ArchType + - ")"); + " does not match the file's architecture (" + + S.getArchString() + ")"); } InputBinaries.push_back(std::move(*BinaryOrErr)); } -- 2.40.0