Skip to content

Commit 30002f2

Browse files
authored
[llvm-lipo] Add support for -info with archive files (llvm#155309)
Previously trying to print the info of an archive caused a crash. Now we correctly report the architecture of the contained object files. Fixes llvm#41655
1 parent 85c7a7f commit 30002f2

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

llvm/test/tools/llvm-lipo/create-archive-input.test

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010
# RUN: llvm-ar cr %t.different_architectures.a %t-i386.o %t-x86_64.o
1111
# RUN: not llvm-lipo %t.different_architectures.a -create -output /dev/null 2>&1 | FileCheck --check-prefix=ARCHIVE-WITH-DIFFERENT-ARCHS %s
1212

13-
# RUN: llvm-ar cr %t.contains_fat_binary.a %t-universal.o
13+
# RUN: llvm-ar cr %t.contains_fat_binary.a %t-universal.o
1414
# RUN: not llvm-lipo %t.contains_fat_binary.a -create -output /dev/null 2>&1 | FileCheck --check-prefix=ARCHIVE-WITH-FAT-BINARY %s
1515

1616
# RUN: llvm-ar cr %t-i386-lib.a %t-i386.o
1717
# RUN: llvm-lipo %t-i386-lib.a %t-x86_64.o -create -output %t-i386-x86_64-universal.o
18+
# RUN: llvm-lipo %t-i386-lib.a -info | FileCheck --check-prefix=INFO-i386 %s
1819
# RUN: llvm-lipo %t-i386-x86_64-universal.o -info | FileCheck --check-prefix=INFO-i386-x86_64 %s
1920
# RUN: llvm-lipo %t-i386-x86_64-universal.o -thin i386 -output %t-extracted-i386-lib.a
2021
# RUN: cmp %t-extracted-i386-lib.a %t-i386-lib.a
@@ -51,4 +52,5 @@
5152
# ARCHIVE-WITH-DIFFERENT-ARCHS: all members must match
5253
# ARCHIVE-WITH-FAT-BINARY: fat file (not allowed in an archive)
5354
#
55+
# INFO-i386: i386
5456
# INFO-i386-x86_64: i386 x86_64

llvm/tools/llvm-lipo/llvm-lipo.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,11 @@ static void printBinaryArchs(LLVMContext &LLVMCtx, const Binary *Binary,
425425
return;
426426
}
427427

428+
if (const auto *A = dyn_cast<Archive>(Binary)) {
429+
OS << createSliceFromArchive(LLVMCtx, *A).getArchString() << "\n";
430+
return;
431+
}
432+
428433
// This should be always the case, as this is tested in readInputBinaries
429434
const auto *IR = cast<IRObjectFile>(Binary);
430435
Expected<Slice> SliceOrErr = createSliceFromIR(*IR, 0);
@@ -455,7 +460,8 @@ printInfo(LLVMContext &LLVMCtx, ArrayRef<OwningBinary<Binary>> InputBinaries) {
455460
for (auto &IB : InputBinaries) {
456461
const Binary *Binary = IB.getBinary();
457462
if (!Binary->isMachOUniversalBinary()) {
458-
assert(Binary->isMachO() && "expected MachO binary");
463+
assert(Binary->isMachO() ||
464+
Binary->isArchive() && "expected MachO binary");
459465
outs() << "Non-fat file: " << Binary->getFileName()
460466
<< " is architecture: ";
461467
printBinaryArchs(LLVMCtx, Binary, outs());

0 commit comments

Comments
 (0)