[lld] c3eb1e2 - [lld-macho] Add error handling for malformed TBD files
Jez Ng via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 12 19:51:07 PDT 2020
Author: Jez Ng
Date: 2020-08-12T19:50:13-07:00
New Revision: c3eb1e27547094405bc0ecbbd7b993912106c28c
URL: https://github.com/llvm/llvm-project/commit/c3eb1e27547094405bc0ecbbd7b993912106c28c
DIFF: https://github.com/llvm/llvm-project/commit/c3eb1e27547094405bc0ecbbd7b993912106c28c.diff
LOG: [lld-macho] Add error handling for malformed TBD files
Previously, lld would crash while complaining that `Expected<T>
must be checked before access or destruction`.
Reviewed By: #lld-macho, compnerd
Differential Revision: https://reviews.llvm.org/D85403
Added:
lld/test/MachO/invalid/invalid-stub.s
Modified:
lld/MachO/Driver.cpp
Removed:
################################################################################
diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp
index 3b45dad1600e..b0ce2f52d8e9 100644
--- a/lld/MachO/Driver.cpp
+++ b/lld/MachO/Driver.cpp
@@ -230,11 +230,12 @@ static void addFile(StringRef path) {
inputFiles.push_back(make<DylibFile>(mbref));
break;
case file_magic::tapi_file: {
- llvm::Expected<std::unique_ptr<llvm::MachO::InterfaceFile>> result =
- TextAPIReader::get(mbref);
- if (!result)
+ Expected<std::unique_ptr<InterfaceFile>> result = TextAPIReader::get(mbref);
+ if (!result) {
+ error("could not load TAPI file at " + mbref.getBufferIdentifier() +
+ ": " + toString(result.takeError()));
return;
-
+ }
inputFiles.push_back(make<DylibFile>(**result));
break;
}
diff --git a/lld/test/MachO/invalid/invalid-stub.s b/lld/test/MachO/invalid/invalid-stub.s
new file mode 100644
index 000000000000..0d070b6c8e44
--- /dev/null
+++ b/lld/test/MachO/invalid/invalid-stub.s
@@ -0,0 +1,12 @@
+# REQUIRES: x86
+# RUN: mkdir -p %t
+# RUN: echo "--- !tapi-tbd-v3" > %t/libinvalidYAML.tbd
+# RUN: echo "invalid YAML" >> %t/libinvalidYAML.tbd
+# RUN: llvm-mc -filetype obj -triple x86_64-apple-darwin %s -o %t/test.o
+# RUN: not lld -flavor darwinnew -Z -L%t -linvalidYAML %t/test.o -o %t/test -Z 2>&1 | FileCheck %s -DDIR=%t
+
+# CHECK: could not load TAPI file at [[DIR]]/libinvalidYAML.tbd: malformed file
+
+.globl _main
+_main:
+ ret
More information about the llvm-commits
mailing list