[lld-macho] Fix crash on invalid framework tbd

Previously these would crash because `file` is null in the case there is
an invalid tbd file.

Differential Revision: https://reviews.llvm.org/D124271
This commit is contained in:
Keith Smiley 2022-04-22 09:42:23 -07:00
parent 67609cdf09
commit 2d8cf26d08
2 changed files with 6 additions and 2 deletions

View File

@ -408,7 +408,8 @@ static void addFramework(StringRef name, bool isNeeded, bool isWeak,
config->hasReexports = true;
dylibFile->reexport = true;
}
} else if (isa<ObjFile>(file) || isa<BitcodeFile>(file)) {
} else if (isa_and_nonnull<ObjFile>(file) ||
isa_and_nonnull<BitcodeFile>(file)) {
// Cache frameworks containing object or bitcode files to avoid duplicate
// symbols. Frameworks containing static archives are cached separately
// in addFile() to share caching with libraries, and frameworks

View File

@ -1,11 +1,14 @@
# REQUIRES: x86
# RUN: mkdir -p %t
# RUN: mkdir -p %t/invalidYAML.framework
# RUN: echo "--- !tapi-tbd-v3" > %t/libinvalidYAML.tbd
# RUN: echo "invalid YAML" >> %t/libinvalidYAML.tbd
# RUN: cp %t/libinvalidYAML.tbd %t/invalidYAML.framework/invalidYAML.tbd
# RUN: llvm-mc -filetype obj -triple x86_64-apple-darwin %s -o %t/test.o
# RUN: not %lld -L%t -linvalidYAML %t/test.o -o %t/test 2>&1 | FileCheck %s -DDIR=%t
# RUN: not %lld -F%t -framework invalidYAML %t/test.o -o %t/test 2>&1 | FileCheck %s -DDIR=%t --check-prefix=CHECK-FRAMEWORK
# CHECK: could not load TAPI file at [[DIR]]{{[\\/]}}libinvalidYAML.tbd: malformed file
# CHECK-FRAMEWORK: could not load TAPI file at [[DIR]]{{[\\/]}}invalidYAML.framework{{[\\/]}}invalidYAML.tbd: malformed file
.globl _main
_main: