From 61e54384982afa89539cc76b79a42af883b172f2 Mon Sep 17 00:00:00 2001 From: Vincent Lee Date: Mon, 12 Sep 2022 14:52:08 -0700 Subject: [PATCH] [llvm-lipo] Support object files with bitcode asm llvm-lipo crashes when trying to use inputs that contain bitcode asm instructions. This happens when trying to create universal binaries for LLVM with LTO. https://reviews.llvm.org/D118575 is a similar change that ran into this same issue, and I'm mirroring the same change by registering the targets to fix this issue. Reviewed By: alexander-shaposhnikov, keith Differential Revision: https://reviews.llvm.org/D133729 --- llvm/test/tools/llvm-lipo/Inputs/arm64-asm.ll | 7 +++++++ llvm/test/tools/llvm-lipo/Inputs/x86_64-asm.ll | 7 +++++++ llvm/test/tools/llvm-lipo/create-arch-asm.test | 8 ++++++++ llvm/tools/llvm-lipo/llvm-lipo.cpp | 7 ++++++- 4 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 llvm/test/tools/llvm-lipo/Inputs/arm64-asm.ll create mode 100644 llvm/test/tools/llvm-lipo/Inputs/x86_64-asm.ll create mode 100644 llvm/test/tools/llvm-lipo/create-arch-asm.test diff --git a/llvm/test/tools/llvm-lipo/Inputs/arm64-asm.ll b/llvm/test/tools/llvm-lipo/Inputs/arm64-asm.ll new file mode 100644 index 0000000..41385f6 --- /dev/null +++ b/llvm/test/tools/llvm-lipo/Inputs/arm64-asm.ll @@ -0,0 +1,7 @@ +target triple = "arm64-apple-macosx11.0.0" + +module asm ".desc ___crashreporter_info__, 0x10" + +define void @somesymbol() { + ret void +} diff --git a/llvm/test/tools/llvm-lipo/Inputs/x86_64-asm.ll b/llvm/test/tools/llvm-lipo/Inputs/x86_64-asm.ll new file mode 100644 index 0000000..5e8b6c6 --- /dev/null +++ b/llvm/test/tools/llvm-lipo/Inputs/x86_64-asm.ll @@ -0,0 +1,7 @@ +target triple = "x86_64-apple-macosx11.0.0" + +module asm ".desc ___crashreporter_info__, 0x10" + +define void @somesymbol() { + ret void +} diff --git a/llvm/test/tools/llvm-lipo/create-arch-asm.test b/llvm/test/tools/llvm-lipo/create-arch-asm.test new file mode 100644 index 0000000..47a707f --- /dev/null +++ b/llvm/test/tools/llvm-lipo/create-arch-asm.test @@ -0,0 +1,8 @@ +# RUN: llvm-as %p/Inputs/arm64-asm.ll -o %t-arm64-asm.o +# RUN: llvm-as %p/Inputs/x86_64-asm.ll -o %t-x86_64-asm.o + +# RUN: llvm-lipo %t-arm64-asm.o %t-x86_64-asm.o -create -output %t-universal.o +# RUN: llvm-lipo %t-arm64-asm.o -arch x86_64 %t-x86_64-asm.o -create -output %t-universal-1.o +# RUN: cmp %t-universal.o %t-universal-1.o +# RUN: llvm-lipo -arch arm64 %t-arm64-asm.o -arch x86_64 %t-x86_64-asm.o -create -output %t-universal-2.o +# RUN: cmp %t-universal.o %t-universal-2.o diff --git a/llvm/tools/llvm-lipo/llvm-lipo.cpp b/llvm/tools/llvm-lipo/llvm-lipo.cpp index 4153e9fa..ab7ff93a 100644 --- a/llvm/tools/llvm-lipo/llvm-lipo.cpp +++ b/llvm/tools/llvm-lipo/llvm-lipo.cpp @@ -28,6 +28,7 @@ #include "llvm/Support/Error.h" #include "llvm/Support/FileOutputBuffer.h" #include "llvm/Support/InitLLVM.h" +#include "llvm/Support/TargetSelect.h" #include "llvm/Support/WithColor.h" #include "llvm/TextAPI/Architecture.h" @@ -425,7 +426,7 @@ static void printBinaryArchs(LLVMContext &LLVMCtx, const Binary *Binary, Expected SliceOrErr = createSliceFromIR(*IR, 0); if (!SliceOrErr) reportError(IR->getFileName(), SliceOrErr.takeError()); - + OS << SliceOrErr->getArchString() << " \n"; } @@ -720,6 +721,10 @@ replaceSlices(LLVMContext &LLVMCtx, int main(int argc, char **argv) { InitLLVM X(argc, argv); + llvm::InitializeAllTargetInfos(); + llvm::InitializeAllTargetMCs(); + llvm::InitializeAllAsmParsers(); + Config C = parseLipoOptions(makeArrayRef(argv + 1, argc - 1)); LLVMContext LLVMCtx; SmallVector, 1> InputBinaries = -- 2.7.4