Skip to content

Commit

Permalink
[llvm-lipo] Support object files with bitcode asm
Browse files Browse the repository at this point in the history
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
  • Loading branch information
thevinster committed Sep 13, 2022
1 parent 41182a6 commit 61e5438
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
7 changes: 7 additions & 0 deletions llvm/test/tools/llvm-lipo/Inputs/arm64-asm.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
target triple = "arm64-apple-macosx11.0.0"

module asm ".desc ___crashreporter_info__, 0x10"

define void @somesymbol() {
ret void
}
7 changes: 7 additions & 0 deletions llvm/test/tools/llvm-lipo/Inputs/x86_64-asm.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
target triple = "x86_64-apple-macosx11.0.0"

module asm ".desc ___crashreporter_info__, 0x10"

define void @somesymbol() {
ret void
}
8 changes: 8 additions & 0 deletions llvm/test/tools/llvm-lipo/create-arch-asm.test
Original file line number Diff line number Diff line change
@@ -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
7 changes: 6 additions & 1 deletion llvm/tools/llvm-lipo/llvm-lipo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -425,7 +426,7 @@ static void printBinaryArchs(LLVMContext &LLVMCtx, const Binary *Binary,
Expected<Slice> SliceOrErr = createSliceFromIR(*IR, 0);
if (!SliceOrErr)
reportError(IR->getFileName(), SliceOrErr.takeError());

OS << SliceOrErr->getArchString() << " \n";
}

Expand Down Expand Up @@ -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<OwningBinary<Binary>, 1> InputBinaries =
Expand Down

0 comments on commit 61e5438

Please sign in to comment.