Skip to content

Commit 3b2f879

Browse files
committed
[ORC] Use dyn_cast to check input type in StaticLibraryDefinitionGenerator.
Replaces an llvm::cast that assumed that all Binary instances were either Archive or MachOUniversalBinary instances with a dyn_cast. The cast was triggering an assert in StaticLibraryDefinitionGenerator::Load if that method was given a path or MemoryBuffer containing a relocatable object file. Switching to dyn_cast causes the operation to error out with a bad-format error as expected. Fixes rdar://119262300
1 parent 92fccea commit 3b2f879

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ StaticLibraryDefinitionGenerator::Load(
284284

285285
// If this is a universal binary then search for a slice matching the given
286286
// Triple.
287-
if (auto *UB = cast<object::MachOUniversalBinary>(B->getBinary())) {
287+
if (auto *UB = dyn_cast<object::MachOUniversalBinary>(B->getBinary())) {
288288

289289
const auto &TT = L.getExecutionSession().getTargetTriple();
290290

@@ -347,7 +347,7 @@ StaticLibraryDefinitionGenerator::Create(
347347

348348
// If this is a universal binary then search for a slice matching the given
349349
// Triple.
350-
if (auto *UB = cast<object::MachOUniversalBinary>(B->get())) {
350+
if (auto *UB = dyn_cast<object::MachOUniversalBinary>(B->get())) {
351351

352352
const auto &TT = L.getExecutionSession().getTargetTriple();
353353

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
define i32 @main(i32 %argc, i8** %argv) {
2+
entry:
3+
ret i32 0
4+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# RUN: llc -filetype=obj -o %t.o %S/Inputs/main-ret-0.ll
2+
# RUN: cp %t.o %t.a
3+
# RUN: not llvm-jitlink -noexec %t.o %t.a
4+
#
5+
# Try to load an object file as if it were an archive. Should result in an
6+
# error, rather than a crash.

0 commit comments

Comments
 (0)